Jxl對已有的excel追加資料或修改資料
阿新 • • 發佈:2019-02-18
public class ExcelTest { /** * @param args * @throws IOException * @throws BiffException * @throws WriteException */ public static void main(String[] args) throws IOException, BiffException, WriteException { Workbook wb = null; WritableWorkbook wwb = null; try { wb = Workbook.getWorkbook(new File("src\\jxlrwtest.xls")); wwb = Workbook.createWorkbook(new File("src\\jxlrwtest.xls"),wb); // 在原有工作簿jxlrwtest.xls上追加資料 if (wb != null && wwb != null) { WritableSheet sheet = wwb.getSheet(0); WritableCell cell = sheet.getWritableCell(0, 0); // 修改第一頁的第一行第一列資料 if (cell.getType() == CellType.LABEL) { Label l = (Label) cell; l.setString("modified cell2353"); // 設定資料 } wwb.write(); System.out.println("工作簿寫入資料成功!"); } wwb.close();// 關閉 } catch (Exception e) { e.printStackTrace(); } finally { wb.close(); } } }