标头签名无效;读取0x6D78206C6D74683C,当我尝试读取excel表时,预期0xE11AB1A1E011CFD0出现上述错误。 xls格式。
当我尝试手动打开工作表时,我收到此错误:“'*******。xls'的文件格式和扩展名不匹配。文件可能已损坏或不安全。
String strCompleteFilepath=this.strFilePath + File.separator +
this.strFileName;
int strRowIndex=0;
int strColIndex=0;
String strCompVal="";
try{
InputStream file = new FileInputStream(strCompleteFilepath);
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
int strRowCount= sheet.getLastRowNum();
if(strRowCount>0)
{
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
Row row = (Row)rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = (Cell)cellIterator.next();
String strCellValue=cell.toString();
if (strCellValue.contentEquals(strKeyIdentifier))
{
strRowIndex=cell.getRowIndex();
System.out.println("The row number where
"+strKeyIdentifier+"is found: "+strRowIndex);
}
if (strCellValue.contentEquals(strColName))
{
strColIndex=cell.getColumnIndex();
System.out.println("The column where "+strColName+" is
found: "+strColIndex);
}
}
}
HSSFCell CompValue=sheet.getRow(strRowIndex).getCell(strColIndex);
switch (CompValue.getCellType())
{
case 0:
if (DateUtil.isCellDateFormatted(CompValue))
{
strCompVal = CompValue.getDateCellValue().toString();
} else
{
strCompVal = String.valueOf(CompValue.getNumericCellValue());
}
break;
case 2:
strCompVal = String.valueOf(CompValue.getBooleanCellValue());
break;
case 1:
strCompVal = CompValue.getStringCellValue();
}
//strCompVal=CompValue.toString();
file.close();
FileOutputStream out = new FileOutputStream(new `
File(strCompleteFilepath));
workbook.write(out);
out.close();
}
else
{
System.out.println("There is no data in the excel, the row count is : "+strRowCount);
}
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
return strCompVal;