读取和写入DOCX文件 [英] Read and Write DOCX file
问题描述
我有2个正在使用的docx文件.一个docx文件包含产品的文本信息(起始序列号,长度,宽度和高度).另一个docx文件包含一个不干胶标签,其中包含图像和第一个文件中的所有文本信息.
I have 2 docx files that I am working with. One docx file contains text information of a product (start serial number, length, width, and height). The other docx file contains a sticker label with an image and all of the text information from the first file.
这是我目前正在做的事情: 我打开第一个docx文件并复制所有文本信息(序列,长度,宽度和高度) 然后,我将每个信息粘贴到包含格式化标签的第二个docx文件中. 如果需要制作多个标签,请复制标签并将序列号加1.
This is what I do currently: I open the first docx file and copy all of the text information (serial, length, width, and height) Then I paste each info into the second docx file that contains the formatted label. If I need to make more than one label, I copy the label and increment the serial number by 1.
为不同的产品制作多个标签需要花费大量时间.我的目标是想出一种更简便的方法来从一个docx提取数据并将其注入到另一个docx.另外,在需要时生成更多标签.
This takes a lot of time to make several labels for different products. My goal is to come up with an easier way to take data from one docx and inject it into the other. Also, generating more labels when needed.
我的第一个想法是提取docx文件以获取其xml内容.然后使用javascript,c ++或任何其他语言读取数据.然后,请用户输入要生成的标签数量,处理xml并将其重新打包为docx文件.
My first thought was to extract the docx file to get it's xml contents. Then read the data using javascript, c++, or any other language. Then Ask user to input number of labels to generate, manipulate the xml, and repack it as a docx file.
然后,我考虑过尝试使用Windows Office的邮件合并"功能,但我从未做过此事.
Then I thought about trying to use the windows office "mail merge" feature, but I have never done this before.
我想知道是否有人对从一个docx文件导入数据并生成标签到另一个docx的简单解决方案有任何建议.
I would like to know if anyone has any suggestions for an easy solution to import data from one docx file and generating labels into another.
我愿意接受任何建议.
I am open for any suggestion.
我也不是一个专业的程序员.我是计算机工程专业的本科生,在c,c ++,java,javascript,python,MIPS汇编和php方面具有一定的经验.
Also, I am not a professional programmer. I am an undergraduate computer engineering student with some experience in c, c++, java, javascript, python, MIPS assembly, and php.
推荐答案
- 我知道的唯一开源(可能更容易获得)的解决方案是:
http://poi.apache.org/document/quick-guide -xwpf.html
这是一个不错的选择,它涉及到速度,它是免费软件.
This is a good bet when it comes to speed and it is free software.
但是,如果打开文件,请对其进行更改并再次保存-结果可能会不稳定:格式可能会略有偏离.至少在我与pptx同行的测试中.
But if you open a file, alter it and save it again - the result can be flaky: The formatting can be slightly off. At least in my tests with the pptx counterpart.
我认为,当您与用户进行交互(网页?)以创建文档时,可以在该库周围构建一个小的HTTP Api.
I reckon when you have user interaction (web page?) in order to create the document, you can build a small HTTP Api around the library.
还有: http://www.docx4java.org/trac/docx4j -我还没有测试过.
There is also: http://www.docx4java.org/trac/docx4j - which I have not tested yet.