说明,不论使用哪种方式,都不能引用CSS来渲染样式,而是使用style,或者将样式放在当前页面的中
方法一、
1、引用的jar包
org.apache.poi
poi
4.1.0
2、核心代码
String html = "
测试内容
POIFSFileSystem poifs = null;
FileOutputStream ostream = null;
ByteArrayInputStream bais = null;
String uuid = "测试.doc";
File file = null;
try {
//HTML内容必须被
包装fileParam.setcContent("
" + html + "");byte[] b = fileParam.getcContent().getBytes();
bais = new ByteArrayInputStream(b);
poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.getRoot();
//WordDocument名称不允许修改
directory.createDocument("WordDocument", bais);
ostream = new FileOutputStream(uuid);
poifs.writeFilesystem(ostream);//当前目录下就