Export HTML data table to Excel using POI
Can you please let me know how we can proceed in this case, we have pure HTML data in the form of tables that needs to be converted into a custom excel sheet.
This is the original code I wrote, I am getting 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 resources on this, any help is appreciated.
source to share
Using any HTML parser you should parse your HTML content and then write it to Excel using POI.
Links:
POI example
http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/
Parser HTML example
http://jsoup.org/cookbook/extracting-data/example-list-links
Also you easily convert your html code to XLS. You can find an example here http://wiki.sdn.sap.com/wiki/display/WDJava/Export+to+Excel+%28Without+third+party+APIs%29
source to share