今天随便看看了javaeye里边的帖子,有一篇关于读取excel文件的jar包,觉得实用性还是很强的所以在这做一下学习的笔记,为日后使用的时候扑平道路~~~
jar包下载地址
import java.io.File;
import edu.npu.fastexcel.FastExcel;
import edu.npu.fastexcel.Sheet;
import edu.npu.fastexcel.Workbook;
import edu.npu.fastexcel.biff.parser.ParserException;
import edu.npu.fastexcel.compound.io.ReadException;
public class DoReadxml {
public static void main(String args[]) throws ParserException, ReadException
{
DoReadxml d1 = new DoReadxml();
d1.testDump();
}
public void testDump() throws ParserException, ReadException {
Workbook workBook;
workBook = FastExcel.createReadableWorkbook(new File("D://test.xls"));
workBook.open();
Sheet s;
s = workBook.getSheet(0);
System.out.println("SHEET:"+s);
for (int i = s.getFirstRow(); i <= s.getLastRow(); i++) {
System.out.print(i+"#");
for (int j = s.getFirstColumn(); j <=s.getLastColumn(); j++) {
System.out.print(","+s.getCell(i, j));
}
System.out.println();
}
workBook.close();
}
}
在d:/test.xls的sheet1,sheet2,sheet3中填写任意多的数据
结果:
SHEET:{name:Sheet1,index:0,firstRow:0,lastRow:2,firstColumn:0,lastColumn:9,offset:2358}
0#,ww,ww,ss,ssdsd,dsds,ds,sd,sd,sdsd,null
1#,sds,sdsd,sd,ssdsd,dsds,s,dsd,sd,dd,null
2#,null,null,null,null,null,null,null,null,null,null
SHEET:{name:Sheet2,index:1,firstRow:0,lastRow:2,firstColumn:0,lastColumn:10,offset:2929}
0#,dsad,asdas,dasd,asd,ads,asd,asd,asd,asd,asd,null
1#,asd,asdas,asd,asd,asd,ads,asd,asd,asd,asd,null
2#,null,null,null,null,null,null,null,null,null,null,null
SHEET:{name:Sheet3,index:2,firstRow:0,lastRow:3,firstColumn:0,lastColumn:6,offset:3528}
0#,das,das,dsad,asd,asd,dsa,null
1#,dsad,asd,asd,asd,asda,asd,null
2#,asda,asd,dsad,dasd,sdas,asd,null
3#,null,null,null,null,null,null,null