问题
While trying to read an xls file using jExcelAPI, I find that the library dumps a lot of information in stderr, sometimes this information is not relevant. For example, this code snippet causes lots of 'Warnings' to be dumped on stderr stream:
Workbook workbook = Workbook.getWorkbook(new File(flname));
//For each sheet in the workbook
for (int currentSheet = 0; currentSheet < workbook.getNumberOfSheets(); currentSheet++)
{
Sheet sheet = workbook.getSheet(currentSheet);
System.out.println("Currently processing " + sheet.getName());
}
The warnings are like:
Currently processing frst sheet
Warning: Cell C33680 already contains data
Warning: Cell D33680 already contains data
Warning: Cell E33680 already contains data
Warning: Cell F33680 already contains data
Warning: Cell B33680 already contains data
Currently processing Lst Sheet
How to avoid the library from dumping all this unwanted data? Also I do not understand why the code even looks at all the cells of the sheet, when all I am asking for it to do is list the name of the sheets (I understand that Workbook.getSheetNames() can do a similar task - but say I wanted to print the name of the sheet and contents of a single cell in the sheet).
Am I using the library incorrectly?
回答1:
I have never used this library, however quick look at Logger.initializeLogger() it looks like by default it tries to Log using Log4J. Do you have Log4J on your CLASSPATH? You can also use SLF4J bridge.
When you successfully redirect JExcelAPI into logging framework, you can configure which messages are dumped (and where).
来源:https://stackoverflow.com/questions/7860834/why-does-jexcelapi-dump-warnings-in-stderr-and-how-to-stop-this-behaviour