We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Getting the CellArea range "name" to Add to Chart

I have a set of data that will be populated by smart markers. This data will then be used to populate a graph.

So let's say the smart marker populates some data A1:A6.

The code to add data to a chart is like so. SeriesCollection.add("A1:A6");

So my question is, how do I actually get the string "A1:A6"? I tried creating a CellArea and then calling toString(). But that gave me too much: example: "Aspose.Cells.CellArea(B3:B27)[2,1,26,1]".

Interesting. When I follow the example and I hard code the category to be a String "A1:A6" i get a class cast exception

java.lang.ClassCastException: java.lang.String
at com.aspose.cells.SeriesCollection.setCategoryData(Unknown Source)

Sample Code is as follows:

Worksheet template = workbook.getWorksheets().get(0);

Chart chart = template.getCharts().get(chartNumber);

SeriesCollection chartSeries =





NOTE: In our template file, it consts of "blank" charts. We take a reference to one of those charts and then update it by adding Series etc. The very last line is what throwing a classcastexception for String.


Thanks for your inquiry.

I have checked your scenario a bit. Well, I think since your data is dynamic (you might not know how much rows would be in your data source when you process the markers to fill the data into the cells, etc.) you should create a range using Aspose.Cells APIs dynamically for your smart markers cell(s). For example, you will paste a marker in the cell A2 i.e. &=Tab1.Field1, now you create a range for that marker e.g. you may create a range based on the A1:A2 cell area/range, see the sample code segment here:
Worksheet worksheet = workbook.getWorksheets().get(0);
Range range = worksheet.getCells().createRange(“A1”, “A2”);

You will also create your chart but set the data series based on that range source data. E.g
int index = chart.getNSeries().add("=TestRange", true);

Now that when the markers are processed, new blank rows are inserted first to fill the data into the cells/range which would be also extended, the chart would be updated based on the data series data. Similarly you should be able to set/define the category data based on the other range accordingly.

Thank you.