SheetToImageByPage() causing ArgumentException

Hi,

We are using Aspose.Cells.dll (4.8.2.15) to convert xls files to tif images.

Following code throws ArgumentException (Parameter is not valid.) with attached Excel.xls:


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using Aspose.Cells;

namespace ExcelTester
{
class Program
{
static void Main(string[] args)
{
Aspose.Cells.License licenseCells = new Aspose.Cells.License();
licenseCells.SetLicense("Aspose.Cells.lic");

Workbook book = new Workbook();
book.Open("Excel.xls");

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = ImageFormat.Tiff;
imgOptions.HorizontalResolution = 200;
imgOptions.VerticalResolution = 200;
imgOptions.TiffCompression = TiffCompression.CompressionCCITT4;
imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

for (int i = 0; i < book.Worksheets.Count; i++)
{
Worksheet sheet = book.Worksheets[i];

foreach (Cell cell in sheet.Cells)
{
cell.Style.Font.Color = Color.Empty;
cell.Style.ForegroundColor = Color.Empty;
cell.Style.BackgroundColor = Color.Empty;
cell.Style.Pattern = BackgroundType.None;
}

int sheetPageCount = sheet.GetPageCount(imgOptions.PrintingPage);
for (int j = 0; j < sheetPageCount; j++)
sheet.SheetToImageByPage(j, "image" + i.ToString() + "_" + j.ToString() + ".tif", imgOptions); // Exception Here!
}
}
}
}


Please test above code with attached Excel.xls file with Aspose.Cells.dll (4.8.2.15).

This issue was reported from our customer as critical issue that must be fixed ASAP.
It is being used in live production environment and fix is urgent.

Please provide us with an ETA for a fix so that we can tell our customer.

Thank You.

Hi,

After an initial test, I can find the issue you have mentioned using your code and template file.

We will figure it out soon.

Your issue has been logged into our issue tracking system with an issue id: CELLSNET-16744.

Once the issue is sorted out we will inform you.

Thank you.

Hello Amjad,

Do you have any status update on this problem?

Thank you,
Robert

Hi,

Please try the attached version v4.9.1.3, it fixes your issue.

And, kindly use SheetRender API instead of using Worksheet.SheetToImage() method. See the following sample code that works fine.

Workbook book = new Workbook();
book.Open(“e:\test\Excels.xls”);


ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = ImageFormat.Tiff;
imgOptions.HorizontalResolution = 200;
imgOptions.VerticalResolution = 200;
imgOptions.TiffCompression = TiffCompression.CompressionCCITT4;
imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

Style style;

for (int i = 0; i < book.Worksheets.Count; i++)
{
Worksheet sheet = book.Worksheets[i];

foreach (Aspose.Cells.Cell cell in sheet.Cells)
{
style = cell.GetStyle();
style.Font.Color = Color.Empty;
style.ForegroundColor = Color.Empty;
style.BackgroundColor = Color.Empty;
style.Pattern = BackgroundType.None;
cell.SetStyle(style);
}


SheetRender sr = new SheetRender(sheet, imgOptions);
for (int j = 0; j < sr.PageCount; j++)
{

sr.ToImage(j, “e:\test\img_” + sheet.Index + j + “.tif”);
}

}


Thank you.

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

We have not been using SheetRender because it is very buggy. It doesn’t convert to TIF as well and the TIF is creates has wrong information. Please see CELLSNET-14848 “SheetToImageByPage() Bug! - Hang and Omitted Data” for more information.

I tested your new update v4.9.1.3 with the SheetRender code that you provided. While it does now create a TIF file, the TIF information is *incorrect*. As you can see in the example code you provided, the resolution is set to 200x200. If you examine the resulting TIF file, you will see it creates a 96 dpi image with a width of 1654 and a height of 2338. This is wrong. The image should have a dpi of 200, a width of 1700 and a height of 2200.

