This commit is contained in:
Ralph Soika 2022-01-27 23:38:37 +01:00
parent ed87041611
commit 7369c31f79

View file

@ -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;
}
* </pre>
* <p>
* Der Adapter erweitert den POIAdapter somit können felder aktualisiert werden:
* Der Adapter erweitert den POIAdapter somit können felder aktualisiert werden
* (siehe POIFineReplaceAdapter).
*
* <pre>
* {@code
* <poi-update name="findreplace">
<find>F4</find>
<replace><itemvalue>numsequencenumber</itemvalue></replace>
<type>text</type>
</poi-update>
}
* </pre>
* <p>
* Der Adapter copiert die Rechnungsdaten in neue Zeilen, welche ab Zeilnenummer
* 16 eingefügt werden.
* <p>
* Abschliessend wird die Zelle 'TOTAL' noch aktualisiert.
*
* @version 1.0
* @author rsoika
@ -121,7 +118,8 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter {
* <p>
* The method copies the Row A16 as a reference row
* <p>
* 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.