Merge Word- Excel and Images in one document

Hi,

I have the following requirement : I have a set of documents
(word, excel and potentially images that come from a PDF conversion)
and I would like to merge them all in one big document.

That big document will then be transformed in PDF. I am using the Java API.

I
was wondering how to insert an excel document in a word document. I
have read around the examples supplied with Java demos. Very very
impressive but there is nothing about interaction between XLS files and DOC files. I have found how to import the images in the document, how
to merge multiple word documents but I cannot find how to import an
Excel document in a Word document.

Moreover, I would like to
understand how to avoir pitfalls of XLS files that can contain too many
columns to be inserted in my document or how to insert them as
landscape, etc.

Can you help me please ?

Thanks in advance,

Boris

Hi Boris,
Thanks for your request. I think in your case, the best option is converting all your documents to PDF and then concatenate these PDFs using Aspose.Pdf.Kit:
https://docs.aspose.com/pdf/net/concatenate-pdf-documents/
You can use Aspose.Words to convert Word documents and Images to PDF:
https://docs.aspose.com/words/net/convert-a-document-to-pdf/
https://docs.aspose.com/words/net/convert-a-document/
Aspose.Cells will allow you to convert Excel documents to PDF:
https://docs.aspose.com/cells/net/convert-excel-workbook-to-pdf/
Aspose.Slides can be used to convert PowerPoint presentations to PDF:
https://docs.aspose.com/slides/net/convert-powerpoint-to-pdf/
Best regards,

Hi Alexey,

thank you for your answer. I have read that you wrote a converter from XLS to DOC (or the opposite ?).
Was it only for .NET ? because some tool like this would be great. I would like to keep the ability to edit some part of the document (XLS part and DOC part) in the final document.

Do you have any suggestion to be able to do that ? Can I “translate” an XLS grid to a DOC grid ?

Boris

Hi
Thanks for your request. I attached Java version of this converter here. Please let us know in case of any issues, we are always glad to help you.
Best regards,

Hi Alexey,

thanks a lot. I will try to use it and post the result.

Boris

I have tried to import this java class into eclipse. I have cells version 7.0.1 and word 7.0.1 jars in my classpath.

I have a lot of errors that are raised due to problems in API. For instance, NamedRange is not recognized. For which version your converter was done ?

Can I ask you few questions about the API ? I will translate the file for the version 7.0.2 I think.

thank you.

Boris

Hi Boris,
Thanks for your request. I updated the class for you. Please let us know if you need more assistance, we are always glad to help you.
Best regards,

Hi Alexey,

Thank you for the update. It is very kind. I have tried the converter on an XLS file. I encountered a problem : parsing is failing on cells that contains data that are formatted as number.
The exact error message is the following :

Exception in thread "main" java.lang.IllegalArgumentException: Malformed pattern "#,##0.00’ '€40"
at java.text.DecimalFormat.applyPattern(Unknown Source)
at java.text.DecimalFormat.(Unknown Source)
at com.aspose.cells.b.a.o.a(Unknown Source)
at com.aspose.cells.aR.b(Unknown Source)
at com.aspose.cells.aR.c(Unknown Source)
at com.aspose.cells.aR.a(Unknown Source)
at com.aspose.cells.aR.a(Unknown Source)
at com.aspose.cells.Cell.getStringValue(Unknown Source)
at ConverterXls2Doc.GetTextFromCell(ConverterXls2Doc.java:911)
at ConverterXls2Doc.ImportExcelCell(ConverterXls2Doc.java:276)
at ConverterXls2Doc.GetTablePart(ConverterXls2Doc.java:229)
at ConverterXls2Doc.GetTablePartsArray(ConverterXls2Doc.java:170)
at ConverterXls2Doc.Convert(ConverterXls2Doc.java:92)
at ConverterXls2Doc.main(ConverterXls2Doc.java:1370)

The format of the cell is monetary. Can you tell me how to fix it please ?

Thank you !

Boris

Hi Boris,
Thanks for your request. Could you please attach your Excel file here for testing? I will check it and provide you more information.
Best regards,

Hi Alexey,

the file is attached here.

Thank your for your time !

Boris

Hi
Thank you for additional information. Please try modifying GetTextFromCell method in the converter as shown below:

/// 
/// Get text with formating from Excel cell
/// 
/// Input Excel cell
/// Parent document
/// Run that contains text with formating
private Run GetTextFromCell(com.aspose.cells.Cell cell, Document doc) throws Exception
{
    Run run = new Run(doc);
    if (cell.getValue() != null)
    {
        run.setText(cell.getValue().toString().replace(ControlChar.LINE_FEED_CHAR, ControlChar.LINE_BREAK_CHAR));
        // Convert Excel Font to Words Font
        ImportFont(run.getFont(), cell.getStyle().getFont());
    }
    return run;
}

Hope this helps.
Best regards,

Hi Alexey,

Thank you for your answer.

This fix is not really what I expect. The fix ignores the error but I would like to support those number format and insert the value in the word document.

Could you explain me what the methode getStringValue() is doing please ? I can probably do some other parsing to support this.
My understanding (but I haven’t seen aspose code) is that the code is identifying the content of the cell as a double (that is what my debugger says).
When calling getStringValue() on cell, the code is probably searching in the style of the cell what the format is to give the exact representation to the caller. But the problem is that this is not a numeric but a currency. So the format returned is containing an euro symbol (in my case) and the DecimalFormat class is unable to generate the value since the euro sign cannot be parsed. And it is failing with an IllegalArgumentException. Am I on a good track ? Do I have to investigate in the style/format of the cell ?

Thank you,

Boris

Hi Boris,
Thanks for your request. I think, it would be better to ask this question in Aspose.Cells forum. My colleagues from Aspose.Cells team have more experience with Excel and Aspose.Cells. So they are standing on better position to help you with this matter.
Best regards,

Thanks a lot Alexey !

I post the question on the cells forum !

Cheers,

boris