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

Free Support Forum - aspose.com

Embedded rar and zip files

Hello,
when I attach embedded files as OleObject and this file is rar or zip, after save excel file on disk, and then open it by office 2013, i can’t open those files.

In general i’m working with office 2013

I got message as u can see in attachment.
In attachment u can find as well result file.

Code :

public class ZipRarTest {

public static void main(String[] args) throws Exception {
// LICENSE
FileInputStream fstream = new FileInputStream(“C:\Users\malolepj\IdeaProjects\excel_gbp\Aspose.Total.Java.lic”);
License license = new License();
license.setLicense(fstream);

Workbook workbook = new Workbook(“C:\Users\malolepj\excel_test2\Book1.xlsx”);

Worksheet worksheet = workbook.getWorksheets().get(0);
OleObjectCollection oleObjectCollection = worksheet.getOleObjects();

int objectNumber = 0;
for (Object anOleObjectCollection : oleObjectCollection) {
String fileName = “C:\Users\malolepj\excel_test2\rarTest\object” + objectNumber++;
OleObject oleObject = (OleObject) anOleObjectCollection;
// fileName+="" + oleObject.getObjectSourceFullName();
switch (oleObject.getFileFormatType()) {
case FileFormatType.DOCX:
fileName += “.docx”;
break;
case FileFormatType.XLSX:
fileName += “.xlsx”;
break;
case FileFormatType.PPTX:
fileName += “.Ppt”;
break;
case FileFormatType.PDF:
fileName += “.Pdf”;
break;
case FileFormatType.UNKNOWN:
if (oleObject.getProgID().equals(“Acrobat Document”)) {
fileName += “.pdf”;
} else {
fileName += “.bin”;
}
break;
default:
if (oleObject.getProgID().equals(“Packager Shell Object”)) {
if (oleObject.getSourceFullName().contains(".rar")) {
fileName += “.rar”;
} else if (oleObject.getSourceFullName().contains(".zip")) {
fileName += “.zip”;
} else {
fileName += “.data”;
}
} else {
fileName += “.data”;
}

break;
}

FileOutputStream fos = new FileOutputStream(fileName);
byte[] data = oleObject.getObjectData();
fos.write(data);
fos.close();
}

Workbook resultWorkbook = new Workbook(“C:\Users\malolepj\excel_test2\empty.xlsx”);
// Worksheet sheet = resultWorkbook.getWorksheets().get(“Attachments”);
Worksheet sheet = resultWorkbook.getWorksheets().get(0) ;

byte[] excelImgData = getObjectByteData(new File(“C:\Users\malolepj\excel_test2\img.jpg”));

File folder = new File(“C:\Users\malolepj\excel_test2\rarTest\”);
int i = 1;
for (final File fileEntry : folder.listFiles()) {

if (!fileEntry.isDirectory()) {
System.out.println(fileEntry.getName());

int oleObjIndex = sheet.getOleObjects().add(7, i++, 90, 90, excelImgData);
OleObject oleObj = sheet.getOleObjects().get(oleObjIndex);

oleObj.setProgID(“Packager Shell Object”);
oleObj.setFileFormatType(35);
oleObj.setFileType(10);

oleObj.setObjectData(getObjectByteData(fileEntry));
oleObj.setDisplayAsIcon(true);
oleObj.setFileFormatType(FileFormatType.UNKNOWN);

}
}

resultWorkbook.save(“C:\Users\malolepj\excel_test2\rar.xlsx”);

}

public static byte[] getObjectByteData(File file) throws IOException {

byte[] img = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(img);

return img;
}
}

Hi Jack,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue. After inserting RAR file as OLE object, it does not open well in MS-Excel and it shows error message "Cannot start the source application for this object."

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSJAVA-40931.

Hi,

We have analyzed your issue further. If the file format is not supported by MS Excel, please set source file name of Ole object because MS Excel starts application by the file's extension for these file.

Please try the following codes:

e.g

Sample code:


for (final File fileEntry : folder.listFiles()) {

if (!fileEntry.isDirectory()) {

System.out.println(fileEntry.getName());

int oleObjIndex = sheet.getOleObjects().add(7, i++, 90, 90, excelImgData);

OleObject oleObj = sheet.getOleObjects().get(oleObjIndex);

oleObj.setProgID("Packager Shell Object");

if(fileEntry.getName().contains(".rar") || fileEntry.getName().contains(".zip"))

{

oleObj.setObjectSourceFullName(fileEntry.getName());

}

oleObj.setObjectData(getObjectByteData(fileEntry));

oleObj.setDisplayAsIcon(true);

oleObj.setFileFormatType(FileFormatType.UNKNOWN);

}

}


Thank you.

Hello ,
this coda absolutely works corectly.
Thanks for so quick answer.

Hi,


Good to know that your issue is resolved now. Feel free to contact us any time if you need further help or have some other issues or queries, we will be happy to assist you soon.

Thank you.