X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/blobdiff_plain/f9a87300a83456070e649e44c92f6a59e28c3f9e..498f30dc4a1d447ab4e5a8fbff3670b4682eea35:/cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/ExcelUtils.java diff --git a/cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/ExcelUtils.java b/cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/ExcelUtils.java index 140fcb648b..c03f695f39 100644 --- a/cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/ExcelUtils.java +++ b/cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/ExcelUtils.java @@ -10,10 +10,10 @@ package eu.etaxonomy.cdm.common; -import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.net.URI; import java.util.ArrayList; import java.util.HashMap; -import java.io.FileNotFoundException; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFCell; @@ -31,14 +31,25 @@ public class ExcelUtils { private static final Logger logger = Logger.getLogger(ExcelUtils.class); /** Reads all rows of an Excel worksheet */ - public static ArrayList> parseXLS(String fileName) throws FileNotFoundException { + public static ArrayList> parseXLS(URI uri) throws FileNotFoundException { + return parseXLS(uri, null); + } + + + /** Reads all rows of an Excel worksheet */ + public static ArrayList> parseXLS(URI uri, String worksheetName) throws FileNotFoundException { ArrayList> recordList = new ArrayList>(); try { - POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fileName)); + POIFSFileSystem fs = new POIFSFileSystem(UriUtils.getInputStream(uri)); HSSFWorkbook wb = new HSSFWorkbook(fs); - HSSFSheet sheet = wb.getSheetAt(0); + HSSFSheet sheet; + if (worksheetName == null){ + sheet = wb.getSheetAt(0); + }else{ + sheet = wb.getSheet(worksheetName); + } HSSFRow row; HSSFCell cell; @@ -61,7 +72,6 @@ public class ExcelUtils { } } } - HashMap headers = null; ArrayList columns = new ArrayList(); row = sheet.getRow(0); for (int c = 0; c < cols; c++){ @@ -75,12 +85,11 @@ public class ExcelUtils { } for(int r = 1; r < rows; r++) { row = sheet.getRow(r); - headers = new HashMap(); + HashMap headers = new HashMap(); boolean notEmpty = false; - for (int j = 0; j