Charts

Im having trouble trying to get a chart to appear on an existing worksheet in one of my templates. The code is below. Everything executes without error, but no chart appears. I have tried using Workbook.Charts.Add("Residuals") instead of line 3 below, but this throws a ''worksheet already exists'' type error. All I want to do is create and display a chart on an existing worksheet - can anybody show me how to do this ? IWorksheet chartSheet = Workbook.Worksheets["Residuals"]; IRange residualChartRange = chartSheet.Range[RESIDUALS_CHART]; IChart residualChart = chartSheet.Charts.Add(); residualChart.ChartType = ExcelChartType.Bar_Clustered; residualChart.XPos = 72; residualChart.YPos = 72; residualChart.DataRange = chartSheet.Range[RESIDUALS_DATA]; residualChart.IsSeriesInRows = true;

1 Reply

AD Administrator Syncfusion Team June 7, 2006 11:38 AM UTC

Hi Roy, Sorry for the long delay in getting back to you. I am not sure if I understand your requirements correctly. However 1) To preserve the chart properties in the template worksheet please use the following code : IWorkbook workbook = application.Workbooks.Open(@"..\..\Data\ChartsTemplate.xls",ExcelParseOptions.DoNotParseCharts); Here is a sample which does this:ChartsTemplate.zip 2) If you need to add a chart sheet to a template document please use the following peace of code: //Adding a New(Embedded chart) to the Worksheet IChartShape shape = sheet.Charts.Add(); shape.DataRange = sheet.Range["B3:D6"]; Here is a sample for your reference:Embedded_Charts.zip Regarding the "Worksheet already exists" Exception. This will be thrown only when adding a worksheet with the same name as a already existing worksheet. Please take a look at the samples and let me know if you have any queries. BestRegards, Bharath

Loader.
Up arrow icon