poi笔记
2020.06.05
word转html
//导入依赖
<dependency>
<groupId> e-iceblue </groupId>
<artifactId>spire.doc</artifactId>
<version>3.5.5</version>
</dependency>
Document doc = new Document();
doc.loadFromFile("E:\\documentPath\\upload\\那些年spark踩过的坑.docx");
doc.saveToFile("E:\\documentPath\\upload\\那些年spark踩过的坑.html", FileFormat.Html);
2020.06.08
pdf转html
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile("Input.pdf");
pdf.saveToFile("ToHTML.html", FileFormat.HTML);
正则替换html中的内容
public String getHtmlByHight(String fileName,String key) throws Exception {
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(documentPath + fileName), "UTF-8"));
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(documentPath + "hight_" + fileName), "UTF-8"));
String line = null;
while ((line = br.readLine()) != null && (line != "")) {
bw.write(line.replaceAll("欢迎", "<span style=\"color:red;\">欢迎</span>")
.replaceAll("Evaluation Warning: The document was created with Spire.Doc for JAVA.",""));
}
bw.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (br != null){
br.close();
}
if (bw != null){
bw.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}