From: <udi...@us...> - 2023-04-15 10:51:13
|
Revision: 1473 http://sourceforge.net/p/j-trac/code/1473 Author: udittmer Date: 2023-04-15 10:51:10 +0000 (Sat, 15 Apr 2023) Log Message: ----------- handle null (i.e., empty) cells during Excel import Modified Paths: -------------- trunk/jtrac/src/main/java/info/jtrac/domain/ExcelFile.java trunk/jtrac/src/main/java/info/jtrac/wicket/ExcelImportPage.java Modified: trunk/jtrac/src/main/java/info/jtrac/domain/ExcelFile.java =================================================================== --- trunk/jtrac/src/main/java/info/jtrac/domain/ExcelFile.java 2023-04-14 07:03:55 UTC (rev 1472) +++ trunk/jtrac/src/main/java/info/jtrac/domain/ExcelFile.java 2023-04-15 10:51:10 UTC (rev 1473) @@ -503,8 +503,8 @@ Workbook wb = null; try { wb = WorkbookFactory.create(is); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (Exception ex) { + throw new RuntimeException(ex); } Sheet sheet = wb.getSheetAt(0); Row r = null; @@ -526,6 +526,7 @@ break; } Column column = new Column(value.trim()); + logger.debug("adding column "+value.trim()); columns.add(column); col++; } @@ -541,18 +542,22 @@ boolean isEmptyRow = true; for(col = 0; col < columns.size(); col++) { c = r.getCell((short) col); - Object value = null; - switch (c.getCellType()) { - case STRING : - value = c.getStringCellValue(); break; - case NUMERIC : - // value = c.getDateCellValue(); - value = c.getNumericCellValue(); - break; - case BLANK : - break; - default: // do nothing - } + Object value = null; + if (c != null) { + switch (c.getCellType()) { + case STRING : + value = c.getStringCellValue(); break; + case NUMERIC : + // value = c.getDateCellValue(); + value = c.getNumericCellValue(); + break; + case BLANK : + break; + default: // do nothing + } + } else { + // the cell may just be empty + } if (value != null && value.toString().length() > 0) { isEmptyRow = false; rowData.add(new Cell(value)); Modified: trunk/jtrac/src/main/java/info/jtrac/wicket/ExcelImportPage.java =================================================================== --- trunk/jtrac/src/main/java/info/jtrac/wicket/ExcelImportPage.java 2023-04-14 07:03:55 UTC (rev 1472) +++ trunk/jtrac/src/main/java/info/jtrac/wicket/ExcelImportPage.java 2023-04-15 10:51:10 UTC (rev 1473) @@ -22,11 +22,13 @@ import info.jtrac.domain.ExcelFile.Cell; import info.jtrac.domain.ExcelFile.Column; import info.jtrac.domain.Space; + import java.io.InputStream; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; + import org.apache.wicket.behavior.SimpleAttributeModifier; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Check; @@ -43,10 +45,15 @@ import org.apache.wicket.model.AbstractReadOnlyModel; import org.apache.wicket.model.PropertyModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * excel import and cleanup */ -public class ExcelImportPage extends BasePage { +public class ExcelImportPage extends BasePage { + + private static final Logger logger = LoggerFactory.getLogger(ExcelImportPage.class); private ExcelFile excelFile; private int action; @@ -77,12 +84,13 @@ try { is = fileUploadField.getFileUpload().getInputStream(); excelFile = new ExcelFile(is); - } catch(Exception e) { + } catch (Exception ex) { + ex.printStackTrace(); error(localize("excel_upload.error.invalidFile")); return; } } - + @Override public boolean isVisible() { return excelFile == null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |