package File;import java.io.File;import jxl.Cell;
import jxl.CellType;
import jxl.DateCell;
import jxl.NumberCell;
import jxl.Sheet;
import jxl.Workbook;public class ExeclReader
{
public static void main(String[] args)
{
Workbook workbook = null;
Sheet sheet =null;
Cell cell = null;
try {
workbook = Workbook.getWorkbook(new File("D:/Backup/我的文档/12.xls"));
} catch (Exception e) {
try {
throw new Exception("file to import not found!");
} catch (Exception e1) {
e1.printStackTrace();
}
} sheet= workbook.getSheet(0);
int columnCount=sheet.getColumns();
int rowCount=sheet.getRows();
for (int i = 0; i <rowCount; i++) {
for (int j = 0; j <columnCount; j++) {//注意,这里的两个参数,第一个是表示列的,第二才表示行
cell=sheet.getCell(j, i); //要根据单元格的类型分别做处理,否则格式化过的内容可能会不正确
if(cell.getType()==CellType.NUMBER){
System.out.print(((NumberCell)cell).getValue());
}
else if(cell.getType()==CellType.DATE){
System.out.print(((DateCell)cell).getDate());
}
else{
System.out.print(cell.getContents());
}
//System.out.print(cell.getContents());
System.out.print("/t");
}
System.out.print("/n");
}
//关闭它,否则会有内存泄露
workbook.close();
}
}
原文链接:http://blog.csdn.net/lgq_0714/article/details/4281951
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货