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 javax.inject.Inject;
import org.apache.poi.ss.usermodel.CellCopyPolicy;
import org.apache.poi.ss.util.CellReference; 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.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -37,17 +37,14 @@ import org.imixs.workflow.poi.POIFindReplaceAdapter;
} }
* </pre> * </pre>
* <p> * <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> * <p>
* {@code * Der Adapter copiert die Rechnungsdaten in neue Zeilen, welche ab Zeilnenummer
* <poi-update name="findreplace"> * 16 eingefügt werden.
<find>F4</find> * <p>
<replace><itemvalue>numsequencenumber</itemvalue></replace> * Abschliessend wird die Zelle 'TOTAL' noch aktualisiert.
<type>text</type>
</poi-update>
}
* </pre>
* *
* @version 1.0 * @version 1.0
* @author rsoika * @author rsoika
@ -121,7 +118,8 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter {
* <p> * <p>
* The method copies the Row A16 as a reference row * The method copies the Row A16 as a reference row
* <p> * <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 * @throws PluginException
*/ */
@ -135,8 +133,6 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter {
XSSFWorkbook doc = new XSSFWorkbook(imputStream); XSSFWorkbook doc = new XSSFWorkbook(imputStream);
// NOTE: we only take the first sheet ! // NOTE: we only take the first sheet !
XSSFSheet sheet = doc.getSheetAt(0); XSSFSheet sheet = doc.getSheetAt(0);
XSSFCell cell = null;
CellReference cr = new CellReference("A16"); CellReference cr = new CellReference("A16");
XSSFRow referenceRow = sheet.getRow(cr.getRow()); XSSFRow referenceRow = sheet.getRow(cr.getRow());
int referenceRowPos = 16; int referenceRowPos = 16;
@ -149,28 +145,18 @@ public class ZahlungsavisExportAdapter extends POIFindReplaceAdapter {
ItemCollection invoice = documentService.load(invoiceID); ItemCollection invoice = documentService.load(invoiceID);
// now create a new line.. // now create a new line..
XSSFRow row = sheet.createRow(rowPos); XSSFRow row = sheet.createRow(rowPos);
// copy cells row.copyRowFrom(referenceRow, new CellCopyPolicy());
cell= copyCell( referenceRow, row, 0); // insert values
cell.setCellValue(invoice.getItemValueString("numsequecenumber")); row.getCell(0).setCellValue(invoice.getItemValueString("numsequencenumber"));
row.getCell(1).setCellValue(invoice.getItemValueDate("invoice.date"));
cell= copyCell( referenceRow, row, 1); row.getCell(2).setCellValue(invoice.getItemValueString("invoice.number"));
cell.setCellValue(invoice.getItemValueDate("invoice.date")); row.getCell(3).setCellValue(invoice.getItemValueDate("invoice.due.date"));
row.getCell(4).setCellValue(0.00);
cell= copyCell( referenceRow, row, 2); row.getCell(5).setCellValue(invoice.getItemValueDouble("invoice.total"));
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"));
rowPos++; rowPos++;
} }
// delete reference cell // delete reference row 16
sheet.shiftRows(referenceRowPos, lastRow + invoiceIDs.size(), -1, true, true); sheet.shiftRows(referenceRowPos, lastRow + invoiceIDs.size(), -1, true, true);
// finally update the total formula... // 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 * This method loads a text-block for a specified ref and appends the named
* fileData object of this document. * fileData object of this document.