package inputXlsx.com;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class InputXlsx {
/**
* 读取文件内容时必须是原生的.xls文件,也就是新建的.xls文件,其他通过更改后缀变更成的.xls文件无法进行读取,会报错
* @param args
*/
public static void main(String[] args) {
File file = new File("D:/哈南生产计划.xls");
if (file.exists()) {// 判断该文件是否存在
try {
Workbook book = Workbook.getWorkbook(file);//
Sheet sheet = book.getSheet(0); // 获得第一个工作表对象
for (int i = 0; i < sheet.getRows(); i++) {
for (int j = 0; j < sheet.getColumns(); j++) {
Cell cell = sheet.getCell(j, i); // 获得单元格
System.out.print(cell.getContents() + " ");
}
System.out.print("\n");
}
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}