Search code examples
javaexceljxl

Modifying Excel worksheet that contains metadata - how can I avoid unnecessary warnings?


I've been given an Excel worksheet that I have to fill in so I'm using JExcel to do it for me. However, when I use JExcel to fill just one cell, it works but I get a whole bunch of unnecessary warnings which lags everything (I'm assuming it's because of all the metadata that's contained in the excel file). Does anyone know how I can avoid these warnings without deleting the metadata? (I need to keep the metadata since I'm assuming it's important for parsing the filled excel worksheet on the other end)

Your help is much appreciated!

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

These are the insane warnings that I get:

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

Solution

  • You can consider this code to copy a worksheet in one workbook to a new worksheet in another workbook to avoid such warnings. Also check how to use WorkBookSettings in jxl that may help you to avoid those warnings.

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

    Here is the source code for that warning

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

    Hope you are able to analyze reason for warning.