2

我得到了一个必须填写的 Excel 工作表,所以我使用 JExcel 来为我填写。但是,当我使用 JExcel 仅填充一个单元格时,它可以工作,但我会收到一大堆不必要的警告,这些警告会滞后于所有内容(我假设这是因为 excel 文件中包含所有元数据)。有谁知道如何在不删除元数据的情况下避免这些警告?(我需要保留元数据,因为我假设它对于解析另一端填充的 Excel 工作表很重要)

非常感谢您的帮助!

public static void main(String args[]){
    Workbook workbook;
    try{
        workbook = Workbook.getWorkbook(new File("Test.xls"));
        WritableWorkbook copy = Workbook.createWorkbook(new File("output.xls"), workbook);
        WritableSheet sheet1 = copy.getSheet(0); 
        Label label = new Label(4,5, "PO1234355");
        sheet1.addCell(label);


        copy.write(); 
        copy.close();

    }
    catch(Exception e){
        System.out.println("Could not get workbook. Error: " + e.toString());
    }
}

这些是我得到的疯狂警告:

Warning:  Cannot read name ranges for BUY - setting to empty
Warning:  Cannot read name ranges for Buyer - setting to empty
Warning:  Cannot read name ranges for Casual_Buyer - setting to empty
Warning:  Cannot read name ranges for Departments - setting to empty
Warning:  Cannot read name ranges for Dept_No - setting to empty
Warning:  Cannot read name ranges for Designer - setting to empty
Warning:  Cannot read name ranges for Model - setting to empty
Warning:  Cannot read name ranges for Seasons - setting to empty
Warning:  Cannot read name ranges for Supplier - setting to empty
Warning:  Cannot read name ranges for Technologist - setting to empty
Warning:  Cannot read name ranges for Typed_by - setting to empty
Warning:  Cannot read name ranges for YESNO - setting to empty
Warning:  no filename property for drawing
Warning:  no filename property for drawing
Warning:  no filename property for drawing
Warning:  no filename property for drawing
Warning:  no filename property for drawing
Warning:  no filename property for drawing
Warning:  no filename property for drawing
Warning:  no filename property for drawing
Warning:  no filename property for drawing
4

3 回答 3

1

您可以考虑使用此代码将一个工作簿中的工作表复制到另一个工作簿中的新工作表以避免此类警告。还要检查如何WorkBookSettings在 jxl 中使用,这可能会帮助您避免这些警告。

for (int i = 0 ; i < numrows ; i++)
  {
    for (int j = 0 ; j < numcols ; j++)
    {
      readCell = sheet.getCell(i, j);
      newCell = readCell.copyTo(i, j);
      readFormat = readCell.getCellFormat();
      newFormat = new WritableCellFormat(readFormat);
      newCell.setCellFormat(newFormat);
      newSheet.add(newCell);
    }
  }

是该警告的源代码

String n = name != null ? name : builtInName.getName();
logger.warn("Cannot read name ranges for " + n + 
                  " - setting to empty");
NameRange range = new NameRange(0,0,0,0,0);
ranges.add(range);

希望您能够分析警告的原因。

于 2012-12-31T16:45:19.737 回答
1

我也有同样的警告。我删除了 Excel 中的所有命名范围(公式 > 名称管理器)。之后所有的警告都消失了。

于 2014-09-05T21:58:34.893 回答
1

我的文件没有命名范围,我仍然有那个警告。所以我尝试使用带有 WorkbookSettings 的构造函数来获取我的工作簿。它帮助了我。

WorkbookSettings ws = new WorkbookSettings();
ws.setSuppressWarnings(true);
Workbook workbook = Workbook.getWorkbook(new File("Stock labels.xls"), ws);
于 2016-12-27T14:52:39.987 回答