From 7369c31f795690815f27aef079102056133b99ac Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Thu, 27 Jan 2022 23:38:37 +0100 Subject: [PATCH] update --- .../ZahlungsavisExportAdapter.java | 68 ++++++------------- 1 file changed, 19 insertions(+), 49 deletions(-) diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisExportAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisExportAdapter.java index 218af2c..7cec3d2 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisExportAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/ZahlungsavisExportAdapter.java @@ -10,8 +10,8 @@ import java.util.logging.Logger; import javax.inject.Inject; +import org.apache.poi.ss.usermodel.CellCopyPolicy; import org.apache.poi.ss.util.CellReference; -import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -37,17 +37,14 @@ import org.imixs.workflow.poi.POIFindReplaceAdapter; } * *

- * Der Adapter erweitert den POIAdapter somit können felder aktualisiert werden: + * Der Adapter erweitert den POIAdapter somit können felder aktualisiert werden + * (siehe POIFineReplaceAdapter). * - *

- * {@code
- * 
-       F4
-       numsequencenumber
-       text
-   
-   }
- * 
+ *

+ * Der Adapter copiert die Rechnungsdaten in neue Zeilen, welche ab Zeilnenummer + * 16 eingefügt werden. + *

+ * Abschliessend wird die Zelle 'TOTAL' noch aktualisiert. * * @version 1.0 * @author rsoika @@ -121,7 +118,8 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter { *

* The method copies the Row A16 as a reference row *

- * The named cell 'TOTAL' should contain the summary formula + * The named cell 'TOTAL' should contain the summary formula. It will be + * evaluated at the end. * * @throws PluginException */ @@ -135,8 +133,6 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter { XSSFWorkbook doc = new XSSFWorkbook(imputStream); // NOTE: we only take the first sheet ! XSSFSheet sheet = doc.getSheetAt(0); - XSSFCell cell = null; - CellReference cr = new CellReference("A16"); XSSFRow referenceRow = sheet.getRow(cr.getRow()); int referenceRowPos = 16; @@ -149,28 +145,18 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter { ItemCollection invoice = documentService.load(invoiceID); // now create a new line.. XSSFRow row = sheet.createRow(rowPos); - // copy cells - cell= copyCell( referenceRow, row, 0); - cell.setCellValue(invoice.getItemValueString("numsequecenumber")); - - cell= copyCell( referenceRow, row, 1); - cell.setCellValue(invoice.getItemValueDate("invoice.date")); - - cell= copyCell( referenceRow, row, 2); - cell.setCellValue(invoice.getItemValueString("invoice.number")); - - cell= copyCell( referenceRow, row, 3); - cell.setCellValue(invoice.getItemValueDate("invoice.due.date")); - - cell= copyCell( referenceRow, row, 4); - cell.setCellValue(0.00); - - cell= copyCell( referenceRow, row, 5); - cell.setCellValue(invoice.getItemValueDouble("invoice.total")); + row.copyRowFrom(referenceRow, new CellCopyPolicy()); + // insert values + row.getCell(0).setCellValue(invoice.getItemValueString("numsequencenumber")); + row.getCell(1).setCellValue(invoice.getItemValueDate("invoice.date")); + row.getCell(2).setCellValue(invoice.getItemValueString("invoice.number")); + row.getCell(3).setCellValue(invoice.getItemValueDate("invoice.due.date")); + row.getCell(4).setCellValue(0.00); + row.getCell(5).setCellValue(invoice.getItemValueDouble("invoice.total")); rowPos++; } - // delete reference cell + // delete reference row 16 sheet.shiftRows(referenceRowPos, lastRow + invoiceIDs.size(), -1, true, true); // finally update the total formula... @@ -193,22 +179,6 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter { } } - /** - * Helper method to copy a cell (It is heavy how many lines of code are - * necessary to work with Excel and POI - * - * @param row - * @param column - * @return - */ - private XSSFCell copyCell(XSSFRow referenceRow, XSSFRow row, int column) { - XSSFCell cell = row.createCell(column); - XSSFCell refCell = referenceRow.getCell(column); - cell.setCellType(refCell.getCellType()); - cell.setCellStyle(refCell.getCellStyle()); - return cell; - } - /** * This method loads a text-block for a specified ref and appends the named * fileData object of this document.