/**
* html 转 word doc格式
*
* @param path 路径
* @param name word 名称
* @param content 内容
*/
public static void htmlToWord2(String path, String name, String content) {
OutputStream out = null;
try {
out = new FileOutputStream(path);
Document document = new Document(PageSize.A4);
RtfWriter2.getInstance(document, out);
document.open();
Paragraph context = new Paragraph();
StyleSheet ss = new StyleSheet();
ss.loadTagStyle("table", "border", "1000");
List htmlList = com.lowagie.text.html.simpleparser.HTMLWorker.parseToList(new StringReader(content), ss);
for (int i = 0; i < htmlList.size(); i++) {
com.lowagie.text.Element e = (com.lowagie.text.Element) htmlList.get(i);
context.add(e);
}
Font font = new Font(Font.NORMAL, 16, Font.NORMAL, new Color(0, 0, 0));
context.setFont(font);
document.add(context);
document.close();
} catch (IOException | DocumentException e) {
e.printStackTrace();
} finally {
try {
if (out != null)
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
html转doc文档
最新推荐文章于 2024-04-16 14:19:12 发布