当前位置: 代码迷 >> 综合 >> java html转换为word文档
  详细解决方案

java html转换为word文档

热度:29   发布时间:2024-01-21 14:14:17.0
	public static boolean writeWordFile() {  boolean w = false;  String path = "d:/";  try {  if (!"".equals(path)) {  // 检查目录是否存在  File fileDir = new File(path);  if (fileDir.exists()) {  // 生成临时文件名称  String fileName = "a.doc";  String content = "<html><div style=\"text-align: center\"><span style=\"font-size: 28px\"><span style=\"font-family: 黑体\">" +  "制度发布通知<br /> <br /> </span></span></div></html>";  byte b[] = content.getBytes();  ByteArrayInputStream bais = new ByteArrayInputStream(b);  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();  }  return w;  }