EN · DE · RU · FR · ES

#387: ExcelImport.java

projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java Java class, projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java 353 lines · 203 code · 126 comments · 24 blank
Purpose: Source file: projectforge/business/excel/ExcelImport.java. ExcelImport.java is part of the ProjectForge open-source project management application.

Source (first 100 lines)

/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
//         www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
// This community edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation; version 3 of the License.
//
// This community edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, see http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////

package org.projectforge.business.excel;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Convert a given Excel-Sheet into an object-Array.
 *
 * @param <T> baseclass for each row
 * @author Wolfgang Jung (w.jung@micromata.de)
 */
public class ExcelImport<T>
{
  /**
   * The logger
   */
  private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ExcelImport.class);

  /**
   * the workbook containing the values.
   */
  private final HSSFWorkbook work;

  /**
   * a optional map for mapping column-names to property-names.
   */
  private Map<String, String> columnToPropertyMap;

  /**
   * the worksheet from which the values should be read.
   */
  private int activeSheet = 0;

  /**
   * the zero-based index with the column-names
   */
  private int columnNameRow = 0;

  /**
   * the zero-based index of the first row containing values
   */
  private int startAtRow = 1;

  /**
   * the classfactory for creating the objects.
   */
  private ClassFactory<T> clazzFactory;

  /**
   * Opens a given Excel-document. The stream is always closed.
   *
   * @param xlsStream the stream of the Excel-document.
   * @throws IOException if the document is not readable
   */
  public ExcelImport(final InputStream xlsStream) throws IOException
  {
    // Closed by HSSFWorkbook
    work = new HSSFWorkbook(xlsStream);
  }

  /**
   * get a reference to the workbook for special features.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.
c06db1dab Nearly all jars updated (code changes required).

868d6abb7

2025 -> 2026
868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
index e3598d29b..dbb1c0d48 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

63081666f

Source file headers: 2024-> 2025.
63081666f620fb87315f01b817e560e0b2f6a33a
diff --git a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
index 8a1c8f2d9..e3598d29b 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

b6092df09

Copyright 2023 -> 2024
b6092df0927c4a3b161e888445f31dcab57493f2
diff --git a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
index 3189f78de..8a1c8f2d9 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

ab45d51fa

Copyright 2001-2022 -> 2001-2023.
ab45d51fa419ede6174b31d69987f96d4b841ff9
diff --git a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
index 41f18bd64..3189f78de 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2022 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

c06db1dab

Nearly all jars updated (code changes required).
c06db1dab7a4f114f726cfa4ebcf3716bb1d321f
diff --git a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
index a0c4b4380..41f18bd64 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/excel/ExcelImport.java
@@ -325,7 +325,7 @@ public class ExcelImport<T>
     if (cell == null) {
       return null;
     }
-    switch (cell.getCellTypeEnum()) {
+    switch (cell.getCellType()) {
       case NUMERIC:
         log.debug("using numeric");
         if (Date.class.isAssignableFrom(destClazz)) {