java读取03、07版EXCEL

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

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("");

}

}

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航