supercilex / poi-android Goto Github PK
View Code? Open in Web Editor NEW๐ Apache POI for Android
License: Apache License 2.0
๐ Apache POI for Android
License: Apache License 2.0
Hi, I am getting thit error in unit testing, even when I am not using POI in that test:
`javax.xml.stream.FactoryConfigurationError: Provider for class javax.xml.stream.XMLInputFactory cannot be created
at java.xml/javax.xml.stream.FactoryFinder.findServiceProvider(FactoryFinder.java:371)
at java.xml/javax.xml.stream.FactoryFinder.find(FactoryFinder.java:314)
at java.xml/javax.xml.stream.FactoryFinder.find(FactoryFinder.java:227)
at java.xml/javax.xml.stream.XMLInputFactory.newFactory(XMLInputFactory.java:225)
at org.robolectric.res.StaxDocumentLoader.(StaxDocumentLoader.java:22)
at org.robolectric.res.ResourceTableFactory.parseResourceFiles(ResourceTableFactory.java:122)
at org.robolectric.res.ResourceTableFactory.lambda$newFrameworkResourceTable$0(ResourceTableFactory.java:27)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
at org.robolectric.res.ResourceTableFactory.newFrameworkResourceTable(ResourceTableFactory.java:13)
at org.robolectric.android.internal.AndroidTestEnvironment.getSystemResourceTable(AndroidTestEnvironment.java:334)
at org.robolectric.android.internal.AndroidTestEnvironment.injectResourceStuffForLegacy(AndroidTestEnvironment.java:360)
at org.robolectric.android.internal.AndroidTestEnvironment.loadAppPackage_measured(AndroidTestEnvironment.java:303)
at org.robolectric.android.internal.AndroidTestEnvironment.lambda$loadAppPackage$1(AndroidTestEnvironment.java:296)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
at org.robolectric.android.internal.AndroidTestEnvironment.loadAppPackage(AndroidTestEnvironment.java:294)
at org.robolectric.android.internal.AndroidTestEnvironment.installAndCreateApplication(AndroidTestEnvironment.java:195)
at org.robolectric.android.internal.AndroidTestEnvironment.setUpApplicationState(AndroidTestEnvironment.java:171)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:319)
at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:269)
at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.RuntimeException: Provider for class javax.xml.stream.XMLInputFactory cannot be created at java.xml/javax.xml.stream.FactoryFinder.findServiceProvider(FactoryFinder.java:368) ... 23 more Caused by: java.util.ServiceConfigurationError: javax.xml.stream.XMLInputFactory: com.fasterxml.aalto.stax.InputFactoryImpl not a subtype at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:588) at java.base/java.util.ServiceLoader.access$200(ServiceLoader.java:390) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1231) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1259) at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1294) at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1379) at java.xml/javax.xml.stream.FactoryFinder$1.run(FactoryFinder.java:353) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.xml/javax.xml.stream.FactoryFinder.findServiceProvider(FactoryFinder.java:342) ... 23 more`
When I am using that in android runtime, it works very well using the next property definitions:
System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl"); System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl"); System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl");
But I can't define them in unit testing.
I want to know the count of pages of excel sheet and I am trying to do this by using the below code but I am getting an exception.
public static int getExcelSheetCount(String filePath) {
int sheetCount = 0;
OPCPackage myFileSystem = null;
try {
// Creating Input Stream
File file = new File(filePath);
FileInputStream myInput = new FileInputStream(file);
// Create a POIFSFileSystem object
myFileSystem = OPCPackage.open(file);
// Create a workbook using the File System
XSSFWorkbook myWorkBook = new XSSFWorkbook(myFileSystem);
sheetCount = myWorkBook.getNumberOfSheets();
/*// Get the first sheet from workbook
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
*//** We now need something to iterate through the cells.**//*
Iterator<Row> rowIter = mySheet.rowIterator();
while(rowIter.hasNext()){
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator<Cell> cellIter = myRow.cellIterator();
while(cellIter.hasNext()){
HSSFCell myCell = (HSSFCell) cellIter.next();
Log.w("FileUtils", "Cell Value: " + myCell.toString());
Toast.makeText(context, "cell Value: " + myCell.toString(), Toast.LENGTH_SHORT).show();
}
}*/
myFileSystem.close();
} catch (Exception e) {
e.printStackTrace();
try {
if (myFileSystem != null)
myFileSystem.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return sheetCount;
}
Demo code: https://github.com/anta40/StockChecker
My app always crashes when loading XLSX files, seems like because of "org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found"
This is the content of build.gradle:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.anta40.app.stockchecker"
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.SUPERCILEX.poi-android:poi:3.17'
implementation 'com.github.angads25:filepicker:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
When I try to run
XSSFWorkbook workbook = new XSSFWorkbook();
I get the error
java.lang.ClassNotFoundException: Didn't find class "android.support.customtabs.CustomTabsServiceConnection"
I tried to set custom page margins to document using
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar
But there is and issue that this is unresolved reference. I searching in web this issue and detected that this is missing dependency in your project
implementation "org.apache.poi:ooxml-schemas:1.3"
I added this in my forked repo and all references is OK, but i cathing runtime issue every time:
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/poi/javax/xml/stream/XMLEventFactory; at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41) at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161) at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141) at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:72) at org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:394) at org.apache.poi.xwpf.usermodel.XWPFDocument.newPackage(XWPFDocument.java:132) at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:123) at ru.hryasch.coachnotes.repository.tools.JournalDocument.generateDocument(DocExporter.kt:82) at ru.hryasch.coachnotes.repository.tools.JournalDocument$Companion.generate-Alf2mtc(DocExporter.kt:61) at ru.hryasch.coachnotes.repository.tools.DocExporter.export-Alf2mtc(DocExporter.kt:40) at ru.hryasch.coachnotes.domain.journal.interactors.impl.JournalInteractorImpl.exportJournal-djkruGA(JournalInteractorImpl.kt:61) at ru.hryasch.coachnotes.journal.presenters.impl.JournalPresenterImpl$onExportButtonClicked$1.invokeSuspend(JournalPresenterImpl.kt:112) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655) Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.poi.javax.xml.stream.XMLEventFactory" on path: DexPathList[[zip file "/data/app/ru.hryasch.coachnotes-QqhV5YU1zgEki6gvl2p2YA==/base.apk"],nativeLibraryDirectories=[/data/app/ru.hryasch.coachnotes-QqhV5YU1zgEki6gvl2p2YA==/lib/x86, /data/app/ru.hryasch.coachnotes-QqhV5YU1zgEki6gvl2p2YA==/base.apk!/lib/x86, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)ย at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161)ย at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)ย at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:72)ย at org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:394)ย at org.apache.poi.xwpf.usermodel.XWPFDocument.newPackage(XWPFDocument.java:132)ย at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:123)ย
Can you fix it?
p.s i added this but this not helps
System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl") System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl") System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl")
The Gradle dependency is working till 3.17 but when I upgrade it to 4.0.0 then the Gradle gets fail.
Will u update it to 4.0.0. I need it as I have to use XWPFChart which has been included in OOXML-4.0.0.
org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
at org.apache.poi.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at org.apache.poi.javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)
at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:97)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:116)
at com.sunwayworld.document.MainActivity.wordToHtml(MainActivity.java:182)
at com.sunwayworld.document.MainActivity.openDoc(MainActivity.java:126)
at com.sunwayworld.document.MainActivity.access$000(MainActivity.java:41)
at com.sunwayworld.document.MainActivity$2.run(MainActivity.java:110)
at java.lang.Thread.run(Thread.java:764)
Hi,
i'm trying to read word document.
i've set this in my activity
static { System.setProperty( "org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl" ); System.setProperty( "org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl" ); System.setProperty( "org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl" ); }
In my build.gradle
implementation ("com.github.SUPERCILEX.poi-android:poi:3.17") { exclude group: "org.codehaus.woodstox", module: "stax2-api" } implementation "com.github.SUPERCILEX.poi-android:proguard:3.17"
But when i do this :
FileInputStream fps = new FileInputStream(sFileName); XWPFDocument docu = null; docu = new XWPFDocument(fps);
receieve the following error :
Cannot resolve type for handle _XY_Q=space|R=space@http://www.w3.org/XML/1998/namespace (schemaorg_apache_xmlbeans.system.sF1327CCA741569E70F9CA8C9AF9B44B2.cttext7f5btype) - code 13
I'm missing some configuration in my android project?
Thank you in advance
org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
at org.apache.poi.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at org.apache.poi.javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)
at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:72)
at org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:394)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.newPackage(XSSFWorkbook.java:480)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:247)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:239)
gradle:
compileOnly ("org.apache.poi:poi-ooxml:3.17"){
exclude group: "org.apache.xmlbeans", module: "xmlbeans"
}
compileOnly ("org.apache.poi:poi:3.17"){
exclude group: "org.apache.xmlbeans", module: "xmlbeans"
}
implementation "com.github.SUPERCILEX.poi-android:poi:3.17"
Hi.
I can't run demo app with below gradle error.
Failed to find byte code for org/w3c/dom/events/EventListener
Why is this happening?
this app just working with java version below 10
Applying color is not working. java.awt.Color class missing also I tried importing the java.awt.Color from other poi sample and used it did not work. I am new to android development. Can you please help me. I attached the color reference.
Color.java.zip
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.