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

Free Support Forum - aspose.com

Add attachments to Word Doc

Hi there,

Do you have any API to add attachments to a Word document, like you do to attach on PDF docs?
Similar to “fileSpecification”.

Best regards,
Filipe Ribeiro

Hi Filipe,

Thanks for your inquiry. Please use DocumentBuilder.InsertOleObject method (String, String, Boolean, Boolean, Image) to insert an embedded or linked OLE object from a file into the document.

If your still face problem, please share your expected output document here for our reference. We will then provide you more information about your query along with code.

Best Regards,
Tahir Manzoor
Aspose - File Format APIs

Keep in touch! We’re on Twitter and Facebook

Hello Tahir,

Thanks for your help. Now, I have another problem.
I need to get the attachment as FileInputStream, but the method DocumentBuilder.InsertOleObject needs a progID.
What is that and how do I know the correct progID for a certain file type?

Best Regards,
Filipe Ribeiro

Hi Filipe,

Thanks for your inquiry. The ProgID stands for “programmatic identifier”. The ProgID is stored in document binary as string e.g. Word.Document.12, Excel.Sheet.12 etc. I am afraid, there is no such list. We just extract it from there. But we can provide a list of OLE ProgID found in our test documents:

  • MS_ClipArt_Gallery
  • Equation.3
  • WPGraphic21
  • MIDFile
  • MSGraph.Chart.8
  • PBrush
  • MSPhotoEd.3
  • Excel.Sheet.8
  • Excel.Sheet.12
  • WordPad.Document.1
  • Package
  • Word.Document.8
  • Word.Document.12
  • Visio.Drawing.11

Please attach your expected document here for our reference. We will investigate the structure of your expected document how you want your final output be generated like. We will then provide you more information on this.

Hi,

I’m using Java, by the way.

Isn’t possible having any Object that when I pass the InputStream, it calculates the ProgID?

Best Regards,
Filipe Ribeiro

Hi Filipe,

Thanks for your inquiry. The stream object does not contain the information about ProgID. So, you need to pass it in DocumentBuilder.insertOleObject method. Please let us know if you have any more queries.

Hello Tahir,

I’ve managed to do that part. I have another question.

Is possible to choose the font to what I write in builder.write("…")?

Best Regards,
Filipe Ribeiro

Hi Filipe,

Thanks for your inquiry. Yes, you can set the font formatting of text. Please refer to the following article:
Specifying Formatting

Hello again,

I’m almost there. Just one more thing…

When I export an Excel document as attachment on PDF files, that Excel attachment is presented with Excel icon. But when I export it on Word files, this attachment is presented with “general” icon (Packager).

Is there any way to show Excel icon on Word too?

Best Regards,
Filipe Ribeiro

@fcri,

Please use the ProgID Word.Document.12 for Word document and Excel.Sheet.12 for Excel document in DocumentBuilder.insertOleObject method. Hope this helps you.

If you face any issue, please share your input and expected output documents. We will then provide you more information about your query.

Best Regards,
Tahir Manzoor

Hi Tahir,

Now I can show Excel icon. But when I try to open the Excel file, this message appears.
Screenshot_1.jpg (21.1 KB)
Do you want me to send you the generated document?

Best Regards,
Filipe Ribeiro

@fcri,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

Best Regards,
Tahir Manzoor

Hi Tahir,

Sorry for the delay,

AsposeConverter.zip (36.3 KB)

I hope this helps you.

Best Regards,
Filipe Ribeiro

@fcri

Thanks for sharing additional information. I am afraid I am unable to test your shared code due to missing reference. Furthermore, It seems you are using Aspose.Words for Java 16.7. I have tested the scenario with sample XLSX file using latest version of Aspose.Words and I am getting same error with your expectedOutput.docx file and my resultant Word document. Please check attached sample output document at your end and confirm, so we will log the issue accordingly.
testInsertxlsx.zip (16.3 KB)

We are sorry for the inconvenience.

Best Regards,

@tilal.ahmad

I’ve managed to avoid that error by using another insertOleObject constructor: (String fileName, String progID, boolean isLinked, boolean asIcon, BufferedImage presentation).

The problem was the way I was creating the FileStream.

Thanks for your help!

Best Regards,
Filipe Ribeiro

@fcri

Thanks for your feedback. It is good to know that you have managed to resolve the issue.

Please keep using our API and feel free to contact us for any further assistance.

Best Regards,