コード例 #1
0
  private void generateWordDoc(String docName) throws FileNotFoundException, IOException {
    XWPFDocument doc = new XWPFDocument();
    for (Theme t : themes) {
      for (Keyword k : t.getKeywords()) {
        for (Occurrence c : k.getOccurrs()) {
          XWPFParagraph p = doc.createParagraph();
          p.setAlignment(ParagraphAlignment.LEFT);
          XWPFRun r = p.createRun();
          setRunAttributes(r);
          r.setText(c.getOccurInfo());
          r.addCarriageReturn();

          String[] strings = c.getSentece().split(k.getName());
          for (int i = 0; i < strings.length; i++) {
            XWPFRun r2 = p.createRun();
            setRunAttributes(r2);
            r2.setText(strings[i]);

            if (i < strings.length - 1) {
              XWPFRun r3 = p.createRun();
              setRunAttributes(r3);
              r3.setBold(true);
              r3.setItalic(true);
              r3.setColor(t.getHexColor());
              r3.setText(k.getName());
            }
          }
        }
      }
    }
    FileOutputStream outStream = new FileOutputStream(docName);
    doc.write(outStream);
    outStream.close();
  }
コード例 #2
0
 private void setRunAttributes(XWPFRun run) {
   run.setFontFamily("Calibri");
   run.setFontSize(12);
 }