本文整理汇总了Java中org.apache.poi.hwpf.HWPFDocument.write方法的典型用法代码示例。如果您正苦于以下问题:Java HWPFDocument.write方法的具体用法?Java HWPFDocument.write怎么用?Java HWPFDocument.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hwpf.HWPFDocument
的用法示例。
在下文中一共展示了HWPFDocument.write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceWordDoc
import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
public static void replaceWordDoc(String inPath, String outPath, Map<String, String> context) {
Validate.notBlank(inPath);
Validate.notBlank(outPath);
Validate.notNull(context);
try (FileInputStream in = new FileInputStream(new File(inPath));
FileOutputStream out = new FileOutputStream(outPath, false)) {
HWPFDocument hdt = new HWPFDocument(in);
Range range = hdt.getRange();
for (Map.Entry<String, String> entry : context.entrySet()) {
range.replaceText(entry.getKey(), entry.getValue());
}
hdt.write(out);
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: saveDoc
import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
/**
* Method to save the file by parameters in doc format
*
* @param toSave The file where the information will be saved
*/
private void saveDoc(File toSave) {
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("down/empty.doc"));
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
Paragraph parContainer = range.insertAfter(new ParagraphProperties(), 0);
for (String para : paragraphs) {
parContainer.setSpacingAfter(200);
parContainer.insertAfter(para);
parContainer = range.insertAfter(new ParagraphProperties(), 0);
}
FileOutputStream fos = new FileOutputStream(toSave);
doc.write(fos);
fos.close();
} catch (Exception e) {
Logger.getGlobal().log(Level.SEVERE, e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
}
}
示例3: testReadByDoc
import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
@Test
public void testReadByDoc() throws Exception {
InputStream is = new FileInputStream("E://video/doc/xiuParty/90Xiu-NEW/oss/90秀--oss与服务器端接口文档.doc");
POIFSFileSystem pfilesystem = new POIFSFileSystem(is);
HWPFDocument doc = new HWPFDocument(pfilesystem);
// // 输出书签信息
// this.printInfo(doc.getBookmarks());
// // 输出文本
// System.out.println(doc.getDocumentText());
Range range = doc.getRange();
// this.insertInfo(range);
this.printInfo(range);
// 读表格
this.readTable(range);
// 读列表
this.readList(range);
// 删除range
Range r = new Range(2, 5, doc);
r.delete();// 在内存中进行删除,如果需要保存到文件中需要再把它写回文件
// 把当前HWPFDocument写到输出流中
doc.write(new FileOutputStream("D:\\test.doc"));
IOUtils.closeQuietly(is);
}
示例4: CreateDocFromTemplate
import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
/**
* 创建Doc并保存
*
* @param templatePath 模板doc路径
* @param parameters 参数和值
* //* @param imageParameters 书签和图片
* @param savePath 保存doc的路径
* @return
*/
public static void CreateDocFromTemplate(String templatePath,
HashMap<String, String> parameters,
//HashMap<String, String> imageParameters,
String savePath)
throws Exception {
@Cleanup InputStream is = DocProducer.class.getResourceAsStream(templatePath);
HWPFDocument doc = new HWPFDocument(is);
Range range = doc.getRange();
//把range范围内的${}替换
for (Map.Entry<String, String> next : parameters.entrySet()) {
range.replaceText("${" + next.getKey() + "}",
next.getValue()
);
}
@Cleanup OutputStream os = new FileOutputStream(savePath);
//把doc输出到输出流中
doc.write(os);
}
示例5: main
import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
HWPFDocument doc = new HWPFDocument(new FileInputStream(
"data/document.doc"));
// write the file
FileOutputStream out = new FileOutputStream("data/Apache_SaveDoc.doc");
doc.write(out);
out.close();
System.out.println("Process Completed Successfully");
}
示例6: main
import org.apache.poi.hwpf.HWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithdocuments/openexistingdocument/data/";
HWPFDocument doc = new HWPFDocument(new FileInputStream(
dataPath + "document.doc"));
// write the file
FileOutputStream out = new FileOutputStream(dataPath + "Apache_ExistingDoc_Out.doc");
doc.write(out);
out.close();
System.out.println("Process Completed Successfully");
}