简体   繁体   English

使用POI将HTML数据表导出到Excel

[英]Export HTML data table to Excel using POI

Can you please let me know, how we can proceed in this case we have a pure HTML data in the form of Tables which should be converted to proper excel sheet. 你能告诉我,在这种情况下我们如何处理我们有一个表格形式的纯HTML数据,应该转换成适当的excel表格。

This is the source code which I have written, I get an exception --> Error: Invalid header signature; 这是我写的源代码,我得到一个异常 - >错误:无效的头签名; read 0x6D78206C6D74683C, expected 0xE11AB1A1E011CFD0|#] 读取0x6D78206C6D74683C,预期为0xE11AB1A1E011CFD0 |#]

    // Resulting byte stream from the DB
    resultBytes = dokumentSession.getXlsZuAuftrag(ts);
    if (resultBytes != null && resultBytes.length > 0) {
        try {
            InputStream fos = new ByteArrayInputStream(resultBytes);
            HSSFWorkbook workbook = new HSSFWorkbook(fos);
            workbook.createSheet("sheet1");
            FileOutputStream fileOut = new FileOutputStream("ipa_loader.xls");
            workbook.write(fileOut);
            fileOut.close();
        } catch (Exception e)
        {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }

Please let me know any inputs on this, any help is appreciated. 请告知我对此的任何意见,任何帮助表示赞赏。

Using any HTML parser you have to parse your HTML content then write the content into Excel using POI. 使用任何HTML解析器,您必须解析HTML内容,然后使用POI将内容写入Excel。

Links : 链接:

POI Example POI示例

http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/ http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/

HTML Parser Example HTML解析器示例

http://jsoup.org/cookbook/extracting-data/example-list-links http://jsoup.org/cookbook/extracting-data/example-list-links

Also you have easily convert your html code into XLS. 您也可以轻松地将您的HTML代码转换为XLS。 Here you can find the example http://wiki.sdn.sap.com/wiki/display/WDJava/Export+to+Excel+%28Without+third+party+APIs%29 在这里你可以找到例子http://wiki.sdn.sap.com/wiki/display/WDJava/Export+to+Excel+%28Without+third+party+APIs%29

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM