日期:2014-05-20 浏览次数:20941 次
public void Update() {
        boolean isChecked = false;
        int x, y;
        String id = null;
        String number = null;
        try {
            // Excel获得文件
            // Excel获得文件
            Workbook wb = Workbook.getWorkbook(new File("T.xls"));
            // 打开一个文件的副本,并且指定数据写回到原文件
            WritableWorkbook book = Workbook.createWorkbook(new File("T.xls"),
                    wb);
            // 添加一个工作表
            // WritableSheet sheet = book.createSheet("第二页", 1);
            WritableSheet sheet = book.getSheet(0);
            
                    // 得到当前工作表的列数
                    int colNum = sheet.getColumns();
                    for (int j = 0; j < colNum; j++) {
                        // 得到当前列的所有单元格
                        Cell[] cells = sheet.getColumn(j);
                        if (cells.length > 1) {
                            isChecked = true;
                            continue;
                        } else {
                            flag = true;//
                            while (flag) {
                                id = getId();
                                number = this.getNumber(id);
                                // 对每个单元格进行循环
                                for (int k = 1; k < cells.length - 1; k++) {
                                    System.out.println(id);
                                    // 读取当前单元格的值
                                    String cellValue = cells[k].getContents();
                                    if ((cellValue == null || cellValue
                                            .equals(""))
                                            && cellValue.equals(number)) {
                                        Label lc = new Label(k, j, "Checked-in");
                                        sheet.addCell(lc);
                                        book.write();
                                        System.out.println("添加成功");
                                        // k = cells.length;
                                    }
                                }
                            }
                        }
                    }
book.close();
        } catch (Exception e) {
            flag = false;
            System.out.println(e);
        }
    }