修改包含元数据的Excel工作表 – 如何避免不必要的警告?

我已经得到一个Excel工作表,我必须填写,所以我使用JExcel来为我做。 然而,当我使用JExcel来填充一个单元格时,它可以工作,但是我得到了一大堆不必要的警告,这些警告滞后于一切(我假设这是因为Excel文件中包含的所有元数据)。 有谁知道我怎样才能避免这些警告,而不删除元数据? (我需要保留元数据,因为我认为parsing另一端填充的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 

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

 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); 

希望你能分析警告的理由。

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

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

 WorkbookSettings ws = new WorkbookSettings(); ws.setSuppressWarnings(true); Workbook workbook = Workbook.getWorkbook(new File("Stock labels.xls"), ws);