[java] Apache POI를 이용한 Word 문서 모드 설정

Apache POI에서 Word 문서의 모드를 설정하려면 다음과 같은 단계를 따를 수 있습니다.

  1. XWPFDocument 객체를 생성합니다. 이 객체는 Word 문서를 나타냅니다.
    XWPFDocument document = new XWPFDocument();
    
  2. document.getDocument().getBody().addNewSectPr()를 호출하여 CTSectPr 객체를 생성합니다. CTSectPr은 섹션 프로퍼티를 나타냅니다.
    CTSectPr sectPr = document.getDocument().getBody().addNewSectPr();
    
  3. sectPr.addNewType().setVal(STSectionMark.CONTINUOUS)를 호출하여 STSectPrtype 속성을 CONTINUOUS로 설정합니다. 이렇게 하면 문서가 연속모드로 설정됩니다.
    sectPr.addNewType().setVal(STSectionMark.CONTINUOUS);
    
  4. document.write()를 호출하여 Word 문서를 파일에 저장합니다.
    FileOutputStream out = new FileOutputStream("document.docx");
    document.write(out);
    out.close();
    

위의 코드를 실행하면 document.docx라는 파일이 생성되며, 해당 파일을 Microsoft Word에서 열어보면 연속모드로 설정된 문서를 확인할 수 있습니다.

Apache POI를 사용하면 Java로 Word 문서를 다양한 방식으로 조작할 수 있습니다. 더 많은 기능을 알아보려면 Apache POI의 공식 문서를 참조하시기 바랍니다.

참고 자료: