Free Support Forum - aspose.com

Getting Null Bitmap while generating image from Excel Worksheet using Aspose Cells Tool

Hi,

I am working with Aspose Cells to generate image of an
Excel worksheet using Aspose Cell tool. we have licence version of
Aspose Cells, we are using 7.4.0.0 version for Aspose Cells dll, when i am going to generate image from Excel Worksheet it
is giving me Null Bitmap for perticular Excel sheet, it is working fine
with other Excel sheet,
Below is the code regarding this -

AsposeCell.Workbook book = new AsposeCell.Workbook(selectedDocumentPath);
if (sheetNo >= 1 && sheetNo <= book.Worksheets.Count)
{
AsposeCell.Worksheet sheet = book.Worksheets[sheetNo - 1];
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
imgOptions.OnePagePerSheet = true;

<span style="color:#2b91af;">SheetRender</span> sr = <span style="color:blue;">new</span> <span style="color:#2b91af;">SheetRender</span>(sheet, imgOptions);
<b>Bitmap bitmap = sr.ToImage(0);</b>

}here it is giving me Null bitmap, please let me know if any one have solution.
Please find the attached Excel Sheet.

Thanks for your response in advance

Hi,


This is not an issue with our component rather it is an issue with your code. See my updated code that works absolutely fine and check the comments that I pasted below in the code.


Sample code:

Workbook book = new Workbook(“e:\test2\failed-test±+Copy.xlsx”);
int sheetNo = 2; ;

//Since at 0 indexed position in the workbook, there is a hidden worksheet (named “JaneRequest”), so you cannot render the image
//from the hidden sheet, so it is better to start with sheetNo as 2 instead of 1 or unhide the sheet.

if (sheetNo >= 2 && sheetNo <= book.Worksheets.Count)
{
Worksheet sheet = book.Worksheets[sheetNo - 1];
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
imgOptions.OnePagePerSheet = true;

SheetRender sr = new SheetRender(sheet, imgOptions);
Bitmap bitmap = sr.ToImage(0);
//Save the bitmap if you want.
bitmap.Save(“e:\test2\outputcopyimage.jpg”, ImageFormat.Jpeg);

}

Hope, this helps,

Let us know if you have any other issue.

Thank you.

Hi,

Thanks for your response, you are right the bug is not in your product, i was not aware that the Excel sheet contains hidden sheet, now i am able to fix the problem.

Thank you again

Hi,

Thanks for your posting and using Aspose.Cells.

We are pleased to know your issue is now resolved. If you encounter any other issue, please feel free to post, we will be glad to help you more.