poi笔记

poi笔记

2020.06.05

word转html

 //导入依赖
 <dependency>
            <groupId> e-iceblue </groupId>
            <artifactId>spire.doc</artifactId>
            <version>3.5.5</version>
        </dependency>
		//创建document对象
		Document doc = new Document();
        //加载Word文档
        doc.loadFromFile("E:\\documentPath\\upload\\那些年spark踩过的坑.docx");
        //将Word保存为HTML格式
        doc.saveToFile("E:\\documentPath\\upload\\那些年spark踩过的坑.html", FileFormat.Html);

2020.06.08

pdf转html

//加载PDF
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile("Input.pdf");
pdf.saveToFile("ToHTML.html", FileFormat.HTML);

正则替换html中的内容

/**
     * 文件转化为html
     * @param fileName
     * @return
     */
    public String getHtmlByHight(String fileName,String key) throws Exception {


        // filePath 要读取的文件 savePath 要写入的文件
        BufferedReader br = null;
        BufferedWriter bw = null;

        try {
            // 以下读取和写入都转成UTF-8 防止乱码
            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("id=\"\\S+\"", ""));
                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;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值