JXL   只有  write xls 文件?
没有  read  的 ?

解决方案 »

  1.   

    有呀
    public Collection readXLSForLabStandard(InputStream in) throws Exception
    {
    Collection result = new ArrayList();
    HSSFWorkbook  workbook = new HSSFWorkbook(in);

    HSSFSheet  sheet = workbook.getSheetAt(0);

    ImportUtil sheetUtil = new ImportUtil();

    //构建出读取合并单元格的对象。
    MergedManager mergedManager = new MergedManager(sheet);

    //取得这张工作表一共有多少行。
    int rowCount = sheet.getPhysicalNumberOfRows();

    //开始循环读取Excel.
    row:for (int i = 0; i < rowCount; i++) {
    int cellCount = sheet.getRow(i).getPhysicalNumberOfCells();
    for (int j = 0; j < cellCount; j++) {
    HSSFCell  cell = sheet.getRow(i).getCell((short)j);
    if(cell!=null && cell.getCellType()==HSSFCell.CELL_TYPE_STRING)
    {
    String cellValue = cell.getStringCellValue();

    //以LabConstants.CONTENTTITLE为基准开始进行读取。
    if(cellValue.startsWith(LabConstants.CONTENTTITLE))
    {
    log.info(cellValue);
    temp:for (int k = 0; k < cellCount-3; k++) {

    //定位起点,也就是"防寒服"等列,然后开始读取。
    Lab_standard_postition lab_pos = new Lab_standard_postition(i+2,(short)(j+3+k));

    int index = lab_pos.getRownum()+3;

    for(;;index++)
    {
    //读取三级岗位所在的位置。
    Position firstPostPos = lab_pos.getFirstPost(index);
    Position secondPostPos = lab_pos.getSecondPost(index);
    Position thirdPostPos = lab_pos.getThridPost(index);

    //拿取三级岗位的名称。
    String firstPostName = sheetUtil.getStringValueWhitPosition(sheet, firstPostPos);
    String secondPostName = sheetUtil.getStringValueWhitPosition(sheet, secondPostPos);
    String thirdPostName = sheetUtil.getStringValueWhitPosition(sheet, thirdPostPos);

    //判断如果超过最大行数并且这个一行中的劳保用品读完了,则停止读取。
    if(index>=rowCount && k == cellCount-3)
    {
    break row;
    }

    //如果第三级岗位的名称没拿到,那么则说明这一行已经没有值,跳出列循环,去循环下一列。
    if(thirdPostName==null || "".equals(thirdPostName.trim()))
    continue temp;

    //在读取一级岗位名称的时候如果没拿到,那说名这个一级岗位在合并的单元格中,读取出这个合并单元格的值。
    if(firstPostName==null || "".equals(firstPostName.trim()))
    {
    firstPostName =  mergedManager.getRegionValue(firstPostPos);
    }

    //与读一级岗位时同理,读二级岗位名称。
    if(secondPostName==null || "".equals(secondPostName.trim()))
    {
    secondPostName = mergedManager.getRegionValue(secondPostPos);
    }

    //读取发放标准,如2(24),如果没读到,进入下一次循环。
    Position contentPos = lab_pos.getContentPos(index);
    String contentValue =null;
    try {
    contentValue = sheetUtil.getStringValueWhitPosition(sheet, contentPos);
    } catch (RuntimeException e) {
    continue;
    }
    if(contentValue==null || "".equals(contentValue.trim()))
    {
    continue;
    }

    //读取出劳保用品名称,如"防寒服"。
    String temp_labName = sheetUtil.getStringValueWhitPosition(sheet, lab_pos);

    //构建出Temp_Lab_standardBean,保存在results中。
    Temp_Lab_standardBean temp_bean = new Temp_Lab_standardBean();
    temp_bean.setLabName(temp_labName.trim());
    temp_bean.setPos(lab_pos);
    temp_bean.setFirstPostName(firstPostName.trim());
    temp_bean.setSecondPostName(secondPostName.trim());
    temp_bean.setThirdPostName(thirdPostName.trim());
    temp_bean.setContent(contentValue.trim());
    result.add(temp_bean);

    log.info("读取到Temp_Lab_standardBean::     first :"  + temp_bean.getFirstPostName() + "         second : "+ temp_bean.getSecondPostName() + "   thrid :" + temp_bean.getThirdPostName());

    }
    }
    }
    }
    }
    }
    in.close();

    return result;
    }
      

  2.   

     Collection result = new ArrayList();
            HSSFWorkbook  workbook = new HSSFWorkbook(in);
            
            HSSFSheet  sheet = workbook.getSheetAt(0);
            
            ImportUtil sheetUtil = new ImportUtil();
    HSSFWorkbook
    HSSFSheet
    这些都是JXL API  里没有的吧 
    你自己  创建的 ?
      

  3.   

    HSSFCell  cell = sheet.getRow(i).getCell((short)j); 你不是读execl吗?我以前都这么读
      

  4.   

     不好意思搞错了 我用的poi