이 작업을 두 단계로 나눠야하며 다른 문제를 해결하기 때문에 Jsoup와 POI가 모두 필요합니다.
- 잡아 웹 페이지 및 분석 (Jsoup)는
- 쓰기는 엑셀 스프레드 시트로 결과를 구문 분석 (POI)
1) 당신은 웹 페이지를 얻을 구문 분석 Jsoup을 사용할 수 있으며, Jsoup Cookbook가있다 당신이 이것을 할 수있는 많은 간단한 예. 예를 들면 다음과 같습니다.
Document doc = Jsoup.connect("http://example.com/").get(); // Grab page
Element table = doc.getElementById("my-table"); // Get table with id "my-table"
선택기를 사용하면 필요한 데이터를 읽고 POJO 또는 어디서든 원하는대로 쓸 수 있습니다.
2) 필요한 데이터가 있으면 POI를 사용하여 Excel 스프레드 시트를 만들 수 있습니다.
바쁜 개발자 가이드는 how to write to an excel sheet과 hyperlinks을 만드는 방법을 보여줍니다. 생성 하이퍼 링크의 요지는
이다
Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("Test sheet");
Cell cell = sheet.createRow(0).createCell((short)0);
cell.setCellValue("URL Link"); // Text that will be shown, e.g. AL2015
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
link.setAddress("http://poi.apache.org/"); // Set actual hyperlink URL
cell.setHyperlink(link); // Add hyperlink to cell