操作excel
static void create(String path) throws Exception { //读取文件 FileInputStream in = new FileInputStream(path); XSSFWorkbook wb = new XSSFWorkbook(in); // 获得该工作区的第一个sheet XSSFSheet sheet = wb.getSheetAt(0); int rowNum = sheet.getLastRowNum();//行 int columnNum = sheet.getRow(0).getPhysicalNumberOfCells();//列 System.out.println(rowNum + "条数据," + columnNum + "列"); XSSFRow row; String bm; String mm; for (int i = 1; i <= rowNum; i++) { row = sheet.getRow(i); //读取值 bm = (long) row.getCell(0).getNumericCellValue() + ""; mm = jia(bm); //设置值 row.getCell(4).setCellValue(mm); System.out.println(mm); } //另存为 FileOutputStream out = new FileOutputStream("/Users/1111/Desktop/112000000.xlsx"); //写出 wb.write(out); out.close(); }
以上程序使用poi读取excel表2007,修改值,另存一份。