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

Free Support Forum - aspose.com

SheetRender ToImage Throws Exception: Index was out of range. Must be non-negative and less than the size of the collection

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

We are creating TIF files from XLS files. We have an XLS that generates the exception “Index was out of range. Must be non-negative and less than the size of the collection.” The error is generated when the 4th worksheet in the XLS is converted to a TIF. We have been able to convert other XLS files that contain more worksheets than this one so we do not understand why this one is failing. It displays properly in Excel. It appears to be a problem with SheetRender.

The uploaded ZIP file, XLS-IndexException.zip, contains the problem XLS file.

We are using Aspose.Cells.dll which was given to us last week.

This is the code that we are using to render the tifs.

Workbook book = new Workbook();


if (imgOptions == null)


imgOptions = new ImageOrPrintOptions();

imgOptions.ImageFormat = ImageFormat.Tiff;

imgOptions.HorizontalResolution = 200;

imgOptions.VerticalResolution = 200;

imgOptions.TiffCompression = TiffCompression.CompressionCCITT4;

imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;


int bookPageCount = 0;

for (int i = 0; i < book.Worksheets.Count; i++)


Worksheet sheet = book.Worksheets[i];

if (settingOrientation) sheet.PageSetup.Orientation = orientation;

if (settingZoom) sheet.PageSetup.Zoom = zoom;

if (settingPrintGridlines) sheet.PageSetup.PrintGridlines = printGridlines;

if (settingAutoFitColumns) sheet.AutoFitColumns();

if (settingAutoFitRows) sheet.AutoFitRows();

if (imgOptions.TiffCompression == TiffCompression.CompressionCCITT4)


foreach (Cell cell in sheet.Cells) // If rendering to B&W, force black text on white background.


cell.Style.Font.Color = Color.Empty;

cell.Style.ForegroundColor = Color.Empty;

cell.Style.BackgroundColor = Color.Empty;

cell.Style.Pattern = BackgroundType.None;



SheetRender sr = new SheetRender(sheet, imgOptions);

int sheetPageCount = sr.PageCount;

string subPageName = string.Empty;

for (int j = 0; j < sheetPageCount; j++)


subPageName = SubPageName(pageName, (uint)(bookPageCount + j)); // Generates a unique file name

sr.ToImage(j, batchDir + @"\" + subPageName + ".tif");


sr = null;

bookPageCount += sheetPageCount;


I look forward to your reply.

Thank you,



Thanks for providing us the template file with sample code:

I can find the issue as you have described using your template file with sample code provided. We will figure your issue out soon. I have logged your issue into our issue tracking system with an id: CELLSNET-18687. Once we have any update about it, we will let you know.

Thank you.


Please try the attached version.

We have fixed your issue now.

Thank you.


I can confirm that this fixes the problem.

Thank you,


The issues you have found earlier (filed as 18687) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan