diff --git a/main/src/com/google/refine/importers/ExcelImporter.java b/main/src/com/google/refine/importers/ExcelImporter.java index 5838d7a87..2cd9cfbd2 100644 --- a/main/src/com/google/refine/importers/ExcelImporter.java +++ b/main/src/com/google/refine/importers/ExcelImporter.java @@ -44,6 +44,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.poi.POIXMLDocument; import org.apache.poi.POIXMLException; import org.apache.poi.common.usermodel.Hyperlink; @@ -54,6 +55,7 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,9 +85,9 @@ public class ExcelImporter extends TabularImportingParserBase { JSONArray sheetRecords = new JSONArray(); JSONUtilities.safePut(options, "sheetRecords", sheetRecords); try { - if (fileRecords.size() > 0) { - JSONObject firstFileRecord = fileRecords.get(0); - File file = ImportingUtilities.getFile(job, firstFileRecord); + for (int index = 0;index < fileRecords.size();index++) { + JSONObject fileRecord = fileRecords.get(index); + File file = ImportingUtilities.getFile(job, fileRecord); InputStream is = new FileInputStream(file); if (!is.markSupported()) { @@ -98,19 +100,18 @@ public class ExcelImporter extends TabularImportingParserBase { new HSSFWorkbook(new POIFSFileSystem(is)); int sheetCount = wb.getNumberOfSheets(); - boolean hasData = false; for (int i = 0; i < sheetCount; i++) { Sheet sheet = wb.getSheetAt(i); int rows = sheet.getLastRowNum() - sheet.getFirstRowNum() + 1; JSONObject sheetRecord = new JSONObject(); - JSONUtilities.safePut(sheetRecord, "name", sheet.getSheetName()); + JSONUtilities.safePut(sheetRecord, "name", file.getName() + "#" + sheet.getSheetName()); + JSONUtilities.safePut(sheetRecord, "fileNameAndSheetIndex", file.getName() + "#" + i); JSONUtilities.safePut(sheetRecord, "rows", rows); - if (hasData) { - JSONUtilities.safePut(sheetRecord, "selected", false); - } else if (rows > 1) { + if (rows > 1) { JSONUtilities.safePut(sheetRecord, "selected", true); - hasData = true; + } else { + JSONUtilities.safePut(sheetRecord, "selected", false); } JSONUtilities.append(sheetRecords, sheetRecord); } @@ -181,9 +182,22 @@ public class ExcelImporter extends TabularImportingParserBase { return; } - int[] sheets = JSONUtilities.getIntArray(options, "sheets"); - for (int sheetIndex : sheets) { - final Sheet sheet = wb.getSheetAt(sheetIndex); + JSONArray sheets = JSONUtilities.getArray(options, "sheets"); + + for(int i=0;i tables = odfDoc.getTableList(); - int sheetCount = tables.size(); - - boolean hasData = false; - for (int i = 0; i < sheetCount; i++) { - OdfTable sheet = tables.get(i); - int rows = sheet.getRowCount(); - - JSONObject sheetRecord = new JSONObject(); - JSONUtilities.safePut(sheetRecord, "name", sheet.getTableName()); - JSONUtilities.safePut(sheetRecord, "rows", rows); - if (hasData) { - JSONUtilities.safePut(sheetRecord, "selected", false); - } else if (rows > 0) { - JSONUtilities.safePut(sheetRecord, "selected", true); - hasData = true; + for (int index = 0;index < fileRecords.size();index++) { + JSONObject fileRecord = fileRecords.get(index); + File file = ImportingUtilities.getFile(job, fileRecord); + InputStream is = new FileInputStream(file); + odfDoc = OdfDocument.loadDocument(is); + List tables = odfDoc.getTableList(); + int sheetCount = tables.size(); + + for (int i = 0; i < sheetCount; i++) { + OdfTable sheet = tables.get(i); + int rows = sheet.getRowCount(); + + JSONObject sheetRecord = new JSONObject(); + JSONUtilities.safePut(sheetRecord, "name", file.getName() + "#" + sheet.getTableName()); + JSONUtilities.safePut(sheetRecord, "fileNameAndSheetIndex", file.getName() + "#" + i); + JSONUtilities.safePut(sheetRecord, "rows", rows); + if (rows > 0) { + JSONUtilities.safePut(sheetRecord, "selected", true); + } else { + JSONUtilities.safePut(sheetRecord, "selected", false); + } + JSONUtilities.append(sheetRecords, sheetRecord); } - JSONUtilities.append(sheetRecords, sheetRecord); } } catch (FileNotFoundException e) { logger.info("File not found",e); @@ -139,9 +142,21 @@ public class OdsImporter extends TabularImportingParserBase { List tables = odfDoc.getTableList(); - int[] sheets = JSONUtilities.getIntArray(options, "sheets"); - for (int sheetIndex : sheets) { - final OdfTable table = tables.get(sheetIndex); + JSONArray sheets = JSONUtilities.getArray(options, "sheets"); + for(int i=0;i