hi
i try to draw piechart of using excel data using coding in c# i use Microsoft.Office.Interop.Excel
i get chart if i try for column A and B but if if i try For A and Column C it not take column c so my problem is that how we pass range for pie chart which take nay column from excel sheet,
I use below code.
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
object missing = Type.Missing;
Microsoft.Office.Interop.Excel.Range xlRange;
Microsoft.Office.Interop.Excel.Sheets xlSheets = null;
Microsoft.Office.Interop.Excel.Worksheet xlSheet = null;
Microsoft.Office.Interop.Excel.Workbook xlWorkbook = null;
xlWorkbook = excelApp.Workbooks.Open(@"C:\delfolder\data12.xlsx", missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing);
xlSheets = (Microsoft.Office.Interop.Excel.Sheets)xlWorkbook.Sheets;
xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlSheets[1];
Microsoft.Office.Interop.Excel.ChartObjects chartObjs = (Microsoft.Office.Interop.Excel.ChartObjects)xlSheet.ChartObjects(Type.Missing);
Microsoft.Office.Interop.Excel.ChartObject chartObj = chartObjs.Add(1000,20,500,500);
Microsoft.Office.Interop.Excel.Chart xlChart = chartObj.Chart;
Microsoft.Office.Interop.Excel.Range rg = xlSheet.get_Range("A2:A13", "B2:B13");
xlChart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlPie;
xlChart.SetSourceData(rg3, Type.Missing);
xlChart.ApplyDataLabels(Microsoft.Office.Interop.Excel.XlDataLabelsType.xlDataLabelsShowLabelAndPercent,Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing);
xlWorkbook.SaveAs(@"C:\delfolder\data12.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkbook.Close(true, Type.Missing, Type.Missing);
excelApp.Quit();
releaseObject(xlSheet);
releaseObject(xlWorkbook);
releaseObject(excelApp);
so
Microsoft.Office.Interop.Excel.Range rg = xlSheet.get_Range("A2:A13", "B2:B13");
in place of range "B2:B13" i want to take column "C2:C13" but my problem is that in i pass "C2:C13"
it give me a chart for "B2:B13"g which is help full for me please help me
thank you.
[Edit]Code block formatting added, Excel tag added[/Edit]