I am exporting a file from a web application which is in .xls format. When I am trying to read this file, it is throwing error as:
java.io.IOException: Invalid header signature; read 0x6576206C6D783F3C, expected 0xE11AB1A1E011CFD0
This is an exported file so could not change the format.
Here is my code and attached is the excel file:
public void verifyExportedData() throws Exception{
String filename = "Top_Down_Planning_by_Investment.xls"
File=new FileInputStream(new File("testdata/"+filename));
HSSFWorkbook workbook = new HSSFWorkbook(File);
HSSFSheet sheet=workbook.getSheet("Top Down Planning by Investmen");
DataFormatter formatter = new DataFormatter();
System.out.println("Cell data : "+sheet.getRow(0).getCell(1));
}
Can anyone please help?
The "expected" and "actual" file signatures are being output in the reverse order to normal. (It is probably a big-endian versus little-endian thing ...)
According to a source I found on the web, the file signature for a ".xls" file is
D0 CF 11 E0 A1 B1 1A E1
which matches the "expected" signature (reversed). So if I reverse the "actual" signature, I get
3C 3F 78 6D 6C 20 76 65
If I convert those hex code to ASCII I get
'<' '?' 'x' 'm' 'l' ' ' 'v' 'e'
or
<?xml ve
Is this looking familiar? Here's a typical XML file header:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
You appear to have exported the file as an XML-based format rather than the legacy ".xls" format. I am guessing the file is in ".xlxs" format or similar.
I think that you need to use XSSF rather than HSSH: