qqsheji
全部博文(54)
2016年(3)
2014年(8)
2013年(4)
2012年(2)
2011年(29)
2010年(8)
cynthia
浪花小雨
Phyllis6
fenzao
菱绿
poluy
damingge
anben197
hzzxsuni
分类: Java
2011-03-01 10:17:00
Workbook rwb = null;String fileName = "e:\\test.xls";try { File file = new File(fileName); rwb = Workbook.getWorkbook(file); Sheet result = rwb.getSheet(0); int rsColumns = result.getColumns(); //获取Sheet表中所包含的总行数 int rsRows = result.getRows(); System.out.print(rsColumns + "--" + rsRows); String simNumber = "", termSeqId = ""; for (int k = 0; k < rsRows; k++) { for (int j = 0; j < rsColumns; j++) { Cell cell = result.getCell(j, k); if (j == 0) { simNumber = cell.getContents(); } if (j == 1) { termSeqId = cell.getContents(); } } }} catch (Exception e) { e.printStackTrace();} finally { rwb.close();}
Excel 2007:
< import="org.apache.poi.xssf.usermodel.XSSFWorkbook"%>< import="org.apache.poi.xssf.usermodel.XSSFSheet"%>< import="org.apache.poi.xssf.usermodel.XSSFRow"%>< import="org.apache.poi.hssf.usermodel.HSSFRow"%>< import="org.apache.poi.xssf.usermodel.XSSFCell"%>
//Excel文件处理 try { XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(WEBROOT+"/WEB-INF/tmp/"+Calendar.getInstance().getTime().getTime()+"."+tail)); XSSFSheet sheet = wb.getSheetAt(0);//获取工作薄 int totalRows = sheet.getLastRowNum();//获取行数 XSSFRow column = sheet.getRow(0); int totalColumn = column.getLastCellNum();//获取列数 for (int j = 0; j < totalRows; j++) { if(j == 0) continue; XSSFRow sheetrows = sheet.getRow(j); for (int k = 0; k < totalColumn; k++) { XSSFCell cell = sheetrows.getCell((short) k); if(cell!=null){ System.out.println("第" + j + "行 第" + k + "列的值是"+sheetrows.getCell(k).toString()); } } } }catch (Exception e) { e.printStackTrace(); }
上一篇:android中CheckBox,button控件绑定监听器
下一篇:android杀死进程
chinaunix网友2011-03-05 16:17:27
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com
登录 注册