去除Spire.Doc导出字样信息

//去除Spire.Doc导出字样信息
    try (FileInputStream in = new FileInputStream(wordPath)){
        XWPFDocument docnew = new XWPFDocument(OPCPackage.open(in));
        List paragraphs = docnew.getParagraphs();
        if (paragraphs.size() < 1){
            return true;
        }
        XWPFParagraph firstParagraph = paragraphs.get(0);
        if (firstParagraph.getText().contains("Spire.Doc")){
            docnew.removeBodyElement(docnew.getPosOfParagraph(firstParagraph));
        }
        OutputStream out = new FileOutputStream(wordPath);
        docnew.write(out);
        docnew.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}catch (Exception e){
    System.out.println("系统异常"+e.getMessage());
    e.printStackTrace();;
}

你可能感兴趣的:(java,开发语言)