How can I convert an embedded excel file to Pdf?

Hi,

I am having a xml file which internally embedded with another xls file as a link.(attached here) .Now i have to generate a pdf of this xls file with the embedded file. How can I do this ?

Sample code :

String fileName="C:\\Test\\Book2.xlsx"

Workbook exl = new Workbook();

exl.open(fileName);

exl.save(pdfFileName, FileFormatType.PDF);

If I am doing like this the embedded file is not coming as a part of the generated Pdf.

Please help.

Hi,

Thanks for your interest in Aspose.Cells for Java.

In .NET version, there is a property OleObjects, which give you access to embedded objects. But I am not finding it in Java version. So it seems to me a new feature.

I have added it as a New Feature Request with id: CELLSJAVA-29103

Hi,


I think you may try to extract the OLE Objects from the Excel files, The Ole Objects are represented as Shapes in the sheet, see the document for your complete reference:
http://www.aspose.com/documentation/java-components/aspose.cells-for-java/managing-ole-objects.html

Thank you.

Hi,

For embedded excel file in excel97-2003 template file, please follow our previous reply of Amjad.

For excel2007 template file, currently we do not support to parse the embedded object into our OleObject model. So for this given template file “container.xlsx”, you cannot get the OleObject instance from the shapes collection.

We need to make further investigation to check whether we can support to parse OleObject from xlsx template file.

Hey,
This is working in 97-2003 version but the oles.get(i).getType() is coming as 8 i.e. MsoDrawingType.PICTURE. I have attached a 97 version xls file as embedded.

Any idea why its not coming as MsoDrawingType.OLE_OBJECT i.e. 24.

Hi,


As we told you in previous reply, for Excel2007 template file, currently we do not support to parse the embedded object into our OleObject model. So for this given template file “container.xlsx”, you cannot get the OleObject instance from the shapes collection.

We need to make further investigation to check whether we can support to parse OleObject from xlsx template file.

Updated:

Also, if you found the component cannot recognize
OleObjects in XLS template file, please post the template file and we will check
it soon.<o:p></o:p>

Hi,

Please find the 97-2003 version for which I tried. I could not get the Ole objects from it.

Hi ,

To minimise the confusion :

I need a toolkit for extracting embedded OLE objects from MS Word, Excel, PowerPoint, and PDF files.
(http://www.aspose.com/community/forums/90100/i-need-a-toolkit-for-extracting-embedded-ole-objects-from-ms-word-excel-powerpoint-and-pdf-files/showthread.aspx#90100)

I got the solution for .NET in the Aspose forum. But I need it in java.


Please help.

Hi,

Your file seems to me corrupt. Because I could not extract the OLE object from it using Ms-Excel 2010.

It gives me error. Please see the screenshot.


The file is searching the embedded file in the path specified as my system. ie. C:\ziptest\Embedded_97.xls.

You please create a xml file with embedded with another xml as per your file location.

Hi,

Please see the code below and the source.xls attached by me. It contains an embedded xls file. The code extracts the embedded xls file and write it as source.xls.out-0.xls

I have attached both the source and output xls files.

Java


String path = “F:\Shak-Data-RW\Downloads\Files\source.xls”;


//Instantiating a Workbook object

Workbook workbook = new Workbook();


//Open the template file.

workbook.open(path);


//Get the OleObject Collection in the first worksheet.

Shapes oles = workbook.getWorksheets().getSheet(0).getShapes();


//Loop through all the ole objects and extract each object.

//in the worksheet.


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

{

if (oles.get(i).getType() == MsoDrawingType.OLE_OBJECT)

{

OleObject ole = (OleObject)oles.get(i);


//Specify the output filename.

String fileName = path + “.out-” + i + “.”;


//Specify each file format based on the oleformattype.

switch (ole.getFileType())

{

case OleFileType.DOC:

fileName += “doc”;

break;


case OleFileType.XLS:

fileName += “xls”;

break;


case OleFileType.PPT:

fileName += “Ppt”;

break;


case OleFileType.PDF:

fileName += “Pdf”;

break;


case OleFileType.UNKNOWN:

fileName += “Jpg”;

break;


default:

fileName += “data”;

break;

}//switch


FileOutputStream fos = new FileOutputStream(fileName);

byte[] data = ole.getObjectData();

fos.write(data);

fos.close();


}//if

}//for