Hi Amjad,
First, I manually created an Excel file and then insert my custom OLE object using MS Excel 2003 (please see the attachment ExcelMOLOLE.xls), then I use Aspose.Cell for Java to inspect OLE object properties. Here is the code I used to inspect my custom OLE object
package mypackage.aspose;
import java.io.FileInputStream;
import com.aspose.cells.OleObject;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
public class ExtractOleInfo {
/
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream(“ExcelMOLOLE.xls”);
Workbook wb = new Workbook(fis);
Worksheet sheet = wb.getWorksheets().get(0);
int oleCount = sheet.getOleObjects().getCount();
for (int i = 0; i < oleCount; i ++) {
OleObject oleObject = sheet.getOleObjects().get(i);
System.out.println(“oleObject.getFileType():” + oleObject.getFileType());
System.out.println(“oleObject.getMsoDrawingType():” + oleObject.getMsoDrawingType());
System.out.println(“oleObject.getPlacement():” + oleObject.getPlacement());
System.out.println(“oleObject.getLinkedCell():” + oleObject.getLinkedCell());
System.out.println(“oleObject.getProgID():” + oleObject.getProgID());
System.out.println(“oleObject.getName():” + oleObject.getName());
System.out.println(“oleObject.getImageSourceFullName():” + oleObject.getImageSourceFullName());
}
}
}
Then I tried to re-create the Excel which contain my custom OLE object, here is the code:
package mypackage.aspose;
import java.io.File;
import java.io.FileInputStream;
import com.aspose.cells.OleObject;
import com.aspose.cells.PlacementType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
public class TestAspose {
/
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
//Get the image file.
File file = new File(“sample.jpg”);
//Get the picture into the streams.
byte[] img = new byte[(int)file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(img);
//Get the excel file into the streams.
file = new File(“test.mol”);
byte[] data = new byte[(int)file.length()];
fis = new FileInputStream(file);
fis.read(data);
//Instantiate a new Workbook.
Workbook wb = new Workbook();
//Get the first worksheet.
Worksheet sheet = wb.getWorksheets().get(0);
//Add an Ole object into the worksheet with the image
//shown in MS Excel.
int oleObjIndex = sheet.getOleObjects().add(14, 3, 200, 220, img);
OleObject oleObj = sheet.getOleObjects().get(oleObjIndex);
//Set embedded ole object data.
oleObj.setObjectData(data);
oleObj.setPlacement(PlacementType.MOVE);
oleObj.setFileType(5);
oleObj.setProgID(“MDLDrawOLE.MDLDrawObject.1”);
oleObj.setName(“OleObject 1”);
wb.save(“test-with-mol-ole.xls”);
}
}
When I open up the Excel file created by Aspose.Cell in Excel 2003, the OLE object DID get inserted with the specified image, but when I double click the OLE object, MS Excel 2003 give me this error: Cannot start the source application for this object
How can I set the correct source application for my custom OLE object?
I’ve also attached the raw data file for my custom OLE object, it is created with the application Accelrys Draw 4.0, you can request an academic license to test it out.
If you need further information, just give me a shout, I will provide as much as I can.
Many thanks for your support!