docx

java导出2007版word(docx格式)freemarker + xml 实现

ぃ、小莉子 提交于 2019-11-29 10:38:30
Freemarker+xml生成docx 原理概述:word从2003版就支持xml格式,而freemarker是java封装的模板工具,两者结合也就是在xml中需要动态生成的部分调用freemarker的指令(类似于EL表达式),来生成我们需要的数据,再用流输出文件,就达到了写word的效果。 生成word的基本流程图如下: 1. 生成docx模板和xml模板 生成docx模板 按照项目需要生成固定格式的docx格式的模板。 为方便测试做了个简单的例子,docx模板的内容如下图: 生成xml模板 从docx模板中取出word/document.xml,由于docx属于zip格式,可以用winrar打开,如图: 除word文件夹外其它文件为基本配置文件,取出word/document.xml(存放word文件的文本内容)如下图: 需要把document.xml解压出来,修改里面需要从数据库导出的数据用freemarker的指令代替,例如${test} 同时可以用遍历函数 替换完成后相当于生成了 xml 模板 生成的Xml模板: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010

java模板导出word

谁说我不能喝 提交于 2019-11-29 10:37:57
java模板导出word 功能描述 只需配置好word模板,自动替换指定的模板变量为具体数据,自动导出word 支持导出doc和docx 支持word静态图片上有文字导出,导出自动添加图片未尝试 支持中文名word文件导出 解决思路 本demo采用的解决思路为freemarker导出(freemarker的主要作用为将动态表达式替换为javabean的值)。 word的doc和docx的底层存储结构不一样,因此对这两种情况分别进行处理。 freemarker导出doc及docx注意事项 请取消拼写检查的功能以及 和 表 达 式 字 体 设 置 为 一 致 , 否 则 d o c 或 d o c x 的 表 达 式 和表达式字体设置为一致,否则doc或docx的表达式~ 和 表 达 式 字 体 设 置 为 一 致 , 否 则 d o c 或 d o c x 的 表 达 式 {numNo} ,转为xml后会变成 <w:t>${</w:t>…numNo…<w:t>}~,将导致freemark无法正确解析表达式,也可手动删除,但没那必要是不。 freemarker导出doc doc为单文件格式,我们将其转为可编辑的xml格式后,替换掉表达式值,再将其还原为doc文件即可。 手动模拟步骤: 创建doc,新建内容如“hello,${name}”,文件另存为word 2003 xml文档

How to Search and Replace in odt Open Office document?

人走茶凉 提交于 2019-11-29 07:33:11
In my Delphi application I am currently do Search&Replace programmatically for doc and docx word documents using office ole automation. Does anyone has the code to do the same (for doc, docs, odt) in OpenOffice? I also asked a related question on saving to pdf . You should take a focus on XReplaceable interface. Here is the example. Please note, that there's no error handling. I've tested it with LibreOffice writer and it works fine for me. uses ComObj; procedure OpenOfficeReplace(const AFileURL: string; ASearch: string; const AReplace: string); var StarOffice: Variant; StarDesktop: Variant;

How to load text of MS Word document in C# (.NET)?

百般思念 提交于 2019-11-29 04:33:49
How do I load MS Word document (.doc and .docx) to memory (variable) without doing this?: wordApp.Documents.Open I don't want to open MS Word, I just want that text inside. You gave me answer for DOCX, but what about DOC? I want free and high performance solution - not to open 12.000 instances of Word to process all of them. :( Aspose is commercial product, and 900$ is a way too much for what I do. You can use wordconv.exe which is part of the Office Compatibility Pack to convert from doc to docx. http://www.microsoft.com/downloads/details.aspx?familyid=941b3470-3ae9-4aee-8f43-c6bb74cd1466

Text-Replace in docx and save the changed file with python-docx

不问归期 提交于 2019-11-29 04:14:03
I'm trying to use the python-docx module to replace a word in a file and save the new file with the caveat that the new file must have exactly the same formatting as the old file, but with the word replaced. How am I supposed to do this? The docx module has a savedocx that takes 7 inputs: document coreprops appprops contenttypes websettings wordrelationships output How do I keep everything in my original file the same except for the replaced word? edi9999 As it seems to be, Docx for Python is not meant to store a full Docx with images, headers, ... , but only contains the inner content of the

how to Show or Read docx file

核能气质少年 提交于 2019-11-29 03:54:31
I am new to rendering files in android, and I want to render or display a docx file in my application. I had already extract text from docx file, but now I want to extract images from the docx file as well. I've found several ways to display images in pure Java, but are there any good examples for Android? I tried this code to fetch Images but not working... public void extractImages(Document xmlDoc) { NodeList binDataList = xmlDoc.getElementsByTagName("w:drawings"); String fileName = ""; Node currentNode; for(int i = 0; i < binDataList.getLength(); i++) { currentNode = binDataList.item(i); if

Find and replace text in .docx file - Python

拜拜、爱过 提交于 2019-11-29 03:47:31
问题 I've been doing a lot of searching for a method to find and replace text in a docx file with little luck. I've tried the docx module and could not get that to work. Eventually I worked out the method described below using the zipfile module and replacing the document.xml file in the docx archive. For this to work you need a template document (docx) with the text you want to replace as unique strings that could not possibly match any other existing or future text in the document (eg. "The

PHP Convert Word file to HTML without losing styling and images [closed]

▼魔方 西西 提交于 2019-11-29 00:53:02
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Is there an API for converting word files to HTML without losing the format? Can the google documents API be used for this? I tried saaspose but the returning result is always a server error. Solutions that did not work for me: Converting MS Word document to html in php 回答1: I've spent a bit of time loking into

How can I use predefined formats in DOCX with POI?

冷暖自知 提交于 2019-11-28 21:28:32
I'm creating a docx generator with POI and would like to use predefined formats. Word includes several formats like Title, Heading 1..10 etc. These formats are predefined in every DOCX you create with Word. I would like to use them in my docx generator. I tried the following but the format was not applied: paragraph = document.createParagraph(); lastParagraph.setStyle("Heading1"); I also tried "heading 1", "heading1" and "Heading1" as style, but none of them worked. The API documentation doesn't show any details. I analysed a docx file created with Word 2007 and found out "Heading1" would be

Batch conversion of docx to clean HTML

为君一笑 提交于 2019-11-28 19:35:13
I'm starting to wonder if this is even possible. I've searched for solutions on Google and come up with nothing that works exactly how I'd like it to. I think it'd benefit to explain what that entails. I work for database group at my university's IT department. My main job is to take specs of a report in a docx file, copy that over to dreamweaver, fix some formatting, and put it onto their website. My issue is that it's ridiculously tedious to do this over and over. I figured, hey, I haven't written anything in C# for some time now, perhaps I could write an application to grab a docx file,