Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Programmatically Create a Word Document Containing Images on an Android?

On an Android, I want to programmatically create a word document (which will contain images) with UTF-8 support.

Actually I am looking for a standard lightweight library.

like image 929
Mojtaba Yeganeh Avatar asked Mar 08 '14 12:03

Mojtaba Yeganeh


People also ask

How can I open Word programmatically in Android?

Here is the complete way to open . doc file in Android 7.0 or less: Step-1: First of all, place your pdf file in assets folder like the following screenshot. Step-3: Now add a new java file which should extend from FileProvider Like in my case file name is LegacyCompatFileProvider and code inside of it.

How do I create a Dox file?

Select the folder where you want to save your document. The dialog box will open > Select "Save as" > In the "Save as type" menu > Select the option "Word document (. docx)" > Click on the "Save as" button and a copy of your file will be saved in Docx format.


3 Answers

You have only a few options available:

  • Aspose.Words for Android (reads and creates docs)
  • Apache POI (poor support)
  • OliveDOCLibrary for Android (only reads)

Your best bet is on Aspose.Words for what you are looking for, but it comes with a price. Other two options are free and open source.

like image 131
Bruno Borges Avatar answered Sep 28 '22 02:09

Bruno Borges


I can't Find Any Library To Work With Word Documents

I used Itext For Creating PDF files instead of Word Documents

like image 35
Mojtaba Yeganeh Avatar answered Sep 28 '22 02:09

Mojtaba Yeganeh


This question is quite old, but as I had the same problem and was looking for a solution for a long time, I would like to point out these two free options:

https://github.com/centic9/poi-on-android

This enables you to create a custom Apache POI .jar-file with only the necessary parts of POI for your task, as POI is capable of handling other document types as well.

To enable word support with image handling for the custom jar, you would have to remove the following lines from the build.gradle file in the poishadow folder:

exclude 'org/apache/poi/wp/**' exclude 'org/apache/poi/xwpf/**' exclude 'org/openxmlformats/schemas/drawingml/**' exclude 'org/openxmlformats/schemas/wordprocessingml/**'

Then build the project according to the documentation mentioned in the README of the project. This is necessary because the standard POI would not run on Android out of the box because of some not supported dependencies (javax etc.) and number of methods limit.

An alternative would be https://github.com/leonardoanalista/java2word which is also not optimized for Android, but has almost no dependencies and can be made to run on Android. It is only capable of creating .doc-files, but it is very easy to work with and to customize (A little bit of effort is necessary to support images on Android, to base64-encode them in the Android way.) This solution has some limitations when it comes to files with lots of images, as the files get quite big.

like image 27
Steve Avatar answered Sep 28 '22 03:09

Steve