locked
Bagaimana cara membuat animasi berputar/rotasi 3D pada Chart 3D Clustered Column Microsoft Excel 2013? RRS feed

  • Pertanyaan

  • Saya punya kode C# untuk membuat Chart pada Microsoft Excel 2013:

    using System;
    using System.Windows.Forms;
    using Excel = Microsoft.Office.Interop.Excel; 
    
    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Excel.Application xlApp ;
                Excel.Workbook xlWorkBook ;
                Excel.Worksheet xlWorkSheet ;
                object misValue = System.Reflection.Missing.Value;
    
                xlApp = new Excel.ApplicationClass();
                xlWorkBook = xlApp.Workbooks.Add(misValue);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    
                //add data 
                xlWorkSheet.Cells[1, 1] = "";
                xlWorkSheet.Cells[1, 2] = "Student1";
                xlWorkSheet.Cells[1, 3] = "Student2";
                xlWorkSheet.Cells[1, 4] = "Student3";
    
                xlWorkSheet.Cells[2, 1] = "Term1";
                xlWorkSheet.Cells[2, 2] = "80";
                xlWorkSheet.Cells[2, 3] = "65";
                xlWorkSheet.Cells[2, 4] = "45";
    
                xlWorkSheet.Cells[3, 1] = "Term2";
                xlWorkSheet.Cells[3, 2] = "78";
                xlWorkSheet.Cells[3, 3] = "72";
                xlWorkSheet.Cells[3, 4] = "60";
    
                xlWorkSheet.Cells[4, 1] = "Term3";
                xlWorkSheet.Cells[4, 2] = "82";
                xlWorkSheet.Cells[4, 3] = "80";
                xlWorkSheet.Cells[4, 4] = "65";
    
                xlWorkSheet.Cells[5, 1] = "Term4";
                xlWorkSheet.Cells[5, 2] = "75";
                xlWorkSheet.Cells[5, 3] = "82";
                xlWorkSheet.Cells[5, 4] = "68";
    
                Excel.Range chartRange ; 
    
                Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
                Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 300, 250);
                Excel.Chart chartPage = myChart.Chart;
    
                chartRange = xlWorkSheet.get_Range("A1", "d5");
                chartPage.SetSourceData(chartRange, misValue);
                chartPage.ChartType = Excel.XlChartType.xlColumnClustered; 
    
                xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();
    
                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);
    
                MessageBox.Show("Excel file created , you can find the file c:\\csharp.net-informations.xls");
            }
    
            private void releaseObject(object obj)
            {
                try
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                    obj = null;
                }
                catch (Exception ex)
                {
                    obj = null;
                    MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
                }
                finally
                {
                    GC.Collect();
                }
            }
    
        }
    }

    Yang saya inginkan membuat animasi berputar/rotasi 3D pada  Chart 3D Clustered Column Microsoft Excel. Apakah ada yang bisa membantu?


    Minggu, 10 Februari 2013 11.58

Jawaban

  • Hi Dudi Gunawan

    Mohon maaf atas keterlambatan membalas forum ini, karena kita melakukan beberapa tes untuk mencoba memecahkan masalah ini.

    1. Kode diatas dapat berjalan dengan mengubah kode

    chartPage.ChartType = Excel.XlChartType.xlColumnClustered; menjadi xl3DColumnClustered

    atau

    2. Create dahulu non 3D chart dan ketika ingin mengubah menjadi 3D cluster colum, ubah kode VBA dibawah menjadi C#:

        Range("A1:D5").Select
        ActiveSheet.Shapes.AddChart2(286, xl3DColumnClustered).Select
    ActiveChart.SetSourceData Source:=Range("Sheet1!$A$1:$D$5")

    Semoga bisa menjawab pertanyaan kamu

    Terima kasih


    Andy Nugraha

    TechNet Community Support

    Senin, 18 Februari 2013 08.38
    Moderator