This repository has been archived by the owner on May 15, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
182 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#Reading and Writing XLSX on Android 5 | ||
Reading and Writing XLSX and XLS on Android 5 with Apache POI | ||
|
||
It was quite a challenging task to use Apache POI on android with Dalvik VM. It is much easier to use Apache POI on Android 5+ with ART VM and Build Tools 21+ | ||
|
||
Please refer to https://github.com/andruhon/AndroidReadXLSX if you need to read XLSX on Android 4 with Dalvik VM. | ||
|
||
#Contents | ||
I've repacked poi-ooxml to contain all dependencies in order to read and write XLSX (XLS as well, obviously) | ||
All javax classes from the STAX library and calls to them are renamed to aavax, to avoid --core-library warning and conflicts. | ||
|
||
* poi-3.12-android-a.jar //Repacked POI with all dependencies | ||
* poi-ooxml-schemas-3.12-20150511-a.jar //original schemas jar | ||
|
||
Copy these two jars into your project's libs directory and use gradle config similar to [build.gradle](build.gradle) from this repo. | ||
|
||
It will also work if you use all original files from https://poi.apache.org/download.html, however you need to re-pack xmlbeans-2.6.0.jar because for some reason it contains duplicates and Android does not like it. See (below)[#Contents of poi-3.12 jar] for contents of jar and details of javax -> aavax hack. | ||
|
||
#Configuration | ||
Please find gradle app configuration with comments in the build.gradle, the crucial thing is to enable multi-dex. | ||
|
||
#Auto-downloading dependencies | ||
This might also be achieved by adding 'org.apache.poi:poi-ooxml:3.12' into dependencies, but it is not very straightforward because it is required to add some routine to re-pack xmlbeans and disable preDex. It will work. however the build process will be very slow, so it is easier just to prepare jars once and put them into libs directory (as described above) | ||
|
||
|
||
#Usage example | ||
Please find usage example in [example](example) | ||
|
||
|
||
#Contents of poi-3.12 jar | ||
* poi-3.12-20150511.jar | ||
* poi-ooxml-3.12-20150511.jar | ||
* stax-1.2.0.jar | ||
* stax-api-1.0.1.jar | ||
* *xmlbeans-2.6.0.jar* //this one contained duplicates, Android does not like it | ||
|
||
|
||
#javax -> aavax hack | ||
the following classes and calls to them were renamed (as HEX strings + renaming namespace dir javax to aavax): | ||
* javax/xml/namespace -> aavax/xml/namespace | ||
* javax.xml.namespace -> aavax.xml.namespace | ||
* javax/xml/stream -> aavax/xml/stream | ||
* javax.xml.stream -> aavax.xml.stream | ||
* javax/xml/XMLConstants -> aavax/xml/XMLConstant | ||
* javax.xml.XMLConstants -> aavax.xml.XMLConstants | ||
|
||
Please note that you'd better not replace all javax to aavax, because there might be calls other classes from javax package which are available in android. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
example/app/src/main/java/pro/kondratev/xlsxpoiexample/ShareContentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package pro.kondratev.xlsxpoiexample; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
|
||
import android.content.ContentProvider; | ||
import android.content.ContentValues; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.os.ParcelFileDescriptor; | ||
|
||
/** | ||
* This is just a share content provider, | ||
* IT IS IRRELEVANT TO THE EXAMPLE BY ITSELF | ||
*/ | ||
public class ShareContentProvider extends ContentProvider { | ||
|
||
|
||
@Override | ||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { | ||
File cacheDir = getContext().getCacheDir(); //may produce NullPointer | ||
File privateFile = new File(cacheDir, uri.getLastPathSegment()); | ||
return ParcelFileDescriptor.open(privateFile, ParcelFileDescriptor.MODE_READ_ONLY); | ||
} | ||
|
||
@Override | ||
public boolean onCreate() { | ||
// no create | ||
return false; | ||
} | ||
|
||
@Override | ||
public Cursor query(Uri uri, String[] projection, String selection, | ||
String[] selectionArgs, String sortOrder) { | ||
// no query | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getType(Uri uri) { | ||
// no get type | ||
return null; | ||
} | ||
|
||
@Override | ||
public Uri insert(Uri uri, ContentValues values) { | ||
// no insert | ||
return null; | ||
} | ||
|
||
@Override | ||
public int delete(Uri uri, String selection, String[] selectionArgs) { | ||
// no delete | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int update(Uri uri, ContentValues values, String selection, | ||
String[] selectionArgs) { | ||
// no update | ||
return 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters