Inserting OLE-object into Excel sheet

Hello,

I'm using aspose.cells for java.

Is it possible to insert an OLE-object into a sheet ?

I see the OLEobject class, but how do I retrieve the OLEobjects collection from a sheet ?

Sheet.getShapes --> Shape.AddOLEObject (I'll have a try)

Thanks,

Goddeau Hendrik

HGOAS4:

Hello,

I'm using aspose.cells for java.

Is it possible to insert an OLE-object into a sheet ?

I see the OLEobject class, but how do I retrieve the OLEobjects collection from a sheet ?

Sheet.getShapes --> Shape.AddOLEObject (I'll have a try)

Thanks,

Goddeau Hendrik

When addign an OLEobject to a sheet I have to provide image and object.

Can I pass these as FileInputStreams or do I have to byte data ?

Hi,

Yes, Aspose.Cells for Java supports to insert an Office document as OLE-object into sheet.

To process all OleObjects from a sheet, the code can like following:

Shapes shapes = sheet.getShapes();

int size = shapes.size();

for(int i=0; i<size; i++)

{

Shape shape = shapes.get(i);

if(shape instanceof OleObject)

{

OleObject ole = (OleObject)shape;

...

}

}

Hi,

Currenty you must build byte data from the file then use the byte data to create OleObject.

Can you provide it with InputStreams ?

We have to specify a total length of the byte stream and this length is not predictable !

Thanks !

Hi,

For total length of byte stream, I think it is more predictable for end users than us. Such as, if the InputStream is from a simple file, then you can use File.length() or inputStream.available() to get its length. For us to provide a uniform interface, we have to take all type of InputStreams as a common InputStream, it is always unpredictable and we have to use expandable buffer to hold datas read from it.

Anyway, if you really need such an interface, we will look into it.

The problem is that within RPG we can't pass parameters greater then 65535 bytes !!

Do I have to specify an image file ?

I want to embed an AVI-file.

HGOAS4:

The problem is that within RPG we can't pass parameters greater then 65535 bytes !!

Do I have to specify an image file ?

I want to embed an AVI-file.

Error --> Unsupported image format when calling addOleObject !!


Message ID . . . . . . : RNX0301 Severity . . . . . . . : 50
Message type . . . . . : Escape
Date sent . . . . . . : 08/07/24 Time sent . . . . . . : 12:07:34

Message . . . . : Java exception received when calling Java method.
Cause . . . . . : RPG procedure ACELLADDOL in program AAITMRMP1/ACELLSRV
received Java exception "java.lang.IllegalArgumentException: Unsupported
image foramt." when calling method "addOleObject" with signature
"(IIII[B[B)Lcom.aspose.cells.OleObject;" in class "com.aspose.cells.Shapes".
Recovery . . . : Contact the person responsible for program maintenance to
determine the cause of the problem.
Technical description . . . . . . . . : If the exception indicates that the
Java class was not found, ensure the class for the method is in the class
path. If the exception indicates that the Java method was not found, check
the method name and signature. If the signature is not correct, change the
RPG prototype for the method, or change the Java method, so that the return

New error :


Message . . . . : Java exception received when calling Java method.
Cause . . . . . : RPG procedure ACELLADDOL in program AAITMRMP1/ACELLSRV
received Java exception "java.lang.IllegalArgumentException: Could not get
image reader." when calling method "addOleObject" with signature
"(IIII[B[B)Lcom.aspose.cells.OleObject;" in class "com.aspose.cells.Shapes".
Recovery . . . : Contact the person responsible for program maintenance to
determine the cause of the problem.
Technical description . . . . . . . . : If the exception indicates that the
Java class was not found, ensure the class for the method is in the class
path. If the exception indicates that the Java method was not found, check
the method name and signature. If the signature is not correct, change the
RPG prototype for the method, or change the Java method, so that the return

Shapes.addOleObject(int p1, int p2, int p3, int p4, byte[] p5, byte[] p6)

Can you help me on the parameter description ?

Thanks

Hi,

The parameter as:

addOleObject(int row, int column, int left, int top, byte[] imageData, byte[] objectData)

For API document, please refer to the online document at http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/com/aspose/cells/package-summary.html.

For the embeded Object, currently Aspose.Cells for Java only support Office document such as Excel, Word, PPT.

Hello,

Will you provide embedding AVI-objects in the near future ?? (that's what we need)

Do you have any idea what causes error :

received Java exception "java.lang.IllegalArgumentException: Could not get
image reader." when calling method "addOleObject" with signature
"(IIII[B[B)Lcom.aspose.cells.OleObject;" in class "com.aspose.cells.Shapes".

Thanks !

Hi,

We will look into this feature and give you estimated time later if we can provide it.

For the Image error, which format of Image do you use? Do you read the image data fully into the byte array and make it as the parameter "imageData" in by calling addOleObject(int row, int column, int left, int top, byte[] imageData, byte[] objectData)?

If the error still persist, please attach your image file here, we will check it soon.

I now have another error : Unsupported image foramt

I do provide a byte array ! Do I have to add a null byte at the end ?

I will attach the image, as object I provide a simple excel.

Thanks !

Hi,

I have tested addOleObject with your attached image file, it works fine. I think maybe you did not read the image data fully and properly into the byte array. My code like following:

Workbook wb = new Workbook();
Shapes shapes = wb.getWorksheets().getSheet(0).getShapes();

shapes.addOleObject(0, 0, 0, 0,
readData(new FileInputStream("L46896.jpg")),
readData(new FileInputStream("t.xls")));
wb.save("tt.xls");

private byte[] readData(InputStream is) throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedInputStream bis = new BufferedInputStream(is);
byte[] buff = new byte[1024];
int c;
while((c=bis.read(buff)) > 0)
{
baos.write(buff, 0, c);
}
return baos.toByteArray();
}

When I provide 2 bytearrayoutputstreams to the procedure I get this error !!

In my previous example I provide 2 strings. --> Unsupported image format


Message . . . . : Java exception received when calling Java method.
Cause . . . . . : RPG procedure ACELLADDOL in program AAITMRMP1/ACELLSRV
received Java exception "java.lang.NoSuchMethodError: addOleObject" when
calling method "addOleObject" with signature
"(IIIILjava.io.ByteArrayOutputStream;Ljava.io.ByteArrayOutputStream;)Lcom.as
pose.cells.OleObject;" in class "com.aspose.cells.Shapes".

Hi,

Currently Shapes.addOleObject only accept byte[] as datasource for the OleObject's icon image data and object data. We are looking into supporting InputStream as datasource.

join:

Hi,

Currently Shapes.addOleObject only accept byte[] as datasource for the OleObject's icon image data and object data. We are looking into supporting InputStream as datasource.

Any idea when this will be available ?

Thanks.

Hi,

Hope we can provide you a patch supporting this feature in 1-2 days, please keep an eye on this thread.

Hi,

Now we support embedding AVI file as OleObject into the Excel file, and we also support use InputStream as the source of image data and OleObject data. please try this attached patch. there are two new methods added for Shapes object for this new feature:

public OleObject addOleObject(int row,
                              int column,
                              int left,
                              int top,
                              byte[] imageData,
                              byte[] objectData,
                              byte fileType,
                              java.lang.String sourceFullName)
Embed an OleObject in the worksheet. Take the file format as MS Office related document.

Parameters:
row - row index of the cell that shape's top-left corner in.
column - column index of the cell that shape's top-left corner in.
left - the horizontal offset of the top left corner of shape and cell, in unit of pixel.
top - the vertical offset of the top left corner of shape and cell, in unit of pixel.
imageData - data of Image as icon of the embeded object
objectData - data of the embeded object
fileType - the embeded object's file type, supproted file type see OleFileType.
sourceFullName - the ole native source full file name
Returns:
the new OleObject embeded in

public OleObject addOleObject(int row,
                              int column,
                              int left,
                              int top,
                              java.io.InputStream imageStream,
                              java.io.InputStream objectStream,
                              byte fileType,
                              java.lang.String sourceFullName)
Embed an OleObject in the worksheet.

Parameters:
row - row index of the cell that shape's top-left corner in.
column - column index of the cell that shape's top-left corner in.
left - the horizontal offset of the top left corner of shape and cell, in unit of pixel.
top - the vertical offset of the top left corner of shape and cell, in unit of pixel.
imageStream - InputStream of the Image as icon of the embeded object
objectStream - InputStream of the embeded object
fileType - the embeded object's file type, supproted file type see OleFileType.
sourceFullName - the ole native source full file name
Returns:
the new OleObject embeded in