我想阅读xml
文件并使用jxl
。但我收到错误jxl.read.biff.BiffException: Unable to recognize OLE stream
。
当我搜索互联网时,Everbody说你应该保存为Excel 97-2003 Workbook.But我的excel文件是Excel 97-2003。我怎么解决这个问题?
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class deneme {
private String inputFile;
public void setInputFile(String inputFile) {
this.inputFile = inputFile;
}
public void read() throws IOException {
File inputWorkbook = new File(inputFile);
Workbook w;
try {
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
for (int j = 0; j < sheet.getColumns(); j++) {
for (int i = 0; i < sheet.getRows(); i++) {
Cell cell = sheet.getCell(j, i);
CellType type = cell.getType();
if (type == CellType.LABEL) {
System.out.println("I got a label "
+ cell.getContents());
}
if (type == CellType.NUMBER) {
System.out.println("I got a number "
+ cell.getContents());
}
}
}
} catch (BiffException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
deneme test = new deneme();
test.setInputFile("c:/data.xls");
test.read();
}
}
答案 0 :(得分:2)
单击“另存为”再次保存,然后选择“Excel 97-2003 WorkBook”。 它适合我......
答案 1 :(得分:0)
将其重命名为.xls文件不起作用。
您必须手动转到另存为 - &gt; Excel 97-2003工作簿并保存。