I will show you a very simple script to update data from Word files. Sometimes you may need update an object atribute (e.g., Description) from a Word document previously generated, this works for me:
Import POI library
var importer = JavaImporter(
Packages.java.io.File,
Packages.java.io.FileInputStream,
Packages.org.apache.poi.hwpf,
Packages.org.apache.poi.hwpf.HWPFDocument,
Packages.org.apache.poi.hwpf.extractor.WordExtractor,
Packages.org.apache.poi.hwpf.usermodel.TableIterator
);
Open Word file
var docFile = new java.io.File([Word Document]);
var fis = new java.io.FileInputStream(docFile);
var doc = new importer.HWPFDocument(fis);
Iterate tables and rows in document
var range = doc.getRange();
var ti = new importer.TableIterator(range);
ArisData.getActiveDatabase().setAutoTouch(false);
//Iterate tables in document
while(ti.hasNext()) {
var table = ti.next();
//Iterate rows in table
for (var rowIdx=0; rowIdx<table.numRows(); rowIdx++) {
var row = table.getRow(rowIdx);
var cell = row.getCell(0);
var sid = cell.getParagraph(0).text();
Search and update the attribute
//Search item in EPC model
bitemisvalid = __toBool(getitembyid(ocurritem, sid));
if (bitemisvalid) {
//Get description attribute
ocurrattr = ocurritem.value.Attribute(Constants.AT_DESC, g_nloc);
if (ocurrattr.IsValid()) {
var svalue = getCellText(row.getCell(1));
changeAutoTouch(ocurritem.value);
//Update attribute value
if (ocurrattr.setValue(svalue) == false) {
...
ArisData.getActiveDatabase().setAutoTouch(true);
Best regards,
Hello!
Just for info.
I'm using ARIS release 7.2.0.554169. When I tryed to use appache POI for *.doc (HWPFDocument or XWPFDocument) I faced issue:
"method <init>()V not found".
I've resolved this by updating POI-*.jar libraries in ARIS server's lib directory. Newest version of POI libraries could be found here.
Hope, this helps smbd.