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

2022-09-04 04:17:01

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

java.lang.NoClassDefFoundError 在使用 Apache POI 创建.xlsx文件时

使用 poi-ooxml jar 文件创建.docx文件

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

  • dom4j-1.6.1.jar

  • poi-3.10-最终-20140208.jar

  • poi-ooxml-3.10-FINAL-20140208.jar

  • stax-api-1.0.1.jar

  • xmlbeans-2.3.0.jar

  • poi-ooxml-schemas-3.10-FINAL-20140208.jar

  • commons-codec-1.5.jar

  • 共享资源-日志记录-1.1.jar

  • 朱尼特-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

请告知我该怎么做。

编辑:

我的最终目的是:我希望创建.docx和.xlsx文件,并向其中添加一些内容。创建文件后,我应该能够在我已将手机连接到的PC系统上成功查看它们。

编辑2:找到了通过删除所有这些依赖项并使用jspreadsheet-1.0 jar文件来生成.xlsx文件的解决方法。但我仍然不知道该如何处理.docx文件。

更新的问题:

似乎我的问题在于使用Android不支持的POI jar文件。有人可以向我提供链接,以便我可以获得专门针对Android的POI

或者,有人可以告诉我如何创建.docx文件,我可以向其中添加内容,以便可以查看它们吗?


答案 1

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

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

所以你需要使用基于JAXB的Java库来表示Word docx

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

然后你的下一个问题“这与机器人兼容吗?看看这个:JAXB可以让它在Android上运行

我认为这会对你有所帮助。


答案 2

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

谷歌也在其Quick Office Application for Android中使用它。

对于像 docx 和 xlsx 这样的 .***x 文件,它可能对 Dalvik 中允许的函数有一些限制。


推荐