Can anyone tell me why this line works with no problem using an Excel 2003 .xls template file but throws an error using an Excel 2007 .xlsx file?
m_oChart.NSeries[0].Values = "D64:D174";
There is an existing series in the template file chartsheet and this line updates the existing series with a new series address.
We are using Aspose Cells for .Net version 4.4.3.1 (yes I know its an old one). This application has been running flawlessly since 2008 but my client now needs larger workbooks exported to Excel (more than 256 columns), so I'm making a simple change to use the Excel2007xlsx file format.
As long as I use and refer to an Excel 2003 xls file there is no problem, but using an Excel 2007 xlsx file it errors with:
"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
'm_oChart.NSeries[0]' threw an exception of type 'System.ArgumentOutOfRangeException' Aspose.Cells.ASeries {System.ArgumentOutOfRangeException}
More code bits:
Old Code for Excel designer workbook v 2003 xls (just the pertinent lines):
CellsLicense.SetLicense("Aspose.Cells.lic");
Workbook m_oWBIMSRpt = new Workbook();
sFileName = "SegmentsReport.xls";
path = HttpContext.Current.Server.MapPath("~/templates");
templatefile = path + "/" + sFileName;
m_oWBIMSRpt.Open(templatefile);
m_oIMSChartSheet = m_oWBIMSRpt.Worksheets[1].Charts;
Chart m_oChart = m_oIMSChartSheet[0];
m_oChart.Type = ChartType.Scatter;
m_oChart.NSeries[0].Values = "D64:D174"
New Code for Excel 2007 xlsx
CellsLicense.SetLicense("Aspose.Cells.lic");
Workbook m_oWBIMSRpt = new Workbook();
sFileName = "SegmentsReport.xlsx";
path = HttpContext.Current.Server.MapPath("~/templates");
templatefile = path + "/" + sFileName;
m_oWBIMSRpt.Open(templatefile, FileFormatType.Excel2007Xlsx);
m_oIMSChartSheet = m_oWBIMSRpt.Worksheets[1].Charts;
Chart m_oChart = m_oIMSChartSheet[0];
m_oChart.Type = ChartType.Scatter;
m_oChart.NSeries[0].Values = "D64:D174"
It does a lot of processing to add data to the workbook in Sheet1 and then to the chart series in a ChartSheet. Everything works perfectly except that line.
It make no sense as even this older version of Aspose Cells should handle this. Attached is the v2007 template file.
Thanks,
Rob