Please let us know when you will have a fix. We cannot use this update with this problem. While it would be good for you to fix SheetRender, our request is that you fix SheetToImageByPage so it works with the provided XLS because SheetToImageByPage produces better output and has had much more testing.

Thank you,

Robert.

Hi Robert,

For the TIF information being incorrect, this is because the horizontal/vertical resolution is not feasible when you set the TiffCompression to CompressionCCITT4. It would always come as 96dpi in that case.

For you case, kindly use:
imgOptions.TiffCompression = TiffCompression.CompressionLZW instead.

Sample code:

Workbook book = new Workbook();
book.Open(“e:\test\Excels.xls”);


ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = ImageFormat.Tiff;
imgOptions.HorizontalResolution = 200;
imgOptions.VerticalResolution = 200;
imgOptions.TiffCompression = TiffCompression.CompressionLZW;

//…


Thank you.

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

Our images must be CCITT compressed, not LZW.

Your SheetToImageByPage method correctly creates 200 dpi images. Your Aspose Word API also correctly creates 200 dpi CCITT compressed TIF images.

Every imaging application I have ever used, Photoshop, PaintShopPro, IrfanView and many more, all correctly save and read 200 dpi CCITT images. The standard says that G4 images support up to 400 dpi.

My company has been working with 200 dpi CCITT images for a long time. Our software creates them. Libraries like Snowbound and Leadtools create them. We process images from other vendors created at 200 dpi.

We must be able to create 200 dpi CCITT images directly with your software. We do not want to have to save them as LZW then run an extra step using a different library to correctly convert your LZW image to a 200 dpi CCITT image.

The TIFF format is the standard in document imaging and document management systems using CCITT Group IV 2D compression, which supports black-and-white (bitonal, monochrome) images. In high-volume storage scanning, documents are scanned in black and white (not in color or in grayscale) to conserve storage capacity. An average A4 scanning produces 30 kB of data at 200 PPI (pixels per inch of resolution) and 50 kB of data at 300 PPI; 300 PPI is more common than 200 PPI.

“Group 4 : A protocol for sending fax documents over ISDN networks. The Group 400 protocol supports images of up to 400 dpi resolution.”

Please let us know when you expect to have this fixed.

Thank you,

Robert.

Hi Robert,

Please try the attached version.

We have generated tiff pictures with 2482*3508 (300dpi) using CompressionCCITT3, please refer to the attachment. And we will not support/enhance SheetToImage any more. If you find any issue in SheetRender, we will provide a fix as soon as possible.

Thank you.

The 4.9.1.4 update does allow the original XLS file to be converted to TIF. However, one obvious problem is that SheetRender is creating blank pages that do not exist when printed with Microsoft Excel. We cannot use this fix until that problem is corrected or we will be breaking existing functionality in our product. I created the new post “SheetRender Creates Blank Pages But Excel Does Not” to get the blank issue resolved. I look forward to the resolution.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you,

Robert

Hi,

We have replied you in your other thread for your mentioned issue:
http://www.aspose.com/community/forums/239143/sheetrender-creates-blank-pages-but-excel-does-not/showthread.aspx#239143
So, kindly follow up the thread and keep in touch.

Thank you.

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


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

While trying to keep the API as straightforward and clear as possible, we have decided to recognize and honor the common development practices of the platform; we have re-arranged API Structure/ Namespaces.

With this release, we have reorganized the API classes for Aspose.Cells component. This change has some major aspects that we follow. We have added new namespaces. The entire API (classes, interfaces, enumerations, structures etc.) were previously located in the Aspose.Cells namespace. Now, certain sets of API have been moved to their relative namespaces, which make the relationship of classes (with their members) and namespaces clear and simplified. It is to be noted here, we have not renamed existing API (classes, enumerations etc.) but, I am afraid you still need to make certain adjustments in your existing projects accordingly.

For complete reference, please see the product's API Reference.