Hello, I’m trying to create a image from excel file (ejemplo.xlsx) but Aspose Cells Java don’t convert all the sheets of that file in images.
we have this code in Java:
Workbook book = new Workbook(absolutePath);
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageFormat(ImageFormat.getJpeg());
WorksheetCollection sheets = book.getWorksheets();
for (int s = 0; s < sheets.getCount(); s++){
Worksheet sheet = book.getWorksheets().get(s);
SheetRender sr = new SheetRender(sheet, imgOptions);
for (int j = 0; j < sr.getPageCount(); j++){
sr.toImage(j, workDirUrl+“page”+j+“.”+this.getImageFormat());
}
}
The file images-test1.zip has the images converted from that excel file.
That we copy from → Converting Worksheet to Different Image Formats|Documentation
Now I’m trying to solve this problem by following the page → Combine Multiple Worksheets into a Single Worksheet|Documentation
All the sheets are converted to image but this new image, is not similar than source excel, please view the file images-test2.zip
Could you help us?, the excel file ejemplo.xlsx will be properly converted into an image.
We have Aspose-cells-7.5.0
Best regards
Martin
Hi,
Thanks for your posting and using Aspose.Cells for Java.
Please use the following code to convert all of your worksheets into images. We have attached the output images for your reference.
We have tested this issue with the latest version: Aspose.Cells
for Java v7.5.0.2.
Java
String filePath=“F:\Shak-Data-RW\Downloads\ejemplo.xlsx”;
Workbook workbook =
new Workbook(filePath);
for(
int i=0; i<workbook.getWorksheets().getCount(); i++)
{
Worksheet worksheet = workbook.getWorksheets().get(i);
ImageOrPrintOptions options =
new ImageOrPrintOptions();
options.setOnePagePerSheet(
true);
SheetRender sr =
new SheetRender(worksheet, options);
sr.toImage(0,
new FileOutputStream(filePath + i + “.
out.png”));
}
I could solve the problem with your help.
thanks a lot!
But I have one doubt, as you find out when a sheet is empty?, I use this code:
Range range = worksheet.getCells (). GetMaxDisplayRange ();
if (range.getValue ()! = null) {
/ / Process
}
This working properly, but I wanted to know if there is another way.
My complete code is:
Workbook sourceBook = new Workbook(absolutePath);
int pos = 0;
for(int i=0; i<sourceBook.getWorksheets().getCount(); i++){
Worksheet worksheet = sourceBook.getWorksheets().get(i);
Range range = worksheet.getCells().getMaxDisplayRange();
if (range.getValue()!=null){
/* the empty sheets are not converted to image */
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setOnePagePerSheet(true);
SheetRender sr = new SheetRender(worksheet, options);
sr.toImage(0, new FileOutputStream(workDirUrl+“page”+pos+"."+this.getImageFormat()));
pos ++;
}
}
Best regards.
Martin Fernandez
Hi,
Thanks for your posting and using Aspose.Cells for Java.
You can use the following code to check if the worksheet is empty or not.
Java
if(worksheet.getCells().getCount()==0)
{
//Worksheet is empty
}
Perfect!! thank you very much.
excellent support!
Best regards,
Martin Fernandez
Java Developer
Hi Shakeel, excuse me, Could you help me with this ticket, is related about pictures in black after converting PDF to images.
<a href="https://forum.aspose.com/t/83603
Thank you very much.
Martin Fernandez
Java Developer
Hi,
I am afraid, we cannot help you for the issues for another product. We only provide technical support for Aspose.Cells product family here. Since, your other query/ticket is related to some other product i.e. Aspose. Pdf posted in another forum (Aspose.Pdf forum), so kindly follow up and keep in touch with the Aspose.Pdf team in their forum, they will surely sort your issue out and respond you in your thread.
Thank you and have a good day!