Error trying to create Sparklines

I am trying to add a SparkLine to a worksheet and I am getting an error:

"The reference for the location or data range is invalid".

Here is my code:

CellArea cellArea = new CellArea();

cellArea.StartColumn = 0;
cellArea.EndColumn = 0;
cellArea.StartRow = 0;
cellArea.EndRow = 0;

int sparklineIndex = worksheet.SparklineGroupCollection.Add(SparklineType.Column, "'P&L Statement'!D8:O8", true, cellArea);
SparklineGroup group = worksheet.SparklineGroupCollection[sparklineIndex];

I am getting the error on Add method.

I am using version 7.3.4.0.

Thanks,

Mark

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please use the following code with the latest version: Aspose.Cells
for .NET v7.5.2.2
it works fine. We have also attached the output xlsx file for your reference.

C#


Workbook workbook = new Workbook();


//Clear workbook’s worksheets

workbook.Worksheets.Clear();


//Insert new Worksheet in workbook and name it “New”

Worksheet worksheet = workbook.Worksheets.Add(“P&L Statement”);


//Insert dummy data in A8, A9 and A10 cells

worksheet.Cells[“A8”].PutValue(34);

worksheet.Cells[“A9”].PutValue(50);

worksheet.Cells[“A10”].PutValue(34);


//Intialize Cell Area

CellArea cellArea = new CellArea();


//Assign Cell Area boundaries

cellArea.StartColumn = 0;

cellArea.EndColumn = 0;

cellArea.StartRow = 0;

cellArea.EndRow = 0;


//Add new Sparklines in worksheet’s sparlines collection and Assign the area for it

int index = worksheet.SparklineGroupCollection.Add(SparklineType.Column, “‘P&L Statement’!A8:A10”, true, cellArea);


workbook.Save(“output.xlsx”, SaveFormat.Xlsx);

Hi,


And, see the document/article for your further reference:
http://www.aspose.com/docs/display/cellsnet/Using+Sparklines

Thank you.