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

Free Support Forum - aspose.com

Question about ExportSheetToImageFile Bitmap

HI. my name is sungtaek choi from south KOREA, working as software engineer.

i have the ASPOSE.Cells for.NET 8.3 License and i would like to ask you about ExportSheetToImageFile.

my job is after making excel file, capture image first of the excel sheet and save it as .bmp file

sometimes it works completely
but sometimes it does not work.
when job is fail, making excel file is ok
but image file is not made.

this is the sentence where error is occurred
Bitmap bitmap = sr.ToImage(0);

and this is the error messagese
Aspose.Cells.CellsException: The parameter is invalid.

i dont’ know why
sometimes it works well
but sometimes it does not work

please give me advice
thanks

Hi,


Thanks for your posting and using Aspose.Cells.

Please make sure you are not setting ImageOrPrintOptions.OnePagePerSheet as true. Because if you will set one page per sheet property to true, then Aspose.Cells will try to print entire worksheet contents on a single image.

This works good if the entire worksheet is like 3-10 pages but if entire worksheet has many pages, then SheetRender.ToImage() will throw exception e.g. parameter is invalid etc.

hi. i’m very sorry to say that i could not let you know exactly.

here is the option


bool bResult = false;
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
imgOptions.OnePagePerSheet = true;

SheetRender sr = new SheetRender(wbReport.Worksheets[strSheetName], imgOptions);

Bitmap bitmap = sr.ToImage(0); -> error occured

bitmap.Save(strImagePath);


as you can see. OnePagePerSheet = true;

sometimes it work well.

but sotimes it does not work well

there is no different(same format, same number of sheet)

is there anything to check??

Hi,


Thanks for your sample code and using Aspose.Cells.

Please change the following line of code

imgOptions.OnePagePerSheet = true;

into

imgOptions.OnePagePerSheet = false;

and it should resolve your exception issue. Let us know if you still have any question, we will look into it and help you asap.