03版Excel,需要用到jxl.jar这个jar包
packagetest.poi;importjava.io.File;importjava.io.IOException;importjxl.Sheet;importjxl.Workbook;importjxl.read.biff.BiffException;//03版excelpublicclassgetExcel {publicstaticvoidmain(String[] args){
show03Excel();
}publicstaticvoidshow03Excel(){
Sheet sheet;
Workbook book=null;try{
book= Workbook.getWorkbook(newFile("F:\\Book1.xls"));
}catch(BiffException e) {
e.PRintStackTrace();
}catch(IOException e) {
e.printStackTrace();
}//System.out.println(book);//获得第一个工作表对象(ecxel中sheet的编号从0开始,0,1,2,3,....)sheet=book.getSheet(0);introws = 0;intr=0,l=0;
String value=null;while(sheet.getCell(0,r).getContents()!=""&&sheet.getCell(0,r).getContents()!=null){
r++;
}while(sheet.getCell(l,0).getContents()!=""&&sheet.getCell(l,0).getContents()!=null){
l++;
}for(inti=0;i<(r);i++){for(intj=0;j<(l);j++)
System.out.print(sheet.getCell(j,i).getContents()+"\t\t");
System.out.println();
}
}
}
07版EXCEL,需要用到poi这个jar包
packagetest.poi;importjava.io.IOException;importorg.apache.poi.xssf.usermodel.XSSFRow;importorg.apache.poi.xssf.usermodel.XSSFSheet;importorg.apache.poi.xssf.usermodel.XSSFWorkbook;publicclassget07Excel {publicstaticvoidmain(String[] arg){
show07excel();
}publicstaticvoidshow07excel(){
XSSFWorkbook xwb=null;try{
xwb=newXSSFWorkbook("F:\\Book1.xlsx");
}catch(IOException e) {
e.printStackTrace();
}
XSSFSheet sheet=xwb.getSheetAt(0);
XSSFRow row;
String cell;intr=0,l=0;
row= sheet.getRow(0);while(row.getCell(l).toString()!=""&&row.getCell(l).toString()!=null){
l++;
}while(row.getCell(0).toString()!=""&&row.getCell(0).toString()!=null){
r++;
row=sheet.getRow(r);
}
System.out.println("the rows is "+r+" and the number of one row is "+l);//循环输出表格中的内容for(inti = sheet.getFirstRowNum(); i < r; i++)
{
row=sheet.getRow(i);for(intj = row.getFirstCellNum(); j < l; j++)
{
cell=row.getCell(j).toString();
System.out.print(cell+ "\t");
}
System.out.println("");
}
}
}