简体   繁体   中英

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.

This is the source code which I have written, I get an exception --> Error: Invalid header signature; read 0x6D78206C6D74683C, expected 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.

Links :

POI Example

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

HTML Parser Example

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

Also you have easily convert your html code into XLS. Here you can find the example http://wiki.sdn.sap.com/wiki/display/WDJava/Export+to+Excel+%28Without+third+party+APIs%29

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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