Package org.imixs.workflow.poi
Class POIFindReplaceAdapter
java.lang.Object
org.imixs.workflow.poi.POIFindReplaceAdapter
- All Implemented Interfaces:
org.imixs.workflow.Adapter,org.imixs.workflow.SignalAdapter
This POIFindReplaceAdapter can be used to find and replace text fragements in
a MS Word (docx) or MS Excel (xlsx) document.
The adapter can be configured by the event workflow result:
<poi-update name=
"filename">PLA Membership Agreement-<itemvalue>numsequencenumber</itemvalue>.docx</poi-update>
<poi-update name="findreplace">
<find>[company.name]</find>
<replace><itemvalue>company.name</itemvalue></replace>
</poi-update>
<poi-update name="findreplace">
<find>[company.country]</find>
<replace><itemvalue>company.country</itemvalue></replace>
</poi-update>
<poi-update name="findreplace">
<find>[contract.startdate]</find>
<replace><itemvalue format=
"EEE, MMM d, yyyy">contract.start</itemvalue></replace>
</poi-update>
For Excel you can replace cell content:
<poi-update name="findreplace">
<find>F4</find>
<replace><itemvalue>numsequencenumber</itemvalue></replace>
<type>text</type>
</poi-update>
Another option for Excel sheets is a typed item value. In this case the tag 'itemname' defindes the item and 'type' defines the type which will be set into the excel sheet
<poi-update name="findreplace">
<find>F4</find>
<itemname>invoice.date</itemname>
</poi-update>
- Version:
- 1.0
- Author:
- rsoika
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidevalXSSFSheet(org.apache.poi.xssf.usermodel.XSSFWorkbook doc, org.apache.poi.xssf.usermodel.XSSFSheet sheet, String cell) Evaluates a given list of cells in a given XSWorkbookorg.imixs.workflow.ItemCollectionexecute(org.imixs.workflow.ItemCollection document, org.imixs.workflow.ItemCollection event) This method computes the findreplace configuration and updates an attachments form type .docxstatic org.apache.poi.xssf.usermodel.XSSFCellgetCellByRef(org.apache.poi.xssf.usermodel.XSSFWorkbook doc, org.apache.poi.xssf.usermodel.XSSFSheet sheet, String cellReference) Returns a Cell by name or an optional absolute cell postionvoidprocessPOIUpdate(org.imixs.workflow.ItemCollection workitem, org.imixs.workflow.ItemCollection event, String targetName) This helper method processes all poi-update instructions for a given file attachment (.docx | .xlsx)voidreplaceXSSFSheetItemValue(org.apache.poi.xssf.usermodel.XSSFWorkbook doc, org.apache.poi.xssf.usermodel.XSSFSheet sheet, String find, Object itemValue) Helper method replaces a given cell of a XSSFSheet with a typed item valuevoidreplaceXWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument doc, String find, String replace) Helper method replaces a given text in a XWPFDocumentvoidupdateFileData(org.imixs.workflow.FileData fileData, org.imixs.workflow.ItemCollection document, List<String> replaceDevList, String eval) This helper method updates the content of a given FileData object with a replaceDevListvoidupdateXSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook workbook, org.imixs.workflow.ItemCollection workitem, List<String> replaceDevList) This method updates the XSSFWorkbook document.voidupdateXWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument document, org.imixs.workflow.ItemCollection workitem, List<String> replaceDevList) This method updates the XWPFDocument document.
-
Field Details
-
DOCUMENT_ERROR
- See Also:
-
CONFIG_ERROR
- See Also:
-
-
Constructor Details
-
POIFindReplaceAdapter
public POIFindReplaceAdapter()
-
-
Method Details
-
execute
public org.imixs.workflow.ItemCollection execute(org.imixs.workflow.ItemCollection document, org.imixs.workflow.ItemCollection event) throws org.imixs.workflow.exceptions.AdapterException, org.imixs.workflow.exceptions.PluginException This method computes the findreplace configuration and updates an attachments form type .docx- Specified by:
executein interfaceorg.imixs.workflow.Adapter- Throws:
org.imixs.workflow.exceptions.PluginExceptionorg.imixs.workflow.exceptions.AdapterException
-
processPOIUpdate
public void processPOIUpdate(org.imixs.workflow.ItemCollection workitem, org.imixs.workflow.ItemCollection event, String targetName) throws org.imixs.workflow.exceptions.PluginException This helper method processes all poi-update instructions for a given file attachment (.docx | .xlsx)- Parameters:
workitem-event-targetName-- Throws:
org.imixs.workflow.exceptions.PluginException
-
updateFileData
public void updateFileData(org.imixs.workflow.FileData fileData, org.imixs.workflow.ItemCollection document, List<String> replaceDevList, String eval) throws IOException, org.imixs.workflow.exceptions.PluginException This helper method updates the content of a given FileData object with a replaceDevListThe method verifies if the content of the file need to be loaded from the snapshot
- Parameters:
fileData- - the fileData object containing the text or calc filereplaceDevList- - list of text markers or cell positions to be replacedeval- - optional list of cell positions to be evaluated after update (this is for XSSFWorkbooks only)- Throws:
IOExceptionorg.imixs.workflow.exceptions.PluginException
-
updateXWPFDocument
public void updateXWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument document, org.imixs.workflow.ItemCollection workitem, List<String> replaceDevList) throws org.imixs.workflow.exceptions.PluginException This method updates the XWPFDocument document. The method can be overwritten by subclasses to add additional logic- Parameters:
doc-workitem-replaceDevList-- Throws:
org.imixs.workflow.exceptions.PluginException
-
updateXSSFWorkbook
public void updateXSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook workbook, org.imixs.workflow.ItemCollection workitem, List<String> replaceDevList) throws org.imixs.workflow.exceptions.PluginException This method updates the XSSFWorkbook document. The method can be overwritten by subclasses to add additional logic- Parameters:
workbook-workitem-replaceDevList-- Throws:
org.imixs.workflow.exceptions.PluginException
-
replaceXSSFSheetItemValue
public void replaceXSSFSheetItemValue(org.apache.poi.xssf.usermodel.XSSFWorkbook doc, org.apache.poi.xssf.usermodel.XSSFSheet sheet, String find, Object itemValue) throws org.imixs.workflow.exceptions.PluginException Helper method replaces a given cell of a XSSFSheet with a typed item value- Throws:
org.imixs.workflow.exceptions.PluginException
-
getCellByRef
public static org.apache.poi.xssf.usermodel.XSSFCell getCellByRef(org.apache.poi.xssf.usermodel.XSSFWorkbook doc, org.apache.poi.xssf.usermodel.XSSFSheet sheet, String cellReference) Returns a Cell by name or an optional absolute cell postionExamples for refs are 'A1', 'AB3', 'MyCell' where 'MyCell' is a named cell.
-
evalXSSFSheet
public void evalXSSFSheet(org.apache.poi.xssf.usermodel.XSSFWorkbook doc, org.apache.poi.xssf.usermodel.XSSFSheet sheet, String cell) throws org.imixs.workflow.exceptions.PluginException Evaluates a given list of cells in a given XSWorkbook- Parameters:
doc-sheet-cell-- Throws:
org.imixs.workflow.exceptions.PluginException
-
replaceXWPFDocument
public void replaceXWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument doc, String find, String replace) Helper method replaces a given text in a XWPFDocument
-