diff --git a/lib/SparseBitSet-1.2.jar b/lib/SparseBitSet-1.2.jar new file mode 100644 index 0000000..bdb6771 Binary files /dev/null and b/lib/SparseBitSet-1.2.jar differ diff --git a/lib/commons-codec-1.15.jar b/lib/commons-codec-1.15.jar new file mode 100644 index 0000000..f14985a Binary files /dev/null and b/lib/commons-codec-1.15.jar differ diff --git a/lib/commons-collections4-4.4.jar b/lib/commons-collections4-4.4.jar new file mode 100644 index 0000000..da06c3e Binary files /dev/null and b/lib/commons-collections4-4.4.jar differ diff --git a/lib/commons-compress-1.21.jar b/lib/commons-compress-1.21.jar new file mode 100644 index 0000000..4892334 Binary files /dev/null and b/lib/commons-compress-1.21.jar differ diff --git a/lib/commons-io-2.11.0.jar b/lib/commons-io-2.11.0.jar new file mode 100644 index 0000000..be507d9 Binary files /dev/null and b/lib/commons-io-2.11.0.jar differ diff --git a/lib/commons-logging-1.2.jar b/lib/commons-logging-1.2.jar new file mode 100644 index 0000000..93a3b9f Binary files /dev/null and b/lib/commons-logging-1.2.jar differ diff --git a/lib/commons-math3-3.6.1.jar b/lib/commons-math3-3.6.1.jar new file mode 100644 index 0000000..0ff582c Binary files /dev/null and b/lib/commons-math3-3.6.1.jar differ diff --git a/lib/curvesapi-1.07.jar b/lib/curvesapi-1.07.jar new file mode 100644 index 0000000..2b05714 Binary files /dev/null and b/lib/curvesapi-1.07.jar differ diff --git a/lib/jakarta.activation-2.0.1.jar b/lib/jakarta.activation-2.0.1.jar new file mode 100644 index 0000000..521c7c4 Binary files /dev/null and b/lib/jakarta.activation-2.0.1.jar differ diff --git a/lib/jakarta.xml.bind-api-3.0.1.jar b/lib/jakarta.xml.bind-api-3.0.1.jar new file mode 100644 index 0000000..f890cba Binary files /dev/null and b/lib/jakarta.xml.bind-api-3.0.1.jar differ diff --git a/lib/jxl.jar b/lib/jxl.jar deleted file mode 100644 index 4a1fc64..0000000 Binary files a/lib/jxl.jar and /dev/null differ diff --git a/lib/log4j-api-2.18.0.jar b/lib/log4j-api-2.18.0.jar new file mode 100644 index 0000000..b4e933f Binary files /dev/null and b/lib/log4j-api-2.18.0.jar differ diff --git a/lib/poi-5.2.3.jar b/lib/poi-5.2.3.jar new file mode 100644 index 0000000..22b19a3 Binary files /dev/null and b/lib/poi-5.2.3.jar differ diff --git a/lib/poi-ooxml-5.2.3.jar b/lib/poi-ooxml-5.2.3.jar new file mode 100644 index 0000000..2daf4b0 Binary files /dev/null and b/lib/poi-ooxml-5.2.3.jar differ diff --git a/lib/poi-ooxml-lite-5.2.3.jar b/lib/poi-ooxml-lite-5.2.3.jar new file mode 100644 index 0000000..84412a2 Binary files /dev/null and b/lib/poi-ooxml-lite-5.2.3.jar differ diff --git a/lib/slf4j-api-1.7.36.jar b/lib/slf4j-api-1.7.36.jar new file mode 100644 index 0000000..7d3ce68 Binary files /dev/null and b/lib/slf4j-api-1.7.36.jar differ diff --git a/lib/xmlbeans-5.1.1.jar b/lib/xmlbeans-5.1.1.jar new file mode 100644 index 0000000..b828ad3 Binary files /dev/null and b/lib/xmlbeans-5.1.1.jar differ diff --git a/src/pattypan/panes/CreateFilePane.java b/src/pattypan/panes/CreateFilePane.java index 2dd9759..36ba0b2 100644 --- a/src/pattypan/panes/CreateFilePane.java +++ b/src/pattypan/panes/CreateFilePane.java @@ -30,7 +30,9 @@ import com.drew.metadata.exif.ExifSubIFDDirectory; import java.awt.Desktop; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; @@ -40,13 +42,12 @@ import javafx.scene.text.TextAlignment; import javafx.scene.text.TextFlow; import javafx.stage.Stage; -import jxl.CellView; -import jxl.Workbook; -import jxl.read.biff.BiffException; -import jxl.write.Label; -import jxl.write.WritableSheet; -import jxl.write.WritableWorkbook; -import jxl.write.WriteException; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.xssf.streaming.SXSSFSheet; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; import pattypan.Session; import pattypan.Settings; import pattypan.Template; @@ -103,7 +104,7 @@ private WikiPane setActions() { createSpreadsheet(); showOpenFileButton(); Settings.saveProperties(); - } catch (IOException | BiffException | WriteException ex) { + } catch (IOException ex) { addElement(new WikiLabel("create-file-error")); Session.LOGGER.log(Level.WARNING, "Error occurred during creation of spreadsheet file: {0}", @@ -135,20 +136,24 @@ private void showOpenFileButton() { nextButton.setVisible(true); } - private void autoSizeColumn(int column, WritableSheet sheet) { - CellView cell = sheet.getColumnView(column); - cell.setAutosize(true); - sheet.setColumnView(column, cell); + private void autoSizeColumn(int column, Sheet sheet) { + sheet.autoSizeColumn(column); } - private void createSpreadsheet() throws IOException, BiffException, WriteException { - File f = new File(Session.DIRECTORY, fileName.getText() + ".xls"); - WritableWorkbook workbook = Workbook.createWorkbook(f); + private void createSpreadsheet() throws IOException { + File f = new File(Session.DIRECTORY, fileName.getText() + ".xlsx"); + // Autosize appears to only be supported for OOXML workbooks, so making this specific instead of generic + // boolean xml = true; + // final Workbook workbook = xml ? new SXSSFWorkbook() : new HSSFWorkbook(); + final SXSSFWorkbook workbook = new SXSSFWorkbook(); createDataSheet(workbook); createTemplateSheet(workbook); - workbook.write(); + try (OutputStream os = new FileOutputStream(f)){ + workbook.write(os); + os.flush(); + } workbook.close(); Session.FILE = f; } @@ -156,22 +161,24 @@ private void createSpreadsheet() throws IOException, BiffException, WriteExcepti /** * * @param workbook - * @throws WriteException */ - private void createDataSheet(WritableWorkbook workbook) throws WriteException { - WritableSheet sheet = workbook.createSheet("Data", 0); + private void createDataSheet(SXSSFWorkbook workbook) { + SXSSFSheet sheet = workbook.createSheet("Data"); // first row (header) + Row header = sheet.createRow(0); int column = 0; for (String variable : Session.VARIABLES) { - sheet.addCell(new Label(column++, 0, variable)); + Cell c = header.createCell(column++); + c.setCellValue(variable); } // next rows with path and name int row = 1; for (File file : Session.FILES) { - sheet.addCell(new Label(0, row, file.getAbsolutePath())); - sheet.addCell(new Label(1, row++, Util.getNameFromFilename(file.getName()))); + Row cells = sheet.createRow(row++); + cells.createCell(0, CellType.STRING).setCellValue(file.getAbsolutePath()); + cells.createCell(1, CellType.STRING).setCellValue(Util.getNameFromFilename(file.getName())); } if (Session.METHOD.equals("template")) { @@ -181,7 +188,8 @@ private void createDataSheet(WritableWorkbook workbook) throws WriteException { column = Session.VARIABLES.indexOf(tf.name); row = 1; for (File file : Session.FILES) { - sheet.addCell(new Label(column, row++, tf.value)); + // TODO: We may not have the cells created yet here. Let's see what happens + sheet.getRow(row++).getCell(column).setCellValue(tf.value); } } } @@ -191,11 +199,13 @@ private void createDataSheet(WritableWorkbook workbook) throws WriteException { if (column >= 0 && !Settings.getSetting("exifDate").isEmpty()) { row = 1; for (File file : Session.FILES) { - sheet.addCell(new Label(column, row++, getExifDate(file))); + // TODO: We may not have the cells created yet here. Let's see what happens + sheet.getRow(row++).getCell(column).setCellValue(getExifDate(file)); } } - for (int num = 0; num < sheet.getColumns(); num++) { + sheet.trackAllColumnsForAutoSizing(); + for (int num = 0; num < sheet.getRow(0).getLastCellNum(); num++) { autoSizeColumn(num, sheet); } } @@ -203,20 +213,22 @@ private void createDataSheet(WritableWorkbook workbook) throws WriteException { /** * * @param workbook - * @throws WriteException */ - private void createTemplateSheet(WritableWorkbook workbook) throws WriteException { - WritableSheet templateSheet = workbook.createSheet("Template", 1); - templateSheet.addCell(new Label(0, 0, "'" + Session.WIKICODE)); - // ^^ + private void createTemplateSheet(SXSSFWorkbook workbook) { + SXSSFSheet templateSheet = workbook.createSheet("Template"); + Row row = templateSheet.createRow(0); + Cell cell = row.createCell(0); + cell.setCellValue("'" + Session.WIKICODE); + // ^^ // leading apostrophe prevents turning wikitext into formula in Excel + templateSheet.trackAllColumnsForAutoSizing(); autoSizeColumn(0, templateSheet); } /** * - * @param filePath + * @param file * @return */ private String getExifDate(File file) { diff --git a/src/pattypan/panes/LoadPane.java b/src/pattypan/panes/LoadPane.java index cbf9b70..3c77ff7 100644 --- a/src/pattypan/panes/LoadPane.java +++ b/src/pattypan/panes/LoadPane.java @@ -23,18 +23,22 @@ */ package pattypan.panes; -import freemarker.core.InvalidReferenceException; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; import freemarker.template.TemplateExceptionHandler; +import java.io.BufferedInputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.StringReader; import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.TimeZone; @@ -43,13 +47,17 @@ import javafx.scene.layout.VBox; import javafx.stage.FileChooser; import javafx.stage.Stage; -import jxl.Cell; -import jxl.CellType; -import jxl.DateCell; -import jxl.Sheet; -import jxl.Workbook; -import jxl.WorkbookSettings; -import jxl.read.biff.BiffException; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.FileMagic; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + import pattypan.Session; import pattypan.Settings; import pattypan.UploadElement; @@ -236,10 +244,9 @@ private void addInfo(String text, String cssClass) { * @throws Exception when essential headers are missing */ private void readHeaders(Sheet sheet) throws Exception { - int columns = sheet.getColumns(); - ArrayList cols = new ArrayList<>(); - for (int col = 0; col < columns; col++) { - cols.add(sheet.getCell(col, 0).getContents()); + List cols = new ArrayList<>(); + for (Cell c : sheet.getRow(0)) { + cols.add(c.getStringCellValue()); } if (cols.isEmpty()) { @@ -264,18 +271,22 @@ private String getCellValue(Sheet sheet, int column, int row) { formatDate.setTimeZone(TimeZone.getTimeZone("UTC")); formatDateHour.setTimeZone(TimeZone.getTimeZone("UTC")); - Cell valueCell = sheet.getCell(column, row); - String value; + Cell valueCell = sheet.getRow(row).getCell(column); + String value = null; - if (valueCell.getType() == CellType.DATE) { - DateCell dateCell = (DateCell) valueCell; + if (valueCell != null) { + if (valueCell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(valueCell)) { + Date date = DateUtil.getJavaDate(valueCell.getNumericCellValue()); + // FIXME: Restore more sophisticated date handling + value = formatDate.format(date); //@TODO: more elegant hour detection - value = dateCell.getContents().contains(":") - ? formatDateHour.format(dateCell.getDate()) - : formatDate.format(dateCell.getDate()); - } else { - value = sheet.getCell(column, row).getContents().trim(); - } +// value = dateCell.getContents().contains(":") +// ? formatDateHour.format(dateCell.getDate()) +// : formatDate.format(dateCell.getDate()); + } else { + value = valueCell.getStringCellValue().trim(); + } + } return value; } @@ -294,9 +305,7 @@ private void loadSpreadsheet(File file) { readSpreadSheet(); } catch (IOException ex) { addInfo("File error: there are problems opening file. It may be corrupted."); - } catch (BiffException ex) { - addInfo("File error: file needs to be saved in binnary format. Please save your file in \"Excel 97-2003 format\""); - } catch (InvalidReferenceException ex) { + } catch (TemplateException ex) { addInfo("File error: variables mismatch. Column headers variables must match wikitemplate variables."); } catch (Exception ex) { addInfo(ex.getMessage()); @@ -312,14 +321,27 @@ private void loadSpreadsheet(File file) { */ private ArrayList> readDescriptions(Sheet sheet) { ArrayList> descriptions = new ArrayList<>(); - int rows = sheet.getRows(); - int columns = sheet.getColumns(); + int rows = sheet.getLastRowNum(); + int columns = sheet.getRow(0).getLastCellNum(); + // Collect header labels + String[] labels = new String[columns]; + Row cells = sheet.getRow(0); + for (int col = 0; col < columns; col++) { + Cell cell = cells.getCell(col); + if (cell != null) { + String value = cell.getStringCellValue(); + labels[col] = value; + } else { + labels[col] = null; + } + } for (int row = 1; row < rows; row++) { Map description = new HashMap(); + cells = sheet.getRow(row); for (int column = 0; column < columns; column++) { - String label = sheet.getCell(column, 0).getContents().trim(); - if (label.isEmpty()) { + String label = labels[column]; + if (label == null || label.isEmpty()) { continue; } String value = getCellValue(sheet, column, row); @@ -333,17 +355,19 @@ private ArrayList> readDescriptions(Sheet sheet) { /** * Reads spreadsheet stored in Session.FILE. */ - private void readSpreadSheet() throws BiffException, IOException, Exception { + private void readSpreadSheet() throws IOException, TemplateException, Exception { infoContainer.getChildren().clear(); Session.SCENES.remove("CheckPane"); - WorkbookSettings ws = new WorkbookSettings(); - ws.setEncoding("Cp1252"); + InputStream inputStream = new BufferedInputStream(new FileInputStream(Session.FILE)); + Workbook wb = FileMagic.valueOf(inputStream) == FileMagic.OOXML ? new XSSFWorkbook(inputStream) + : new HSSFWorkbook(new POIFSFileSystem(inputStream)); + +// ws.setEncoding("Cp1252"); // FIXME try { - Workbook workbook = Workbook.getWorkbook(Session.FILE, ws); - Sheet dataSheet = workbook.getSheet(0); - Sheet templateSheet = workbook.getSheet(1); + Sheet dataSheet = wb.getSheetAt(0); + Sheet templateSheet = wb.getSheetAt(1); readHeaders(dataSheet); addFilesToUpload(readDescriptions(dataSheet), readTemplate(templateSheet)); } catch (IndexOutOfBoundsException ex) { @@ -362,7 +386,7 @@ private void readSpreadSheet() throws BiffException, IOException, Exception { */ private Template readTemplate(Sheet sheet) throws Exception { try { - String text = sheet.getCell(0, 0).getContents(); + String text = sheet.getRow(0).getCell(0).getStringCellValue(); return new Template("wikitemplate", new StringReader(text), cfg); } catch (ArrayIndexOutOfBoundsException ex) { throw new Exception("Error: template in spreadsheet looks empty. Check if wikitemplate is present in second tab of your spreadsheet (first row and first column).");