`
dylan_cherie
  • 浏览: 17047 次
  • 性别: Icon_minigender_1
最近访客 更多访客>>
社区版块
存档分类
最新评论

JAVA简单读取EXCEL文件内容

 
阅读更多
java 代码
  1. import jxl.Cell;   
  2. import jxl.Sheet;   
  3. import jxl.Workbook;   
  4. import jxl.read.biff.BiffException;  
jxl 包
java 代码
  1. InputStream is;   
  2. try {   
  3.        is = new FileInputStream(filePath + fileName);   
  4.        Workbook rwb = Workbook.getWorkbook(is);   
  5.        Sheet st = rwb.getSheet("Sheet1");   
  6.        int columns = st.getColumns(); // 列   
  7.        int rows = st.getRows(); // 行   
  8.   
  9.        // -- 数据读取循环从行定位,单元格读取参数从列开始定位   
  10.        for(int i=1;i// 不查找表头第一行   
  11.             for(int j=0;j
  12.                 Cell coo = st.getCell(j,i);  // 列,行  // 单元格先定位列,再定位行   
  13.                 String strc = coo.getContents();  // 读出内容默认为字符串   
  14.                 System.out.println(strc);   
  15.             }   
  16.       }   
  17.        rwb.close();   
  18. catch (FileNotFoundException e) {   
  19.  e.printStackTrace();   
  20. catch (BiffException e) {   
  21.  e.printStackTrace();   
  22. catch (IOException e) {   
  23.  e.printStackTrace();   
  24. }   
如果单元格内容有计算公式的话,读出的内容是计算后的显示内容。
分享到:
评论
1 楼 dylan_cherie 2007-02-28  
晕啊,代码贴完预览还没事呢,怎么就少了一块。

for(int i=1;i<rows;i++) {
      for(int j=0;j<columns;j++) {

相关推荐

Global site tag (gtag.js) - Google Analytics