如何在 Android 上创建 .docx 文件和 .xlsx 文件 [英] How to create .docx files and .xlsx files on Android

查看:106
本文介绍了如何在 Android 上创建 .docx 文件和 .xlsx 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a very simple question: How to create .docx and .xlsx files on Android. Before someone marks this as duplicate, let me tell you that I have extensively tried creating them using Apache POI and my attempts are described in these questions:

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

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

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

However, as described in those links, I am getting the java.lang.verify error. These are the jar files I have finally imported into my reference libraries:

  • dom4j-1.6.1.jar

  • dom4j-1.6.1.jar

poi-3.10-FINAL-20140208.jar

poi-3.10-FINAL-20140208.jar

poi-ooxml-3.10-FINAL-20140208.jar

poi-ooxml-3.10-FINAL-20140208.jar

stax-api-1.0.1.jar

stax-api-1.0.1.jar

xmlbeans-2.3.0.jar

xmlbeans-2.3.0.jar

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

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

commons-codec-1.5.jar

commons-codec-1.5.jar

commons-logging-1.1.jar

commons-logging-1.1.jar

junit-4.11.jar

junit-4.11.jar

log4j-1.2.13.jar

log4j-1.2.13.jar

但现在它根本无法编译,并在控制台上说这个

but now it doesn't compile at all, and says this on the console

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 系统上成功查看它们.

My end purpose is: I wish to create .docx and .xlsx files and add some content to them. Once the files are created, I should be able to successfully view them on the PC system which I have connected the phone to.

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

EDIT 2: Found a workaround to generate .xlsx files by removing all these dependencies and using jspreadsheet-1.0 jar file. But I still don't know what to do for .docx files.

更新的问题:

我的问题似乎在于使用了 Android 不支持的 POI jar 文件.有人可以给我提供一个链接,我可以在其中获得专门Android POI 吗?

It seems my problem lies with using the POI jar files which is not supported by Android. Can someone please supply me the link where I can get POI specifically for Android?

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

Or, can someone please tell me how to create .docx files to which I can add content, and such that they can be viewed?

推荐答案

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

You can use docx4j to create .docx files.

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

因此您需要使用 Word docx 的基于 JAXB 的 Java 库.

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

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

Then your next question "is that compatible with the android ? " Look at this: JAXB can be made to run on Android

我认为这会对您有所帮助.

I think this will help you.

这篇关于如何在 Android 上创建 .docx 文件和 .xlsx 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