poi word 添加内容 poi读取word书签内容 - 电脑 - 【龙岩电脑网】_龙岩电脑维修_龙岩笔记本电脑维修_监控安装_市区上门维修
公司动态

poi word 添加内容 poi读取word书签内容

摘要:怎么使用JAVA,POI读写word文档 如何使用JAVA、POI读写word文档??能不能将一个word的内容完全读过来,放到一个新生成的word文件中去,要求能将word中的表格、图片等保留,格式...

发布日期:2020-09-15

poi word 添加内容

怎么使用JAVA,POI读写word文档

如何使用JAVA、POI读写word文档??能不能将一个word的内容完全读过来,放到一个新生成的word文件中去,要求能将word中的表格、图片等保留,格式不变。

最好能给个例子?网上多是很早以前的那个解决方法如下:,只能读文本内容,且新生成的word文件打开时总是要提示选择编码,不太好用,希望能有新的解决方案??!!poi操作word1.1 添加poi支持:包下载地址1.2 POI对Excel文件的读取操作比较方便,POI还提供对Word的DOC格式文件的读取。

但在它的发行版本中没有发布对Word支持的模块,需要另外下载一个POI的扩展的Jar包。

下载地址为;下载extractors-0.4_zip这个文件2、提取Doc文件内容 public static String readDoc(String doc) throws Exception {// 创建输入流读取DOC文件 FileInputStream in = new FileInputStream(new File(doc)); WordExtractor extractor = null; String text = null;// 创建WordExtractor extractor = new WordExtractor();// 对DOC文件进行提取 text = extractor.extractText(in); return text; } public static void main(String[] args) { try{ String text = WordReader.readDoc("c:/test.doc"); System.out.println(text); }catch(Exception e){ e.printStackTrace(); } }3、写入Doc文档 import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class WordWriter { public static boolean writeDoc(String path, String content) { boolean w = false; try { // byte b[] = content.getBytes("ISO-8859-1"); byte b[] = content.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(b); POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry directory = fs.getRoot(); DocumentEntry de = directory.createDocument("WordDocument", bais); FileOutputStream ostream = new FileOutputStream(path); fs.writeFilesystem(ostream); bais.close(); ostream.close(); } catch (IOException e) { e.printStackTrace(); } return w; } public static void main(String[] args) throws Exception{ String wr=WordReader.readDoc("D:\\test.doc"); boolean b = writeDoc("D:\\result.doc",wr);

如何使用POI操作Word文本框中的内容

ueditor实现word文档的导入和下载功能的方法:1、UEditor没有提供word的导入功能,只能说是粘贴复制。

2、方案:用poi来提供word导入,思路是将word转换为html输出,再用UEditor提供的setContent()方法将html的内容添加到编辑器中。

方案缺点,一是poi对word文本的格式获取必须按setContent()可接受的方式进行;二是我暂时没发现poi可以提供获取段落格式(对齐方式、缩进量)的方法。

代码如下:package demo;

poi的word转html,如何显示修订内容的最终状态

实现代码如下:public class Word2Html { public static void main(String argv[]) { try { //word 路径 html输出路径 convert2Html("D:/doctohtml/1.doc","D:/doctohtml/1.html"); } catch (Exception e) { e.printStackTrace(); } } public static void writeFile(String content, String path) { FileOutputStream fos = null; BufferedWriter bw = null; try { File file = new File(path); fos = new FileOutputStream(file); bw = new BufferedWriter(new OutputStreamWriter(fos,"utf-8")); bw.write(content); } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (bw != null) bw.close(); if (fos != null) fos.close(); } catch (IOException ie) { } } } public static void convert2Html(String fileName, String outPutFile) throws TransformerException, IOException, ParserConfigurationException { HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(fileName));//WordToHtmlUtils.loadDoc(new FileInputStream(inputFile)); WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter( DocumentBuilderFactory.newInstance().newDocumentBuilder() .newDocument()); wordToHtmlConverter.setPicturesManager( new PicturesManager() { public String savePicture( byte[] content, PictureType pictureType, String suggestedName, float widthInches, float heightInches ) { //html 中 图片标签中 显示的图片路路径 return "d:/doctohtml/"+suggestedName; } } ); wordToHtmlConverter.processDocument(wordDocument); //save pictures List pics=wordDocument.getPicturesTable().getAllPictures(); if(pics!=null){ for(int i=0;i Picture pic = (Picture)pics.get(i); System.out.println(); try { //word中图片的存储路径 pic.writeImageContent(new FileOutputStream("D:/doctohtml/" + pic.suggestFullFileName())); } catch (FileNotFoundException e) { e.printStackTrace(); } } } Document htmlDocument = wordToHtmlConverter.getDocument(); ByteArrayOutputStream out = new ByteArrayOutputStream(); DOMSource domSource = new DOMSource(htmlDocument); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.transform(domSource, streamResult); out.close(); writeFile(new String(out.toByteArray()), outPutFile); } }

python输出word内容

text = ",本地文件,文本内容到PDF的转换,其最终还是调用wkhtmltopdf命令.add_table(rows=1,cols=1,以及使用freemarker这样的模板引擎这样的方式。

php中也有一些相应的方法,但在python中将web/html内容生成world文档的方法是很少的、Apache POI、Java2Word、iText等各种方式。

使用方法:1.获取网页中的数据, level=1)document,支持URL;, 0)p = document.add_paragraph(")from docx import Documentfrom docx!w = float(row) /first item in ordered list";ListNumber")document.add_picture("程序导出word文档的方法将web/html内容导出为world文档,style = "Table Grid".add_heading("Document Title" and some ")p。

是目前接触到的python生成pdf效果较好的, style=", width=Inches(1.25))table = document,包括Chrome和Safari在内的浏览器都使用了这个内核;ListBullet")document.add_paragraph(",是无法将这些图片转换到word文档中;3.生成的word文档内容格式不容易控制。

优点:1.wkhtmltopdf:利用webkit内核将HTML转为PDFwebkit是一个高效、开源的浏览器内核; 2.0t,比如使用Jacob。

转换效果也不错.odtunoconv -f html *.odt缺点:1.只能对静态html进行转换,对于页面中有使用ajax异步获取数据的地方也不能转换(主要是要保证从web页面保存下来的html文件中有数据)。

2.只能对html进行转换,如果页面中有使用echarts,highcharts等js代码生成的图片.pdfkit功能:1.wkhtmltopdf主要用于HTML生成PDF.id)row_cells[2];test.html".text = item;, "out.pdf")pdfkit.from_file("Desc"for item in recordset:row_cells = table.add_row().cellsrow_cells[0].text = str(item.qty)row_cells[1]。

其中最不好解决的就是如何将使用js代码异步获取填充的数据,图片导出到word文档中;IntenseQuote")document.add_paragraph("Id"hdr_cells[2];first item in unordered list"。

1.docx")缺点:1.功能非常弱。

有很多限制比如不支持模板等,只能生成简单格式的word文档。

程序导出PDF文档方法1,使用python手动排版添加到word文档中。

from docx import Documentfrom docx.columns[0].width = Inches(w)document.save("table-step.text = str(item;monty-truth;)t.autofit = False #很重要.save(".png", level 1".descdocument.add_page_break()document. unoconv功能:1.支持将本地html文档转换为docx格式的文档,所以需要先将网页中的html文件保存到本地,再调用unoconv进行转换;# 安装pip install pdfkit\# 使用import pdfkitpdfkit.from_url(""demo.docx",使用方法非常简单。

\.add_run("bold"A plain paragraph having some ")p.bold = Truep.add_run("),且使用非常简单。

使用方法:\, style=", style="# 安装sudo apt-get install unoconv\# 使用unoconv -f pdf *.").italic = Truedocument.add_heading(", "out.pdf")pdfkit.from_string("Hello!", "out.pdf")缺点:1.对使用echarts,highcharts这样的js代码生成的图标无法转换为pdf(因为它的功能主要是将html转换为pdf,而不是将js转换为pdf)。

对于纯静态页面的转换效果还是不错的。

2.其他其他生成pdf的插件还有:weasyprint,reportlab,PyPDF2等,经简单试验都不如pdfkit效果好,且有些用法复杂。

.odtunoconv -f doc *;Heading.text = ".shared import Inchesdocument = Document()for row in range(9):t = document.pdfkit是基于wkhtmltopdf的python封装。

2. python-docx功能:1.python-docx是一个可以读写word文档的python库,其中有一个选项就是直接“保存为 PDF”。

2.wkhtmltopdf使用webkit内核的PDF渲染引擎来将HTML页面转换为PDF。

高保真,转换质量很好。

2.shared import Inchesdocument = Document()document.add_run("italic。

Chrome打印当前网页的功能.add_paragraph("Intense quote".add_table(rows=1, cols=3)hdr_cells = table.rows[0].cellshdr_cells[0].text = "Qty"hdr_cells[1],再java中有很多解决方案

word是什么意思

程序导出word文档的方法 将web/html内容导出为world文档,再java中有很多解决方案,比如使用Jacob、Apache POI、Java2Word、iText等各种方式,以及使用freemarker这样的模板引擎这样的方式。

php中也有一些相应的方法,但在python中将web/html内容生成world文档的方法是很少的。

其中最不好解决的就是如何将使用js代码异步获取填充的数据,图片导出到word文档中。

1. unoconv 功能:1.支持将本地html文档转换为docx格式的文档,所以需要先将网页中的html文件保存到本地,再调用unoconv进行转换。

转换效果也不错,使用方法非常简单。

\# 安装 sudo apt-get install unoconv \# 使用 unoconv -f pdf *.odt unoconv -f doc *.odt unoconv -f html *.odt 缺点:1.只能对静态html进行转换,对于页面中有使用ajax异步获取数据的地方也不能转换(主要是要保证从web页面保存下来的html文件中有数据)。

2.只能对html进行转换,如果页面中有使用echarts,highcharts等js代码生成的图片,是无法将这些图片转换到word文档中;3.生成的word文档内容格式不容易控制。

2. python-docx 功能:1.python-docx是一个可以读写word文档的python库。

使用方法:1.获取网页中的数据,使用python手动排版添加到word文档中。

from docx import Document from docx.shared import Inches document = Document() document.add_heading("Document Title", 0) p = document.add_paragraph("A plain paragraph having some ") p.add_run("bold").bold = True p.add_run(" and some ") p.add_run("italic.").italic = True document.add_heading("Heading, level 1", level=1) document.add_paragraph("Intense quote", style="IntenseQuote") document.add_paragraph("first item in unordered list", style="ListBullet") document.add_paragraph("first item in ordered list", style="ListNumber") document.add_picture("monty-truth.png", width=Inches(1.25)) table = document.add_table(rows=1, cols=3) hdr_cells = table.rows[0].cells hdr_cells[0].text = "Qty" hdr_cells[1].text = "Id" hdr_cells[2].text = "Desc" for item in recordset:row_cells = table.add_row().cells row_cells[0].text = str(item.qty) row_cells[1].text = str(item.id) row_cells[2].text = item.desc document.add_page_break() document.save("demo.docx") from docx import Document from docx.shared import Inches document = Document() for row in range(9):t = document.add_table(rows=1,cols=1,style = "Table Grid") t.autofit = False #很重要!w = float(row) / 2.0 t.columns[0].width = Inches(w) document.save("table-step.docx") 缺点:1.功能非常弱。

有很多限制比如不支持模板等,只能生成简单格式的word文档。

程序导出PDF文档方法1.pdfkit 功能:1.wkhtmltopdf主要用于HTML生成PDF。

2.pdfkit是基于wkhtmltopdf的python封装,支持URL,本地文件,文本内容到PDF的转换,其最终还是调用wkhtmltopdf命令。

是目前接触到的python生成pdf效果较好的。

优点:1.wkhtmltopdf:利用webkit内核将HTML转为PDF webkit是一个高效、开源的浏览器内核,包括Chrome和Safari在内的浏览器都使用了这个内核。

Chrome打印当前网页的功能,其中有一个选项就是直接“保存为 PDF”。

2.wkhtmltopdf使用webkit内核的PDF渲染引擎来将HTML页面转换为PDF。

高保真,转换质量很好,且使用非常简单。

使用方法:\# 安装 pip install pdfkit \# 使用 import pdfkit pdfkit.from_url("", "out.pdf") pdfkit.from_file("test.html", "out.pdf") pdfkit.from_string("Hello!", "out.pdf") 缺点:1.对使用echarts,highcharts这样的js代码生成的图标无法转换为pdf(因为它的功能主要是将html转换为pdf,而不是将js转换为pdf)。

对于纯静态页面的转换效果还是不错的。

2.其他 其他生成pdf的插件还有:weasyprint,reportlab,PyPDF2等,经简单试验都不如pdfkit效果好,且有些用法复杂。

怎用用java导入、导入word形式的考试题目?

使用java中的io进行读取BufferedReader bufferedReader = null;File file = new File("文档地址+文档名.docx");if(!file.exists()){System.out.println("文件不存在");} else {bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "读取的字符格式(UTF-8或GBK)"));String lineText = null;while((lineText = bufferedReader.readLine()) != null){if (linText != null && !lineText.eq("")){System.out.println("一次读取一行,一行内容为:" + lineText);

我电脑的word怎么打不开??

[编辑本段]Microsoft Word-基本信息 第一个Windows版本的Word发售于1989年,价格是500美元。

在 Windows 3.0 发行之后的一年, 销售开始好转, (WordMicrosoft Word1.0 与 Windows 3.0 的协作比先前版本更好)。

制作一个Windows版WordPerfect的失败已证实为致命的错误。

它是Word 2.0版本,但是却作为市场主流坚实地发展起来。

Word在苹果机市场上没有强大的竞争对手,尽管有程序像Nisus Writer提供“不连续的选择”等的特色功能,这些功能直到Office XP中的Word 2002才添加。

另外,一些用户抱怨Word没有在1987年的3.01版与1991年的5.0版之间实行大的检查。

相对于它的易用性和特色功能来说,由于典雅,苹果机的Word 5.1是一个主流的文字处理器。

但是1994年发布的苹果机的6.0版却受到了广泛的嘲笑。

这是Word第一个基于Windows和Macs之间通用代码的版本;许多人抱怨它慢、简陋及占过多内存。

Windows版本也计入6.0在内以协调跨越不同平台的产品命名(尽管事实上最早的Windows版本为Word 2.0)。

Word的较晚版本拥有比文字处理更多的功能。

绘图工具可进行简单的桌面出版运作,如在文件中加设图像。

近年来已增设Collaboration、文件校对、多语言支援与及其他功能。

[编辑本段]Microsoft Word-作用 使用Microsoft Office Word创建和编辑信件,报告,网页或电子邮件中的文本和图形。

Microsoft Word使用示范MS-DOS计算机开发的Word的第一代于1983年底发行,但是反响并不好,销售落后于WordPerfect等对手产品。

尽管如此,在Macintosh系统中,Word在1985年发布以后赢得了广泛的接受,尤其是对于在两年以后第二次大型发布的Word 3.01 for Macintosh (Word 3.00 由于有严重bug很快下线)。

和其他Mac软件一样,Word for Mac是一个真正的(所见即所得) 编辑器。

由于MS-DOS是一个字符界面系统,Word for DOS是为IBM PC 研发的第一个文本编辑器,在编辑的时候屏幕上直接显示的是“黑体”“斜体”等字体 标识符,而不是“所见即所得”。

其他的DOS 文本编辑器,如WordStar和WordPerfect等,在屏幕显示时使用的是简单文本显示加上标识代码,或者加以颜色区别。

尽管如此,和大多数DOS软件一样,程序为了执行特定的功能,都有自己特殊的,而且往往是复杂的命令组需要使用者去记忆。

(比如在Word for DOS中,保存文件需要依次执行Escape-T-S),而大部分秘书们已经知道如何使用WordPerfect,公司就不大愿意更换成对手产品,何况提供的新优点有限。

[编辑本段]Microsoft Word-专业测评 Microsoft Office Word 2007 通过将一组功能完备的撰写工具与易于使用的 Microsoft Office Fluent 用户界面相结合,来帮助Microsoft Word效果图用户创建和共享具有专业外观的内容。

下面是 Office Word 2007 可以帮助您更快地创建具有专业外观的内容的 10 大理由。

1. 减少设置格式的时间,将主要精力集中于撰写文档。

Office Fluent 用户界面可在需要时提供相应的工具,使您可轻松快速地设置文档的格式。

现在,您可以在 Office Word 2007 中找到适当的功能来更有效地传达文档中的信息。

使用“快速样式”和“文档主题”,您可以快速更改整个文档中文本、表格和图形的外观,使之符合您喜欢的样式或配色方案。

2. 借助 SmartArt 图示和新的制图工具更有效地传达信息。

新的 SmartArt 图示和新的制图引擎可以帮助您使用三维形状、透明度、投影以及其他效果创建外观精美的内容 3. 使用构建基块快速构建文档。

Office Word 2007 中的构建基块可用于通过常用的或预定义的内容(如免责声明文本、重要引述、提要栏、封面以及其他类型的内容)构建文档。

这样就可以避免花费不必要的时间在各文档间重新创建或复制粘贴这些内容;还有助于确保在组织内创建的所有文档的一致性。

4. 直接从 Office Word 2007 另存为 PDF 或 XPS。

Office Word 2007 提供了与他人共享文档的功能。

您无需增加第三方工具,就可以将 Word 文档转换为可移植文档格式 (PDF) 或 XML 文件规范 (XPS) 格式,从而有助于确保与使用任何平台的用户进行广泛交流。

1 5. 直接从 Office Word 2007 中发布和维护博客。

现在,您可以直接从 Office Word 2007 发布博客。

您可以将 Office Word 2007 配置为直接链接到您的博客网站,使用丰富的 Word 体验来创建包含图像、表格和高级文本格式设置功能的博客。

6. 使用 Office Word 2007 和 Microsoft Office SharePoint Server 2007 控制文档审阅过程。

通过 Office SharePoint Server 2007 中内置的工作流服务,您可以在 Office Word 2007 中启动和跟踪文档的审阅和批准过程,帮助加速整个组织的审阅周期,而无需强制用户学习新工具。

7. 将文档与业务信息连接。

使用新的文档控件和数据绑定创建动态智能文档,这种文档可以通过连接到后端系统进行自我更新。

组织可以利用新的 XML 集成功能来部署智能模板,以协助用户创建高度结构化的文档。

8. 删除文档中的修订、批注和隐藏文本。

使用文档检查器检测并删除不需要的批注、隐藏文本或个人身份信息,以帮助确保在发布文档时不会泄露敏感信息。

...