There are libraries for Java developers that have tons of methods which do not work on Android.
I started by working with libraries like OpenCSV, but unfortunately Excel has known issues with opening CSV files.
Then I tried to use:
- Apache POI - It definitely has too many methods.
- JExcelAPI - It works, but only on old binary .xls files.
- docx4j - again too many jars, because it's based on JAXB which is not included in Android.
My question is, how can I create a simple Excel file in .xlsx format on Android, without exceeding 65k methods?
update of Axel Richter's answer:
If you don't need to read xlsx file from any sources i recommande you to use CSV excel is perfectly able to convert that type to any of its std output.
Even if you need formula, cell formatting, there are to way to did it use on of the lib you cite or using your own xml parser as said by many people before me, excel format is just a zip with xml inside. Those xml are describe here :
https://msdn.microsoft.com/en-us/library/dd979921(v=office.12).aspx
As you will discover excel is very complexe format and simple retrocompatibility is not their priority . So making your own restricted parser with XPath or JAXB will be an heavy work but not impossible.
But I don't understand why you want restrict number of methods ? if its about making some embedded sofware, in my opinion, you shouldn't use .xlsx, this is a to complicated and heavy file to just save grids ...
Use Apache POI and enable multi dex by simply adding
compile "com.android.support:multidex:1.0.1"
to your dependencies inbuild.gradle
. You also need to set multiDexEnabled true. That should get rid of the 65k method limitation.xlsx is a zip file. So we can extract zip and get xml files inside and then we can parse it ourself to get sheet data.
This should work for both For both xls and xlsx.
First answer: do it server-side.
If that's not possible, just use JExecelAPI - pretty much everything that reads xlsx files reads xls files too.
Every other Excel library is going to be way too big.
Another thought - write csv files, either manually, or with one of the many csv libraries available. Again, most applications that read Excel files read csv files too.
Since this question seems to be rather: "What is the most lightweight way creating Office Open XML files for Excel (
*.xlsx
)?", I will providing an example which does not need any libraries except the defaultjava.lang
,java.io
andjava.util.zip
.A
*.xlsx
file is nothing else than a ZIP archive containing XML files and other files in a directory structure. So all we need is a possibility for creating, reading and writing ZIP archives and creating, reading and writing XML files. For the ZIP part I am usingjava.util.zip
and for the XML part I am using string manipulation. This, creating and manipulating XML via string manipulation, is not the most recommended way for manipulating XML but it is the most lightweight way since it does not needs any additional XML libraries.Complete example: