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 5.0.0.13 which was given to us last week.
This is the code that we are using to render the tifs.
Workbook book = new Workbook();
book.Open(fullPath);
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,
Robert