Empty xlsx sheets are converted into black images

Hi,

We are using 7.2.1.0 version of Aspose.Cells.dll assembly for converting xlsx files into TIFF images.

When we convert empty worksheets to TIFF images they are converted into black images.

It should be totally white/blank image. Any suggestions on this issue?

Thanks,

Ganesh

Hi,

Please download and try this fix: Aspose.Cells for .NET v7.4.0.1 and let us know your feedback.

If you still find the issue, kindly attached a sample file and paste your code here, we will check your issue soon.

Thank you.

Hi Amjad,

Below is the code

-----Code Start---------

Aspose.Cells.LoadOptions options;

string Extension = System.IO.Path.GetExtension(this.JobList.ActiveJob.FileName).Replace(".", "").ToUpper();
switch (Extension)
{
case "XLS":
options=new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Excel97To2003);
break;
case "XLSX":
options=new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx);
break;
case "CSV":
options=new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.CSV);
break;
case "TBL":
options=new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.TabDelimited);
break;
default:
options=new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Auto);
break;
}


Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(InputData,options);

Aspose.Cells.Rendering.ImageOrPrintOptions saveops = new Aspose.Cells.Rendering.ImageOrPrintOptions();
saveops.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;
saveops.VerticalResolution = 200;
saveops.HorizontalResolution = 200;


bool Color = true;
if (GetParameter("Color").ToUpper() == "FALSE")
Color = false;


if(Color)
saveops.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionLZW;
else
saveops.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionCCITT4;
saveops.IsImageFitToPage = true;

System.Windows.Media.Imaging.TiffBitmapEncoder encoder=new System.Windows.Media.Imaging.TiffBitmapEncoder();
if (Color)
encoder.Compression = TiffCompressOption.Lzw;
else
encoder.Compression = TiffCompressOption.Ccitt4;

foreach (Aspose.Cells.Worksheet sheet in book.Worksheets)
{
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, saveops);
System.IO.MemoryStream tiffStream=new System.IO.MemoryStream();

sr.ToTiff(tiffStream);
tiffStream.Position = 0;

System.Windows.Media.Imaging.TiffBitmapDecoder decoder;

if(Color)
decoder = new System.Windows.Media.Imaging.TiffBitmapDecoder(tiffStream, System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.None);
else
decoder = new System.Windows.Media.Imaging.TiffBitmapDecoder(tiffStream, System.Windows.Media.Imaging.BitmapCreateOptions.IgnoreColorProfile, System.Windows.Media.Imaging.BitmapCacheOption.None);
foreach (BitmapFrame frame in decoder.Frames)
encoder.Frames.Add(BitmapFrame.Create(frame));
}

encoder.Save(BitmapData);

BitmapData.Position = 0;

-----Code End---------

This happens for any xlsx file with empty worksheets in it.

I will check with latest version of the dll and inform you.

Thanks,

Ganesh

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

It’s strange, you are getting this issue, we think, such issues occur because of Colors and Palette and because of Xls format. Xls format can support only 56 colors at a time, more colors are supported by changing the colors in a Palette.

Kindly see this document for your reference and see if it can resolve your issue.

Hi,


By using the latest versions e.g v7.4.0.x, if a worksheet is blank, no output tiff image would be rendered. I have tested it with a template file attached and following code:

Sample code:

Workbook workbook = new Workbook(“e:\test2\BlankBook1.xlsx”);
Worksheet sheet = workbook.Worksheets[0];

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;
imgOptions.VerticalResolution = 200;
imgOptions.HorizontalResolution = 200;
SheetRender sr = new SheetRender(sheet, imgOptions);

for (int j = 0; j < sr.PageCount; j++)
{
sr.ToTiff(“e:\test2\mytiffimage.tiff”);

}

Aspose.Cells would render image files based on the print preview that is shown in Ms Excel. If a worksheet is blank, then Ms Excel does not show its print preview, hence no image would be rendered.

Thank you.

Shakeel, Amjad,

Thanks for the information.

I have used the latest version and it is working fine.

I have added a validation to check if the sheet render object contains any page (pagecount) before putting it to stream object.

Thanks for the help.

Regards,

Ganesh

Hi,


Good to know that your issue is resolved by the new version.

Feel free to contact us any time, if you need further help or have some other issues. We will be happy to assist you.

Thank you.