大家好,最近遇到一个问题,需要用java去读取excel中某一列得 数据,然后对这一列的数据都加1.从网上搜索了一下,说可以用
poi或者jxl。可由于时间紧迫,来不及去仔细得看帮组文档。请各位大侠指点一下!拜谢!

解决方案 »

  1.   

    找个POI的示例代码看看不就知道了
      

  2.   

    对就用poi这个开源的东西,再家itext
      

  3.   

    步骤1: 先下载个poi步骤2:使用下面的代码
    public static void test() {
        String fileToBeRead = "C:\\project_TMP\\testPrj\\新規.xls"; // excel位置
        int coloum = 3; // 比如你要获取第三列
    try {
    HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
    fileToBeRead));
    HSSFSheet sheet = workbook.getSheet("Sheet1"); for (int i = 0; i <= sheet.getLastRowNum(); i++) {
    HSSFRow row = sheet.getRow((short) i);
    if (null == row) {
    continue;
    } else {
    HSSFCell cell = row.getCell((short) 3);
    if (null == cell) {
    continue;
    } else {
    System.out.println(cell.getStringCellValue());
    int temp = Integer.parseInt(cell.getStringCellValue());
    cell.setCellValue(temp + 1);
    }
    }
    }
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }步骤3:结贴给分!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      

  4.   

    给楼住个jxl例子吧/**
    用jxl读excel文件代码例子
    */
    public class ReadExl { 
    public static void main(String args[]) 
        { 
    String path="c:\\测试数据2.xls";//Excel文件URL 
    try{ 
    InputStream is = new FileInputStream(path);//写入到FileInputStream  
    jxl.Workbook wb = Workbook.getWorkbook(is); //得到工作薄 
     jxl.Sheet st = wb.getSheet(0);//得到工作薄中的第一个工作表 
     //Cell cell=st.getCell(1,1);//得到工作表的第一个单元格,即A1  
     //String content=cell.getContents();//getContents()将Cell中的字符转为字符串  
     int  row=st.getRows(); 
     int col=st.getColumns(); 
     for(int i=1;i <row;i++){ 
     for(int j=0;j <col;j++){ 
     Cell cell0 = st.getCell(j, i);//得到工作表的第一个单元格,即A1  
                             String content0 = cell0.getContents(); 
       } 
     } 
      
     wb.close();//关闭工作薄 
     is.close();//关闭输入流 
    }catch(FileNotFoundException e){ 
    e.printStackTrace(); 
    }catch(IOException e){ 
           e.printStackTrace(); 
          }catch(BiffException e){ 
           e.printStackTrace(); 
          } 
        }