安装office2007,添加com引用Microsoft Word12.0 Object Library和Microsoft Office12.0 Object Library using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.Office.Interop.Word; using System.Reflection; using System.
最近多了一个需求,需要对word模板内容进行替换,一开始用的是word03版的,替换起来比较简单,主要是range对像替换非常方便,而且可以保留替换前的字体样式. InputStream is = new FileInputStream(srcFath); OutputStream os = new FileOutputStream(tempFile); XWPFDocument doc = new XWPFDocument(is); Range range = doc.getRange();