Free Support Forum - aspose.com

Charts and worksheets

Hi

I have a workbook with 2 worksheets. I would like the first worksheet to display the data, and the second worksheet to display a chart using data from worksheet 1.

The online documentation recommends

Worksheet worksheet = workbook.Worksheets[0];

int chartIndex = worksheet.Charts.Add(ChartType.Bar, 10, 0,30 , 10);

Chart chart = worksheet.Charts[chartIndex];

chart.NSeries.Add("B2:C5", true);

But the chart.NSeries object defaults to the same worksheet the chart is on. Is it possible to point the chart.NSeries to a different worksheet? Or do I have to copy the values of worksheet 1 to worksheet 2?

Thanks in advance

James

Please try:

chart.NSeries.Add("Sheet2!B2:C5", true);

Many thanks Laurence

That solved it. Just one more quick question, in Excel, by right clicking on a chart and choosing location, a chart can be added to the current worksheet or as a new sheet, in which case it occupies the whole of the sheet. Is add chart as 'new sheet' functionality included in Aspose Cells?

Best Regards

James

Yes, you can. Please try:

Workbook excel = new Workbook();

Cells cells = excel.Worksheets[0].Cells;


cells["A1"].PutValue(1);


cells["A2"].PutValue(2);


cells["A3"].PutValue(3);


cells["B1"].PutValue(4);


cells["B2"].PutValue(5);


cells["B3"].PutValue(6);

cells["C1"].PutValue("a");

cells["C2"].PutValue("b");

cells["C3"].PutValue("c");

excel.Worksheets.Add(SheetType.Chart);

excel.Worksheets[1].Zoom = 75;

int chartIndex = excel.Worksheets[1].Charts.Add(ChartType.Column, 0, 0, 0, 0);

Chart chart = excel.Worksheets[1].Charts[chartIndex];


chart.NSeries.Add("Sheet1!A1:A3", true);

Brilliant!

Thanks again

James