"Object not set to an instance of an object" in 4.9.1.0

I have a couple of Excel files that I am able to convert to TIFF with no problem in 4.9.0.0, but in 4.9.1.0 I get an “Object not set to an instance of an object” error on every sheet. The Excel files are attached.


Here is my code snippet:

Workbook workbook = new Workbook();
workbook.Open(rawStream);
ImageOrPrintOptions sheetOptions = new ImageOrPrintOptions();
sheetOptions.TiffCompression = Aspose.Cells.TiffCompression.CompressionLZW;
sheetOptions.HorizontalResolution = 300;
sheetOptions.VerticalResolution = 300;
sheetOptions.IsCellAutoFit = true;
for (int ix = 0; ix < workbook.Worksheets.Count; ++ix)
{
try
{
Worksheet worksheet = workbook.Worksheets[ix];
worksheet.SheetToImage(tiffPath, true, sheetOptions);
}
catch (Exception sheetException)
{
// TODO: log this exception
// do nothing; this sheet has a problem, continue exporting the other sheets
}
}

Hi,

Please use SheetRender API instead of SheetToImage, we do not enhance SheetToImage anymore now. Please try the attached latest version/fix with the following sample code. I have tested using your file and it works fine.

Sample code:
Workbook workbook = new Workbook();
workbook.Open(“e:\test\eDiscovery+Test+record.xlsx”);
ImageOrPrintOptions sheetOptions = new ImageOrPrintOptions();
sheetOptions.ImageFormat = ImageFormat.Tiff;
sheetOptions.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionLZW;
sheetOptions.HorizontalResolution = 300;
sheetOptions.VerticalResolution = 300;
sheetOptions.IsCellAutoFit = true;
for (int ix = 0; ix < workbook.Worksheets.Count; ++ix)
{
try
{
Worksheet worksheet = workbook.Worksheets[ix];
SheetRender sr = new SheetRender(worksheet, sheetOptions);
int sheetPageCount = sr.PageCount;
string subPageName = string.Empty;
for (int j = 0; j < sheetPageCount; j++)
{
sr.ToImage(j, @“e:\test\image” + ix.ToString() + “_” + j.ToString() + “.tif”);
}

}
catch (Exception sheetException)
{
// TODO: log this exception
// do nothing; this sheet has a problem, continue exporting the other sheets
}
}



Thank you.

Thank you for your reply. Using SheetRender.ToTiff in 5.0.0.0, I am now able to convert the previous Excel file. However, Excel files with blank worksheets result in the blank worksheet being converted to 0KB Tiff images; these blank worksheets should either be ignored or converted into blank Tiff images, rather than a zero-length file.


I’ve worked around this by not converting a worksheet with a Cell count of zero, and maybe that’s the correct solution.

An Excel file that exhibits this behavior is attached.

Hi,

Please try the attached latest fix v5.0.0.1 instead of v5.0.0.0. I have tested with your template file, the tif files are generated fine. The tif images results are same as Ms Excel’s print preview. If you find any difference, kindly let us know.

Thank you.