poi读取和写入excel2003

   /**
     * 方法说明:<br>
     * poi读取excel2003数据
     * @param srcFileUrl
     * @param startDate
     * @param endDate
       */ 

public void readExcel(String srcFileUrl, int startDate, int endDate)
            throws FileNotFoundException, IOException {
        File destFile = new File(destFileUrl);
        HSSFWorkbook book = new HSSFWorkbook(new FileInputStream(destFile));
        HSSFSheet poiSheet = book.getSheetAt(0);
        // 获取sheet页的所有行数
        int dateD = 11 + startDate - 1;
        int endD = 11 + endDate;
        for (int i = dateD; i < endD; i++) {
            HSSFRow row = poiSheet.getRow(i);
            int cellCount = row.getPhysicalNumberOfCells(); //获取总列数 
            for (int j = 0; j < cellCount; j++) {
                .out.println("列数" + j);
                HSSFCell cell = row.getCell(j);
                String value = cell.toString();
                System.out.println(value);
            }
           
        }
    }

/**
     * 方法说明:<br>
     * poi写入excel2003数据
     * @param destFile
     * @param rowNo
     * @param col 
     * @param col
     */   

public static void writeValueInCell(File destFile, int rowNo, int col,
            String value) throws IOException {
        POIFSFileSystem fs = null;
        fs = new POIFSFileSystem(new FileInputStream(destFile));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row = sheet.getRow(rowNo);
        HSSFCellStyle cellStyle = row.getCell(rowNo).getCellStyle();
        HSSFCell cell = row.createCell(col);
        cell.setCellValue(value);
        cell.setCellStyle(cellStyle);
        FileOutputStream fileout = new FileOutputStream(destFile);
        wb.write(fileout);
        fileout.close();
    }
   

你可能感兴趣的:(poi,读取和写入excel2003)