Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create .docx files and .xlsx files on Android

I have a very simple question: How to create .docx and .xlsx files on Android. Before someone marks this as duplicate, let me tell you that I have extensively tried creating them using Apache POI and my attempts are described in these questions:

java.lang.NoClassDefFoundError while creating a .xlsx file using Apache POI

Creating a .docx file using poi-ooxml jar file

However, as described in those links, I am getting the java.lang.verify error. These are the jar files I have finally imported into my reference libraries:

  • dom4j-1.6.1.jar

  • poi-3.10-FINAL-20140208.jar

  • poi-ooxml-3.10-FINAL-20140208.jar

  • stax-api-1.0.1.jar

  • xmlbeans-2.3.0.jar

  • poi-ooxml-schemas-3.10-FINAL-20140208.jar

  • commons-codec-1.5.jar

  • commons-logging-1.1.jar

  • junit-4.11.jar

  • log4j-1.2.13.jar

but now it doesn't compile at all, and says this on the console

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.

[2014-02-19 16:59:24 - test] Dx 1 error; aborting
[2014-02-19 16:59:24 - test] Conversion to Dalvik format failed with error 1

Please advise as to what I am to do.

EDIT:

My end purpose is: I wish to create .docx and .xlsx files and add some content to them. Once the files are created, I should be able to successfully view them on the PC system which I have connected the phone to.

EDIT 2: Found a workaround to generate .xlsx files by removing all these dependencies and using jspreadsheet-1.0 jar file. But I still don't know what to do for .docx files.

UPDATED QUESTION:

It seems my problem lies with using the POI jar files which is not supported by Android. Can someone please supply me the link where I can get POI specifically for Android?

Or, can someone please tell me how to create .docx files to which I can add content, and such that they can be viewed?

like image 537
SoulRayder Avatar asked Feb 19 '14 10:02

SoulRayder


1 Answers

You can use docx4j to create .docx files.

docx4j is an open source (Apache v2) library for creating, editing, and saving OpenXML "packages", including docx, pptx, and xslx.

So you need to use JAXB-based Java library for Word docx.

This is a helpful tutorial for that: http://www.javacodegeeks.com/2012/07/java-word-docx-documents-with-docx4j.html

Then your next question "is that compatible with the android ? " Look at this: JAXB can be made to run on Android

I think this will help you.

like image 121
Zusee Weekin Avatar answered Oct 24 '22 05:10

Zusee Weekin