Reputation: 61
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.
Upvotes: 3
Views: 31834
Reputation: 10069
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
Upvotes: 3