/** * @param filePath * @param output * @throws InvalidFormatException * @throws IOException * @throws ParserConfigurationException * @throws TransformerException */ public static void convert(String filePath, String output) throws InvalidFormatException, IOException, ParserConfigurationException, TransformerException { XlsxConverter converter = new XlsxConverter(filePath, output); Integer sheetNum = converter.x.getNumberOfSheets(); for (int i = 0; i < sheetNum; i++) { XSSFSheet sheet = converter.x.getSheet(converter.x.getSheetName(i)); String sheetName = converter.x.getSheetName(i); System.out.println("----starting process sheet : " + sheetName); // add sheet title { Element title = converter.htmlDocumentFacade.createHeader2(); title.setTextContent(sheetName); converter.page.appendChild(title); } converter.processSheet(converter.page, sheet); } converter.htmlDocumentFacade.updateStylesheet(); Element style = (Element) converter.htmlDocumentFacade.getDocument().getElementsByTagName("style").item(0); style.setTextContent(converter.css.append(style.getTextContent()).toString()); converter.saveAsHtml(output, converter.htmlDocumentFacade.getDocument()); }
public static void main(String[] args) throws InvalidFormatException, IOException, ParserConfigurationException, TransformerException { String name = "xml"; XlsxConverter.convert("c:/poi/" + name + ".xlsx", "c:/poi/x/" + name + ".html"); }