IS
Hello, community!
I have writen some piece of code for creating, reading and editing *.docx files. If it is usefull for somebody, I will translate Russian comments to English. Most of the funcs are simular to ARIS standard output API's funcs.
Also, there are some additionals, like find and replace in body+headers+footers of the document.
This code is based on docx4j libraries, so for using it you have to add docx4j libraries to the ARIS server/lib category.
You have to change extansion "txt" of attachment to "js" and import it to common files on the server (Attached file is visible for registered users only).
Hope, this is usefull.
There is example report and docx4j libraries.
https://www.dropbox.com/s/dpv1vlgppat8wjo/docx4j-2.8.1.7z
Context.setProperty(Constants.PROPERTY_SHOW_OUTPUT_FILE, true); Context.setProperty(Constants.PROPERTY_SHOW_SUCCESS_MESSAGE, false); //Function checks existance of object function IsDefined(obj) { if (typeof(obj)=="undefined") return false; if ((typeof(obj)=="object")&&(obj==null)) return false; if (obj==undefined) return false; return true; } function main() { //Createing instance of wraping class CWordShell var oWord = new CWordShell(); //Reading template file from common files location as byte array. oData = Context.getFile("Template.docx", Constants.LOCATION_COMMON_FILES); //Creating instance of document in memory //Future file name - Context.getSelectedFile() //Template - oData //oWord.Init(Context.getSelectedFile(), oData); //Creating black document oWord.Init(Context.getSelectedFile()); oWord.OutputLnF("Report header: <ARIS:NAME>", "heading 1"); //Replasing text in headers, footers and main part of document oWord.ReplaceText("<ARIS:NAME>", "Test report"); var aSelectedObjDefs = ArisData.getSelectedObjDefs(); //Creating table example var aColWidths = [10, 90]; oWord.BeginTable(100, aColWidths, "TextLT_NoInd"); //Table haeder oWord.TableRow(); oWord.TableCellF("#", "Header12", "TextLT_NoInd"); oWord.TableCellF("Object name", "Header12", "TextLT_NoInd"); for (var i=0; i<aSelectedObjDefs.length; i++) { oWord.TableRow(); oWord.TableCellF(""+(i+1), "Header12", "TextLT_NoInd"); oWord.TableCellF(aSelectedObjDefs[i].Name(-1), "Header12", "TextLT_NoInd"); } oWord.EndTable(); //Writing memory instance of document to Hard drive into ARIS's output directory. oWord.Close(); //When report is finished, document will be transfered to the client's computer. return; } main();