How to read xlsx file in an android application?

14,687

Solution 1

Apache POI 3.5 have added support to all the OOXML (docx, xlsx, etc.)

See the XSSF sub project

Solution 2

Just committed XSSF Android usage demo on github:

https://github.com/andruhon/AndroidReadXLSX

The core idea is just to remove from poi-ooxml and poi-ooxml-schemas all files which are seems to be not necessary to read XLSX. For example xslf and xwpf from poi-ooxml, schemas presentationml and wordrpocessingml from poi-ooxml-schemas and other stuff...

After that, build your project and try to read XLSX, read log after that fails and see which dependency caused this fail, copy missed file from original poi-ooxml-schemas jar. Do it again and again unless it is working.

UPD: no more need in --core-library option!
http://blog.kondratev.pro/2014/09/reading-xlsx-on-android-3.html

Demo mentioned above already contains reduced poi-ooxml and poi-ooxml-schemas.

Share:
14,687
benleung
Author by

benleung

Updated on June 07, 2022

Comments

  • benleung
    benleung almost 2 years

    I know there's many same questions on stackoverflow, but it seems that I can't see any possible solution for reading the content of xlsx.

    What I have try:

    I have try to put the whole Apache POI library to an android application and try to read the xlsx file. However, the problem is that the Apache POI library is too heavy to put into an android application. An error message shows that the Dalvik VM cannot execute an app with more than 65536 methods.

    It there any way to read the content of the xlsx file (could be the content only, other formatting such as color/width of the cell is not important) in an android app? Or it there any one tried to trim down the apache poi library so that Dalvik VM can execute it? As I saw that QuickOffice from Google Play are also using Apache POI, but I really don't know how to put the POI into an app. Thanks so much.

  • benleung
    benleung over 10 years
    That's mean it is possible to only extract the XSSF/HSSF part of Apache POI?
  • Gagravarr
    Gagravarr over 9 years
    The latest version of Apache POI (3.11 beta 2) has no stax dependency, and no dom4j dependency, so you might well be better off starting from that release as it'll be simpler
  • Andrew Kondratev
    Andrew Kondratev over 9 years
    It actually depends on stax in case with android and even more, because it depends on xml beans which uses some javax methods which are not implemented in android. ---- But copying stax won't help in this case because this beta attempts to use javax.xml.stream.XMLEventFactory and fails.
  • Andrew Kondratev
    Andrew Kondratev over 9 years
    So, only 3.10-final for a moment.
  • Andrew Kondratev
    Andrew Kondratev over 9 years
    UPD: no more need in --core-library option!
  • user
    user almost 9 years
    Hi Andrew i am using 3.10-final for read xlsx file but getting java.lang.reflect.InvocationTargetException also added dom4j-1.6.1 need urgent please suggest something to make it working for me.
  • HF_
    HF_ about 5 years
    That's a very large project and can't be used in an Android application.