我想从Excel文件的一栏中找到内容的数量。



Location Device Second
1         A      10
2         B       20
3                 30


现在,我希望它可以显示,
位置:3
设备:2
第二名:3

我正在使用jxl。

 Workbook existingWorkbook = Workbook.getWorkbook(new File(filename1));
        WritableWorkbook workbookCopy = Workbook.createWorkbook(new File(filename1), existingWorkbook);
        WritableSheet sheetToEdit = workbookCopy.getSheet(0);

     int n=   sheetToEdit.getcolumns();
     System.out.println(n);

        workbookCopy.write();
        workbookCopy.close();


在这里,我得到的只是列数,

你能告诉我,我该怎么做?

最佳答案

我认为除了手动计数和确定空单元格外,没有其他直接方法可以做到:

Workbook existingWorkbook = Workbook.getWorkbook(new File(filename1));
WritableWorkbook workbookCopy = Workbook.createWorkbook(new File(filename1), existingWorkbook);
WritableSheet sheetToEdit = workbookCopy.getSheet(0);

for (int i=0; i<sheetToEdit.getcolumns(); i++) {
    int columnCount = 0;
    for (Cell cell : sheetToEdit.getColumn(i))
        if (!cell.getContents().equals(""))
            columnCount++;
    System.out.println(columnCount);
}

workbookCopy.write();
workbookCopy.close();

10-06 12:40