Friday, January 25, 2013

Suppressing JExcel warnings

JExcelAPI(Jxl) which is a Java library for parsing Excel files does not have any configuration to use a custom logger at deployment time. JExcel decides logger class at build time and to use any other logger like Log4J, one must build Jxl jar file after configuring JExcel build.properties to use a custom logger. This is not a practical solution for many as they have to go through the hassles of building a custom jar with every new release of JExcel.

It is common that parsing an Excel file will have many warnings and one will not be interested in seeing those. Also this invokes curiousity of testers and they will create bug for the warning.

One such warning is

Warning:  Cannot read name ranges for GROUP5 - setting to empty

To suppress such warnings, JExcel provides a system property jxl.nowarnings which can be set to disable warnings. This can be passed as a startup argument to JVM or can be set in a class.

To pass it as argument to JVM add -Djxl.nowarnings=true This will suppress all warnings.

java -cp jxl-2.6.12.jar test.Jxl -Djxl.nowarnings=true

If running in Eclipse, set this argument in VM arguments section.


If you don't like the above approach, you can write a custom logger which internally delegates all log messages to a logger of your choice. For this extend jxl.common.Logger class and use logger of your choice and delegate all messages to that logger. To use this logger while running the application use argument logger and specify custom logger class there.

java -cp jxl-2.6.12.jar -Dlogger=test.Jxl.Log4JLogger


Refer Technical notes page at JExcel website for more info.



2 comments:

  1. The other way is to set the appropriate property on the WorkbookSettings bean that you use to create the workbook, as follows:

    File myfile = new File("...");
    WorkbookSettings settings = new WorkbookSettings();
    settings.setSuppressWarnings(true);
    Workbook workbook = Workbook.getWorkbook(myfile, settings);

    ReplyDelete
  2. Hi Marco,
    Thanks for this wonderful code. this is working fine. :)

    ReplyDelete