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

Free Support Forum - aspose.com

Image output to Excel

I tried to convert a table to excel format. The first column of the table is a picture in byte array format, so I iterate over all rows and columns to save all the data into a workbook, but I found that I only can get the first 10 or more images correctly inserted, the rest are all red cross.
Here is the code, am I doing anything wrong?


private Workbook createExcelWorkbook(){

Workbook workbook = new Workbook();
Worksheet workSheet = workbook.getWorksheets().getSheet(0);
Cells cells = workSheet.getCells();
cells.insertRows(0,table.getRowCount()+1);
cells.insertColumns(0,table.getColumnCount());

for(int i=0;i<table.getRowCount()+1;i++){
if(i!=0){
cells.setRowHeightPixel(i,300);
}
for(int j=0;j<table.getColumnCount();j++){
if(i==0){
String colName = table.getColumnName(j);
Cell cell = workSheet.getCells().getCell(0, j);
cell.setValue(colName);
}else{
Object o = table.getValueAt(i - 1, j);
if(o instanceof DesignMolecule){ //DesignMolecule is a customer object
cells.setColumnWidthPixel(j,300);
Molecule molecule = ((DesignMolecule) o).getMolecule().cloneMolecule();
molecule.clean(2,null); //beautify the molecule
byte[] rawPic = molecule.toBinFormat(“jpeg:w250,h250”); // convert it to image byte array
try {
File temp = File.createTempFile(“Image”, “.jpg”);
OutputStream out = new FileOutputStream(temp);
out.write(rawPic);
out.close();
//ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(rawPic);
String path = temp.getAbsolutePath();
System.out.println(path);
workSheet.getShapes().addPicture(i,j, path);
} catch (IOException e) {
e.printStackTrace();
continue;
}

}else{
Cell cell = workSheet.getCells().getCell(i, j);
cell.setValue(o);
}
}
}
}

return workbook;
}

thanks,


Hi,

We have tested our latest fix by inserting about 20 pictures and it worked fine. Would you please try this fix at https://forum.aspose.com/t/67707? If you still get such issue, please send us your image data and we will check it soon . Thank you.

This patch is much better, now it broke after produced 175 images correctly. However, in some cases, we may need to export a few thousand images, is it possible?


Hi,

We have tested the fix by inserting 400 pictures and it worked fine. Would you please save all the images as files(not temporary file) and then create the Pictures by those files? If it cannot work well with those normal files, please send us those files and we will check it soon. Thank you.

Here are the images produced from a public data set.
There are about 2300 of them. All can be viewed under MacOS, but failed to be inserted into excel after a certain number.

code I used to insert:
for(int i=0;i<2339;i++){
String fname = String.format(“aspose_test_%d.jpg”,i);
File temp = new File(fname);
String path = temp.getAbsolutePath();
workSheet.getShapes().addPicture(i,0, path);
}

Hi,

Thank you for sharing the image files. We will further look into your issue and get back to you soon.

Thank You & Best Regards,

Hi,

Well, I tried a test case inserting all your pictures using the following code with the latest version (attached) and it works fine:

Workbook wb = new Workbook();
Worksheet workSheet = wb.getWorksheets().getSheet(0);
for(int i=1;i<2339;i++){
String fname = String.format(“e:\files\chart2image\aspose_test_%d.jpg”,i);
File temp = new File(fname);
String path = temp.getAbsolutePath();
System.out.println(path);
workSheet.getShapes().addPicture(i,0, path);
}

wb.save(“e:\files\outTest.xls”);


(Note: the only thing i have to do is extend some jvm memory to avoid out of memory exception)

Could you try the attached version and let us know if you still find the issue. If so, kindly show your environment details here. We will check it soon.


Thank you.

Sorry, I forgot to mention: I’m using MS excel 2004 for Mac OS Version 11.5.5.


Hi,

Thanks for sharing us some details.

We will look into it and get back to you soon.

Thank you.

I was able to load the excel file into windows excel correctly, but for Mac it is a complete mess.

Jun

Hi,

We will check your issue on MAC environment and get back to you soon.

Thank you.

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

Thank you for considering Aspose.

Please try the attached latest version of Aspose.Cells for Java. We have fixed your mentioned issue regarding Mac OS.

Thank You & Best Regards,

Fantastic!! It works great!!!

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


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