html转为word文档分页,html转word文档

编程知识 行业动态 更新时间:2024-06-13 00:17:38

packagecn.szhtkj.util;importjava.io.ByteArrayInputStream;importjava.io.File;importjava.io.FileOutputStream;importjava.io.IOException;importorg.apache.poi.poifs.filesystem.DirectoryEntry;importorg.apache.poi.poifs.filesystem.DocumentEntry;importorg.apache.poi.poifs.filesystem.POIFSFileSystem;public classtestMain {public static booleanwriteWordFile() {boolean w = false;

String path= "d:/";try{if (!"".equals(path)) {//检查目录是否存在

File fileDir = newFile(path);if(fileDir.exists()) {//生成临时文件名称

String fileName = "a11.doc";//使用传html 转word

String contentConcat = "" + "" + "

信息" + ""

+ "

姓名

+ "

性别" + "" + ""

+ "" + "";byte b[] = contentConcat.getBytes("UTF-8");

ByteArrayInputStream bais= newByteArrayInputStream(b);

POIFSFileSystem poifs= newPOIFSFileSystem();

DirectoryEntry directory=poifs.getRoot();

DocumentEntry documentEntry= directory.createDocument("WordDocument", bais);

FileOutputStream ostream= new FileOutputStream(path +fileName);

poifs.writeFilesystem(ostream);

ostream.close();

poifs.close();

bais.close();/** 访问桌面上的html转word ByteArrayOutputStream bos = new ByteArrayOutputStream();

* FileInputStream fis = new

* FileInputStream("C:\\Users\\ghost\\Desktop\\1.html"); int b = -1; while ((b =

* fis.read()) != -1) { bos.write(b); } fis.close(); bos.close();

* ByteArrayInputStream bais = new ByteArrayInputStream(bos.toByteArray());

* POIFSFileSystem poifs = new POIFSFileSystem(); DirectoryEntry directory =

* poifs.getRoot(); DocumentEntry documentEntry =

* directory.createDocument("WordDocument", bais); FileOutputStream ostream =

* new FileOutputStream(path + fileName); poifs.writeFilesystem(ostream);

* bais.close(); ostream.close();*/}

}

}catch(IOException e) {

e.printStackTrace();

}returnw;

}public static voidmain(String[] args) {

writeWordFile();

}

}

更多推荐

html转为word文档分页,html转word文档

本文发布于:2023-03-25 13:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/16c1273098cb285527c5d47b03ecc8e3.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文档   分页   html   word

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!