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

Free Support Forum - aspose.com

Workbook.Save is throwing error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

My code works 99% of the time, but I have this one .xls file that continues to throw this error, "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" on this line...

workbook.Save(@"D:\AsposePdfSupport\IO\Out\temp.xml", FileFormatType.AsposePdf);

I am attaching a sample solution and .xls file that is my "problem child" file.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, If we use your template file and execute your code, we get the same error message as you mentioned, But by just resaving your template file in MS Excel and testing it with your provided sample application, it works fine. Did you generated this template file using Aspose.Cells? If yes, please share your code and we will look into it and also your provided template file to figure out the issue. Also, now Aspose.Cells provides direct conversion of Excel files to PDF (without converting to XML and using Aspose.PDF APIs), please see the following sample code in this regard,

Sample Code:

//Instantiate the Workbook object

Workbook myWorkbook = new Workbook();

//Open the workbook

myWorkbook.Open("C:\\Input.xls");

//Save the document in PDF format

myWorkbook.Save("C:\\output.pdf", FileFormatType.Pdf);

Thank You & Best Regards,

Unfortunately, I do have the luxury of opening and resaving the .xls as the is being pocessed from an email attachment in a Windows service. I did not create the .xls with Aspose.Cells - it was created bywhoever attache it to the email.

I did try your suggestion of the streamlined conversion from .xls to .pdf. However, the FileFormatTpe of Pdf (i.e. myWorkbook.Save("C:\\output.pdf", FileFormatType.Pdf);) is not available in type-ahead - see screenshot.) I am using Aspose.Cells version 4.6.0.0.....What was the earliest Aspose.Cells version that supports the more direct conversion from .xls to .pdf? It seems like I just upgraded our Aspose.Total package a couple of weeks ago.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

We will check you template file for the index out of range issue and provide you with a fix soon. For FileFormatType.PDF, it was supported after the official release 4.6.0.0, so you may require the latest fix to use this functionality. I have attached the latest fix in case you want to check for this new functionality.

Thank You & Best Regards,

Thank you for your prompt response. I tried the latest Aspose.Cell.dll (version 4.6.0.16) that you sent. Although I like the new streamlined conversion (and I have implemented the newer version in my actual project), it still throws the index error. I will await your fix for this.

Hi,

Please try the new release (4.7.0): http://www.aspose.com/community/files/51/file-format-components/aspose.cells-for-.net-and-java/entry167012.aspx we have fixed your issue.

Thank you.

Your fix worked as you promised. Thank you for your prompt and helpful responses. It is always refreshing to work wi the Aspose Support Team!

Best Regards,

Kyle

Good morning, I have the same problem. When I save my workbook I get the same error.
Perform a first successful rescue, then perform spreadsheet operations, and apply the formulacalculate method and the second rescue process fails.
I use aspose version 7.

@fbaldari,

Thanks for sharing some details.

As you are using some older version (v7.0.0) of the product for which I am not sure about your issue. Neither we can evaluate your issue with older version that you are using. We recommend you to kindly upgrade to and try our latest version/fix:
Aspose.Cells for .NET v17.7:
https://downloads.aspose.com/cells/net

Aspose.Cells for Java v17.7
https://downloads.aspose.com/cells/java

If you still find the issue with v17.7, kindly create a sample console application (runnable), zip the project and post us here with all the files, we will check it soon.

Thank you.