import java.io.*;
import org.apache.poi.hpsf.CustomProperties;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class CreateWordDoc {
public static void main (String[] args) throws Exception {
// POI apparently can't create a document from scratch,
// so we need an existing empty dummy document
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("empty.doc"));
HWPFDocument doc = new HWPFDocument(fs);
// centered paragraph with large font size
Range range = doc.getRange();
Paragraph par1 = range.insertAfter(new ParagraphProperties(), 0);
par1.setSpacingAfter(200);
par1.setJustification((byte) 1);
// justification: 0=left, 1=center, 2=right, 3=left and right
CharacterRun run1 = par1.insertAfter("one");
run1.setFontSize(2 * 18);
// font size: twice the point size
// paragraph with bold typeface
Paragraph par2 = run1.insertAfter(new ParagraphProperties(), 0);
par2.setSpacingAfter(200);
CharacterRun run2 = par2.insertAfter("two two two two two two two two two two two two two");
run2.setBold(true);
// paragraph with italic typeface and a line indent in the first line
Paragraph par3 = run2.insertAfter(new ParagraphProperties(), 0);
par3.setFirstLineIndent(200);
par3.setSpacingAfter(200);
CharacterRun run3 = par3.insertAfter("three three three three three three three three three "
+ "three three three three three three three three three three three three three three "
+ "three three three three three three three three three three three three three three");
run3.setItalic(true);
// add a custom document property (needs POI 3.5; POI 3.2 doesn't save custom properties)
DocumentSummaryInformation dsi = doc.getDocumentSummaryInformation();
CustomProperties cp = dsi.getCustomProperties();
if (cp == null)
cp = new CustomProperties();
cp.put("myProperty", "foo bar baz");
dsi.setCustomProperties(cp);
doc.write(new FileOutputStream("new-hwpf-file.doc"));
}
}
分享到:
相关推荐
Java使用poi-tl生成word文档
Java POI 生成Word文档,支持图片插入,关键是修改XML部分,本人已测试通过。
java使用poi,根据模板,生成word文档.
java 使用POI合并两个word文档.docx
使用java Apache poi 根据word模板生成word报表 仅支持docx格式的word文件,大概是word2010及以后版本,doc格式不支持。 使用说明:https://blog.csdn.net/u012775558/article/details/79678701
Java通过POI读取Excel遍历数据,根本word模板批量生成word文档,demo可运行,可根据需求修改
一个关于word文档的小例子,主要运用到java的poi
本人文章《使用poi根据模版生成word文档并转换成PDF文件》所需要用到的文件
java 使用poi根据模版导出word文件 将文件中的标签替换成文字或者文件 文件中标签用{xxxx}生成新文件
java POI导出word文档代码,可参考具体代码,两个类,根据自己情况参考 java POI导出word文档代码,可参考具体代码,两个类,根据自己情况参考
主要介绍了java poi设置生成的word的图片为上下型环绕以及其位置的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
JAVA使用POI生成Word文档,并带下载功能。使用POI类包
将assets中.xml中的doc文件中,就会生成word文档和excel文档
java使用poi技术解析word文档,简易分析,希望对大家有帮助!
资源描述了poi对于word的操作,poi合并word文档,poi设置word页码,内含maven依赖文档和完整代码,是一个完整工程,打开即可用
最近在做一个出卷系统,需要通过试卷模板从数据库中抽取题目,然后按照模板的样式生成完整的试卷,包括试卷格式的排版和图片的写入。这是用POI模板生成word文档。里面包括完整代码和所需jar包。
poi-tl解析Word文档,包含表格类型的也可以
这是一个POI读取word 2003 和 word 2007的例子 是一个Eclipse工程 下载后直接导入工程 运行 src 目录下的 Test java 类即可 这个 rar 包中包含着 POI 读取word 2003 和 word 2007 所需要的 jar 包 也有需要读取的 ...
最近项目中需要用到数据的导出到Word,本在项目中使用POI将数据导入到Word,代码示例非常简洁,代码包含pom依赖文件,下载解压即可到本地调试运行。