0
Apache POI를 사용하여 단어 문서의 링크를 추출하는 방법을 아는 사람이 있습니까? 또는 단락에서 더 나아 졌습니까?Apache POI는 단어 문서의 하이퍼 링크를 추출합니다.
Apache POI를 사용하여 단어 문서의 링크를 추출하는 방법을 아는 사람이 있습니까? 또는 단락에서 더 나아 졌습니까?Apache POI는 단어 문서의 하이퍼 링크를 추출합니다.
워드 2003과 새로운 :
//Links extractor
StringBuffer text = null;
try {
FileInputStream fis = new FileInputStream(new File("YOUR_DOCX_FULL_PATH_HERE));
XWPFDocument document = new XWPFDocument(fis);
text = new StringBuffer();
// First up, all our paragraph based text
Iterator<XWPFParagraph> i = document.getParagraphsIterator();
while(i.hasNext()) {
XWPFParagraph paragraph = i.next();
// Do the paragraph text
for(XWPFRun run : paragraph.getRuns()) {
if(run instanceof XWPFHyperlinkRun) {
text.append(run.toString());
bean.setName(run.toString());
XWPFHyperlink link = ((XWPFHyperlinkRun)run).getHyperlink(document);
if(link != null) {
text.append(" <" + link.getURL() + ">");
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
일반적으로 파일을 가지고 있다면 InputStream에서 XWFP/XSSF/XSLF 인스턴스를 열지 않는 것이 좋습니다. 전체 인스턴스를 메모리에 버퍼링해야하기 때문입니다. 파일을 통해 직접 열려면 훨씬 낫습니다. – Gagravarr
이전 스타일 .doc 파일, 또는 새로운 스타일 .DOCX 사람? (약간 씩 다릅니다.) – Gagravarr