如何在Android上创build.docx文件和.xlsx文件

我有一个非常简单的问题:如何在Android上创build.docx.xlsx文件。 在有人将其标记为重复之前,让我告诉你,我已经广泛地尝试使用Apache POI创build它们,并在以下问题中描述了我的尝试:

java.lang.NoClassDefFoundError,同时使用Apache POI创build.xlsx文件

使用poi-ooxml jar文件创build一个.docx文件

但是,正如在这些链接中所述,我得到了java.lang.verify错误 。 这些是我最终导入到我的参考库的jar文件:

  • 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-模式-3.10-FINAL-20140208.jar

  • 公地编解码器1.5.jar

  • 共享logging-1.1.jar

  • 基于JUnit 4.11.jar

  • log4j的-1.2.13.jar

但现在它根本不编译,并在控制台上这样说

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 

请告诉我要做什么。

编辑:

我的最终目的是:我希望创build .docx和.xlsx文件并向它们添加一些内容 。 一旦文件被创build,我应该能够成功地在我连接手机的PC系统查看它们。

编辑2:find一个解决方法,通过删除所有这些依赖关系,并使用jspreadsheet-1.0 jar文件生成.xlsx文件。 但我仍然不知道如何处理.docx文件。

更新的问题:

看来我的问题在于使用Android不支持的POI jar文件。 有人可以提供给我的链接,我可以专门Android获得POI吗?

或者,有人可以告诉我如何创build.docx文件,我可以添加内容,以便他们可以查看?

尝试使用http://jexcelapi.sourceforge.net/

该jar文件有一个非常简单的apis,来操纵/创buildExcel工作表。

您可以使用docx4j来创build.docx文件。

docx4j是一个用于创build,编辑和保存OpenXML“包”(包括docx,pptx和xslx)的开源(Apache v2)库。

所以你需要为Word docx使用基于JAXB的Java库 。

这是一个有用的教程: http : //www.javacodegeeks.com/2012/07/java-word-docx-documents-with-docx4j.html

那么你的下一个问题是“与android兼容吗?”看看这个: JAXB可以在Android上运行

我认为这会帮助你。

只使用Apache POI库是因为它是最好的。

Google也将其用于Android的Quick Office Application。

对于docx和xlsx等。*** x文件,Dalvik允许的函数可能有一些限制。

通常你只需要这样做:

 FileOutputStream archivoSalida; HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sht = wb.createSheet("Conciliacion"); ... ... archivoSalida = new FileOutputStream(fileDestination); wb.write(archivoSalida); archivoSalida.close(); 

但似乎你的问题不在代码中。 是在图书馆和汇编。 我错了?