|
DOORS Project reporting V1.0
|
00001 00002 /* ****************************************** 00003 Function: setRowBorder() 00004 *************************************************/ 00005 void setRowFontNormal () { 00006 clear objArgBlock 00007 put (objArgBlock, "MacroName", "setRowFontNormal") 00008 checkRes (oleMethod (objWord, "Run", objArgBlock)) 00009 } 00010 void setRowBorder() { 00011 clear objArgBlock 00012 put (objArgBlock, "MacroName", "setRowBorder") 00013 checkRes (oleMethod (objWord, "Run", objArgBlock)) 00014 } 00015 00016 void setRowFormatBoldGray () { 00017 clear objArgBlock 00018 put (objArgBlock, "MacroName", "setRowFormatBoldGray") 00019 checkRes (oleMethod (objWord, "Run", objArgBlock)) 00020 } 00021 00022 void setRowFontNormalNextRow () { 00023 clear objArgBlock 00024 put (objArgBlock, "MacroName", "setRowFontNormalNextRow") 00025 checkRes (oleMethod (objWord, "Run", objArgBlock)) 00026 } 00027 void setRowFormatNormal() { 00028 clear objArgBlock 00029 put (objArgBlock, "MacroName", "setRowFormatNormal") 00030 checkRes (oleMethod (objWord, "Run", objArgBlock)) 00031 } 00032 00033 int str2int(string s){ 00034 int r = 0 00035 int l = length(s) 00036 int c 00037 for (i = l - 1; i > -1; i--){ 00038 c = intOf(s[i]) 00039 if (c > 57 or c < 48) return -1 00040 r = r + (c - 48) * intOf((real 10.0) ^ realOf(l - i - 1)) 00041 } 00042 return r 00043 } // 00044 00045 00046 /* ****************************************Excel related functions************************* 00047 00048 ******************************************************************************************/ 00049 00050 00051 string new_col_group( string s1, string s2) 00052 { 00053 string strResult 00054 00055 if (s1 == "") 00056 { 00057 strResult = s2 00058 } 00059 else 00060 { 00061 strResult = s1 "\n" s2 00062 } 00063 00064 return strResult 00065 } // new_col_group 00066 00067 string ExcelAlphaCol(int col) 00068 { 00069 string strResult 00070 00071 if (col < 1) 00072 { 00073 strResult = "A" 00074 } 00075 else if ( col <= 26 ) 00076 { 00077 strResult = charOf( intOf( 'A' ) + col - 1)"" 00078 } 00079 else 00080 { 00081 strResult = ExcelAlphaCol(col/26) ExcelAlphaCol(col%26) 00082 } 00083 return strResult 00084 } // ExcelAlphaCol 00085 00086 00087 string ExcelAddress( int col, int row ) 00088 { 00089 string strResult 00090 00091 strResult = ExcelAlphaCol(col)"" row "" 00092 00093 return strResult 00094 } //ExcelAddress 00095 00096 00097 string ExcelRowAddress( int rowStart, int rowEnd ) { 00098 return "$" rowStart ":" "$" rowEnd "" 00099 } 00100 00101 string ExcelColAddress( int colStart, int colEnd ) { 00102 return "$" ExcelAlphaCol(colStart) ":" "$" ExcelAlphaCol(colEnd) "" 00103 } 00104 /* ************************************************************************** 00105 Function : ExcelAvailable() 00106 description: to check the availability of the excel file 00107 *********************************************************************************/ 00108 bool ExcelAvailable() 00109 { 00110 bool is_available = false 00111 00112 if ( null objExcel) 00113 { 00114 is_available = false 00115 } 00116 else 00117 { 00118 is_available = true 00119 } 00120 00121 return is_available 00122 } 00123 /* ************************************************************************** 00124 Function : ExcelSetVisible() 00125 description: to make the excel file visible only if it exists 00126 *********************************************************************************/ 00127 void ExcelSetVisible( bool bVisible ) 00128 { 00129 if (ExcelAvailable()) 00130 { 00131 olePut( objExcel, "Visible", bVisible ) 00132 } 00133 } // ExcelSetVisible 00134 00135 /* ************************************************************************** 00136 Function : ExcelInit() 00137 description: Initialize the excel application, get the workbook, worksheet and make it active 00138 *********************************************************************************/ 00139 void ExcelInit(bool bVisible) 00140 { 00141 00142 OleAutoArgs objArgBlock = create 00143 OleAutoObj objExcelCell = null 00144 00145 objExcel = oleCreateAutoObject( "Excel.Application" ) 00146 00147 if (null objExcel) { 00148 ack "Unable to communicate with Excel!\nIs it installed?" 00149 } 00150 else 00151 { 00152 ExcelSetVisible( bVisible) 00153 oleGet( objExcel, "Workbooks", objWorkbooks ) 00154 00155 if (null objWorkbooks) { 00156 ack "Unable to get workbooks !" 00157 } 00158 00159 00160 oleMethod( objWorkbooks, "Add" ) 00161 oleGet( objExcel, "ActiveWorkbook", objWorkbook ) 00162 if (null objWorkbook) { 00163 ack "Unable to get workbook !" 00164 } 00165 00166 00167 clear( objArgBlock ) 00168 put( objArgBlock, 1 ) // 1st sheet 00169 oleGet( objWorkbook, "Sheets", objArgBlock, objSheet) 00170 if (null objSheet) { 00171 ack "Unable to get sheet !" 00172 } 00173 oleMethod( objSheet, "Activate" ) 00174 00175 delete objArgBlock 00176 } 00177 } // ExcelInit 00178 00179 00180 OleAutoObj ExcelNewSheet(string sSheetName){ 00181 OleAutoArgs objArgBlock = create 00182 OleAutoObj objWorksheets 00183 oleGet(objWorkbook, "Sheets", objWorksheets) 00184 oleMethod(objWorksheets, "Add") 00185 clear objArgBlock 00186 put (objArgBlock, 1) 00187 oleGet( objWorkbook, "Sheets", objArgBlock, objSheet) 00188 olePut(objSheet, "Name", sSheetName) 00189 delete objArgBlock 00190 return objSheet 00191 } 00192 void ExcelColAutoFit(int colStart, int colEnd ) 00193 { 00194 OleAutoArgs objArgBlock = create 00195 OleAutoObj objExcelCell = null 00196 OleAutoObj objRange = null 00197 OleAutoObj objColumns = null 00198 00199 put( objArgBlock, ExcelColAddress(colStart, colEnd) ) 00200 oleGet( objSheet, "Range", objArgBlock, objRange ) 00201 oleGet( objRange, "Columns", objColumns ) 00202 olePut( objColumns, "AutoFit",true) 00203 } 00204 00205 void ExcelColShrinkToFit(int colStart, int colEnd ) 00206 { 00207 OleAutoArgs objArgBlock = create 00208 OleAutoObj objExcelCell = null 00209 OleAutoObj objRange = null 00210 OleAutoObj objColumns = null 00211 00212 put( objArgBlock, ExcelColAddress(colStart, colEnd) ) 00213 oleGet( objSheet, "Range", objArgBlock, objRange ) 00214 olePut( objRange, "ShrinkToFit",true ) 00215 } 00216 00217 00218 00219 void ExcelSelectCol(int colStart, int colEnd ) 00220 { 00221 OleAutoArgs objArgBlock = create 00222 OleAutoObj objExcelCell = null 00223 OleAutoObj objRange = null 00224 OleAutoObj objColumns = null 00225 00226 put( objArgBlock, ExcelColAddress(colStart, colEnd) ) 00227 oleGet( objSheet, "Range", objArgBlock, objRange ) 00228 oleGet( objRange, "Columns", objColumns ) 00229 //oleMethod( objRange, "Select" ) 00230 //olePut( objRange, "ShrinkToFit",true ) 00231 olePut( objColumns, "AutoFit",true) 00232 //Selection.Columns.AutoFit 00233 } 00234 00235 void ExcelPut( int col, int row, string content ) 00236 { 00237 OleAutoArgs objArgBlock = create 00238 OleAutoObj objExcelCell = null 00239 int l=length(content) 00240 00241 if (ExcelAvailable()) 00242 { 00243 clear( objArgBlock ) 00244 put( objArgBlock, ExcelAddress(col,row) ) 00245 oleGet( objSheet, "Range", objArgBlock, objExcelCell ) 00246 if (null objExcelCell) 00247 { 00248 ack "NULL cell ("col","row")" 00249 } 00250 else 00251 { 00252 //enclose string in " if value starts with =, - or a digit 00253 if ( null content) 00254 { 00255 // do nothing 00256 } 00257 else if (l < 20 && matches("^[=0-9.,e-]+$", content)) 00258 { 00259 olePut( objExcelCell, "value", "=\""content"\"" ) 00260 } 00261 else if (content[0] == '\'') 00262 { 00263 olePut( objExcelCell, "value", "'"content ) 00264 } 00265 else 00266 { 00267 olePut( objExcelCell, "value", content ) 00268 } 00269 } 00270 delete objArgBlock 00271 } 00272 } // ExcelPut 00273 00274 00275 /* ************************************************************************** 00276 Function : clearWordState() 00277 description: 00278 *********************************************************************************/ 00279 void wordMergeRowVBA(){ 00280 00281 OleAutoObj Cells_ole 00282 OleAutoObj Selection_ole 00283 00284 00285 oleMethod(objSel, "SelectRow") 00286 oleGet(objSel, "Cells", Cells_ole) 00287 oleMethod(Cells_ole, "Merge") 00288 } 00289 /* ************************************************************************** 00290 Function : clearWordState() 00291 description: 00292 *********************************************************************************/ 00293 void clearWordState() 00294 { 00295 exportEndProgress 00296 checkRes(olePut(objWord,cPropertyScreenUpdating,true)) 00297 halt 00298 } 00299 /* ************************************************************************** 00300 Function : logError() 00301 description: error logging is captured 00302 *********************************************************************************/ 00303 void logError(string errDescription, string errMessage, Object o) 00304 { 00305 errorLogBuffer += errDescription 00306 errorLogBuffer += " failed with error message: '" 00307 errorLogBuffer += errMessage 00308 errorLogBuffer += "' for object " 00309 errorLogBuffer += (identifier o) 00310 errorLogBuffer += "\n\n" 00311 } 00312 /* ************************************************************************** 00313 Function : vbaCheckRes() 00314 description: verification method used for OLE methods 00315 *********************************************************************************/ 00316 void vbaCheckRes(string res) 00317 { 00318 if (res != "") 00319 { 00320 00321 ack "OLE method failed: " res 00322 clearWordState 00323 } 00324 } 00325 00326 /* ************************************************************************** 00327 Function : collapseSelection() 00328 description: 00329 *********************************************************************************/ 00330 void collapseSelection() 00331 { 00332 clear objArgBlock 00333 put(objArgBlock, cParamDirection, wdCollapseEnd) 00334 vbaCheckRes(oleMethod(objSel, cMethodCollapse, objArgBlock)) 00335 } 00336 /* ************************************************************************** 00337 Function : collapseSelectionBackwards() 00338 description: 00339 *********************************************************************************/ 00340 void collapseSelectionBackwards() 00341 { 00342 clear objArgBlock 00343 put(objArgBlock, cParamDirection, wdCollapseStart) 00344 vbaCheckRes(oleMethod(objSel, cMethodCollapse, objArgBlock)) 00345 } 00346 00347 /* ************************************************************************** 00348 Function : vbaGetStyleName() 00349 description: takes style number as input, resolves the styles, style, style name and returns the same 00350 *********************************************************************************/ 00351 string vbaGetStyleName(OleAutoObj objDoc, int styleNumber) 00352 { 00353 OleAutoObj objStyles = null 00354 OleAutoObj objStyle = null 00355 string styleName = null 00356 00357 vbaCheckRes(oleGet(objDoc, cPropertyStyles, objStyles)) // styles is a collection of all style 00358 00359 if (null objStyles) 00360 { 00361 ack "Unable to get handle on styles collection" 00362 clearWordState 00363 } 00364 00365 clear objArgBlock 00366 put(objArgBlock, styleNumber) 00367 00368 vbaCheckRes(oleMethod(objStyles, cMethodItem, objArgBlock, objStyle)) // fetch the style number 00369 00370 if (null objStyle) 00371 { 00372 ack "Unable to get handle on style" 00373 clearWordState 00374 } 00375 00376 vbaCheckRes(oleGet(objStyle, cPropertyNameLocal, styleName))// fetch the style name 00377 00378 if (null styleName) 00379 { 00380 ack "Unable to get style name" 00381 clearWordState 00382 } 00383 00384 closeIfNonNull objStyle 00385 closeIfNonNull objStyles 00386 00387 return styleName 00388 } 00389 00390 00391 /* ************************************************************************** 00392 Function : wordCheckVersion () 00393 description: get the word document's version, either by takingthe existing word, or by creating a new one 00394 *********************************************************************************/ 00395 string wordCheckVersion() 00396 { 00397 objArgBlock = create 00398 00399 if (null objArgBlock) 00400 { 00401 ack "Unable to create argument block. Low memory?" 00402 return "" 00403 } 00404 // Get Word object 00405 objWord = oleGetAutoObject(cObjWordApplication) // get the word application 00406 00407 if (null objWord) 00408 { 00409 objWord = oleCreateAutoObject(cObjWordApplication) // else create a new word object 00410 } 00411 00412 string versionString 00413 vbaCheckRes(oleGet(objWord,cPropertyVersion, versionString)) //version of the word document 00414 return versionString 00415 00416 } 00417 00418 /* ************************************************************************** 00419 Function : wordPreChecksVBA () 00420 description: to make the word document visible, active and set the control 00421 *********************************************************************************/ 00422 bool wordPreChecksVBA() 00423 { 00424 Object curro = current Object 00425 m = current Module 00426 00427 // Make Word visible 00428 if (!doStyleMapping) 00429 { 00430 makeVisible objWord 00431 } 00432 00433 // Get documents collection 00434 checkRes(oleGet(objWord,cPropertyDocuments,objDocs)) //get the document 00435 00436 if (null objDocs) 00437 { 00438 ack "Unable to get Documents collection" 00439 return false 00440 } 00441 00442 clear objArgBlock 00443 put(objArgBlock,TemplateFileName_s) 00444 checkRes(oleMethod(objDocs,cMethodAdd,objArgBlock)) 00445 00446 // Get a handle on the document 00447 checkRes(oleGet(objWord,cPropertyActiveDocument,objDoc)) //activate the document 00448 if (null objDoc) 00449 { 00450 ack "Unable to get active document" 00451 halt 00452 } 00453 00454 // Get a handle on the selection object 00455 checkRes(oleGet(objWord,cPropertySelection,objSel)) //select the object in the document 00456 00457 if (null objSel) 00458 { 00459 ack "Unable to get selection object" 00460 halt 00461 } 00462 // Get a handle on the tables collection 00463 checkRes(oleGet(objDoc,cPropertyTables,objTables)) //defines the set of all tables defined in the document 00464 00465 if (null objTables) 00466 { 00467 ack "Unable to get tables collection" 00468 halt 00469 } 00470 00471 return true 00472 } 00473 /* ************************************************************************** 00474 Function : getWordStyleNames () 00475 description: to get the Fontname, style name etc 00476 *********************************************************************************/ 00477 void getWordStyleNames(OleAutoObj objDoc) 00478 { 00479 OleAutoObj objStyles = null 00480 OleAutoObj objStyle = null 00481 OleAutoObj objFont = null 00482 OleAutoObj objParaFormat = null 00483 OleAutoObj objListTemplate = null 00484 00485 string styleName = null 00486 string fontName = null 00487 00488 int styleType = 0 00489 int leftIndent = 0 00490 int count, stylesToCheck 00491 00492 wordStyleNames = create 00493 wordStyleFonts = create 00494 00495 vbaCheckRes(oleGet(objDoc, cPropertyStyles, objStyles)) 00496 00497 if (null objStyles) 00498 { 00499 ack "Unable to get handle on styles collection" 00500 clearWordState 00501 } 00502 00503 vbaCheckRes(oleGet(objStyles, cPropertyCount, stylesToCheck)) 00504 00505 for (count = 1; count <= stylesToCheck; count++) 00506 { 00507 clear objArgBlock 00508 put(objArgBlock, count) 00509 00510 vbaCheckRes(oleMethod(objStyles, cMethodItem, objArgBlock, objStyle)) 00511 00512 if (null objStyle) 00513 { 00514 ack "Unable to get handle on style" 00515 clearWordState 00516 } 00517 00518 // Don't use character styles 00519 vbaCheckRes(oleGet(objStyle, cPropertyType, styleType)) 00520 00521 if (styleType != wdStyleTypeParagraph) 00522 { 00523 closeIfNonNull objStyle 00524 continue 00525 } 00526 00527 styleName = "" 00528 fontName = "" 00529 leftIndent = 0 00530 00531 vbaCheckRes(oleGet(objStyle, cPropertyNameLocal, styleName)) 00532 00533 if (null styleName) 00534 { 00535 ack "Unable to get style name" 00536 clearWordState 00537 } 00538 put(wordStyleNames,noWordStyles,styleName) 00539 00540 oleGet(objStyle, cPropertyListTemplate, objListTemplate) 00541 00542 oleGet(objStyle, cPropertyParagraphFormat, objParaFormat) 00543 closeIfNonNull objParaFormat 00544 00545 // get font name so we can set the correct default font 00546 vbaCheckRes(oleGet(objStyle, cPropertyFont, objFont)) 00547 00548 if (null objFont) 00549 { 00550 ack "Unable to get handle on font" 00551 clearWordState 00552 } 00553 00554 vbaCheckRes(oleGet(objFont, cPropertyName, fontName)) 00555 00556 if (null fontName) 00557 { 00558 ack "Unable to get font name" 00559 clearWordState 00560 } 00561 00562 closeIfNonNull objFont 00563 closeIfNonNull objStyle 00564 00565 put(wordStyleFonts,styleName,fontName) 00566 00567 noWordStyles++ 00568 } 00569 00570 closeIfNonNull objStyles 00571 00572 string tempWordStyles[noWordStyles] 00573 00574 for (count = 0; count < noWordStyles; count++) 00575 { 00576 find(wordStyleNames, count, tempWordStyles[count]) 00577 } 00578 00579 sort tempWordStyles 00580 delete wordStyleNames 00581 wordStyleNames = create 00582 00583 for (count = 0; count < noWordStyles; count++) 00584 { 00585 put(wordStyleNames, count, tempWordStyles[count]) 00586 } 00587 } 00588 00589 /* ************************************************************************** 00590 Function : fillStyleNameArrays () 00591 description: headingstyle and bodystyle are set in string of arrays 00592 *********************************************************************************/ 00593 void fillStyleNameArrays() 00594 { 00595 int count 00596 string styleName 00597 00598 for (count = 0; count < maxWordLevel; count++) 00599 { 00600 styleName = vbaGetStyleName(objDoc,wordHeadingStyles[count]) 00601 headingStyleNames[count] = styleName 00602 } 00603 00604 styleName = vbaGetStyleName(objDoc,wdStyleNormal) 00605 00606 for (count = 0; count < maxWordLevel; count++) 00607 { 00608 bodyStyleNames[count] = styleName 00609 } 00610 } 00611 /*************************Bookmark Update for the header through macro*****************/ 00612 void HeaderBookmark (string bm) 00613 { 00614 00615 clear objArgBlock 00616 put (objArgBlock, "MacroName", "SetHeaderBaseline") 00617 put (objArgBlock, "varg1", bm) 00618 checkRes (oleMethod (objWord, "Run", objArgBlock)) 00619 00620 } 00621 00622 /* ************************************************************************** 00623 Function : InitWord () 00624 description: initialize the word document 00625 *********************************************************************************/ 00626 void InitWord() 00627 { 00628 string sBaselinever 00629 string wordVersion = wordCheckVersion () 00630 00631 if (wordVersion =="") 00632 { 00633 return 00634 } 00635 wordPreChecksVBA () 00636 fillStyleNameArrays() 00637 getWordStyleNames objDoc 00638 sStyleNormal = vbaGetStyleName(objDoc, wdStyleNormal) 00639 00640 if(Baseline_b==true) 00641 { 00642 mod =current Module 00643 Baseline b = getMostRecentBaseline(mod) 00644 00645 00646 if(baselineExists(mod,b)!=true) 00647 { 00648 00649 ack("Selected module is not baselined hence baseline version is not updated \n") 00650 return 00651 00652 00653 00654 00655 } 00656 00657 else 00658 { 00659 sBaselinever = (major b)"."(minor b)(suffix b) 00660 HeaderBookmark(sBaselinever) 00661 } 00662 00663 00664 00665 00666 } 00667 } 00668 /* ************************************************************************** 00669 Function : UpdateTOC () 00670 description: To update the table of contents. 00671 *********************************************************************************/ 00672 void UpdateTOC(){ 00673 00674 OleAutoObj Fields_ole 00675 OleAutoArgs autoArgs = create 00676 int i 00677 00678 oleGet(objDoc, "Fields", Fields_ole) 00679 oleMethod(Fields_ole, "Update", autoArgs, i) 00680 } 00681 00682 00683 /* ************************************************************************** 00684 Function : makeFontTableFromStyle () 00685 description: get the font name from font skiplist using stylename as key and generate a font table 00686 *********************************************************************************/ 00687 00688 string makeFontTableFromStyle(string styleName) 00689 { 00690 // build a font table with the appropriate default font for the style 00691 string fontName = "" 00692 string defaultFontEntry 00693 string fontTable 00694 00695 find(wordStyleFonts, styleName, fontName) 00696 00697 defaultFontEntry = "{\\f0\\fnil " fontName ";}" 00698 fontTable = fontTableBeginning defaultFontEntry fontTableEnd 00699 00700 return fontTable 00701 } 00702 00703 /* ************************************************************************** 00704 Function : pasteAndApplyStyle () 00705 description: pasting of the data (richtext) from doors to word 00706 *********************************************************************************/ 00707 string pasteAndApplyStyle(OleAutoObj objSelection, RTF_string__ s, string styleName) 00708 { 00709 //styleName = vbaGetStyleName(objDoc,wdStyleNormal) 00710 string fontTable = makeFontTableFromStyle(styleName) 00711 setRichClip(s, styleName,fontTable ) 00712 return oleMethod(objSelection, cMethodPaste) 00713 00714 } 00715 00716 /* ************************************************************************** 00717 Function : pasteAndApplyStyle () 00718 description: pasting of the data (buffer) from doors to word 00719 *********************************************************************************/ 00720 string pasteAndApplyStyle(OleAutoObj objSelection, Buffer b, string styleName) 00721 { 00722 //styleName = vbaGetStyleName(objDoc,wdStyleNormal) 00723 string fontTable = makeFontTableFromStyle(styleName) 00724 setRichClip(b, styleName,fontTable) 00725 return oleMethod(objSelection, cMethodPaste) 00726 } 00727 /* ************************************************************************** 00728 Function : endKey () 00729 description: table of contents will be stored in the begining 00730 without this it will be at the end of the document 00731 *********************************************************************************/ 00732 void endKey() 00733 { 00734 // move past the object 00735 clear objArgBlock 00736 put(objArgBlock, wdStory) 00737 vbaCheckRes(oleMethod(objSel,cMethodEndKey,objArgBlock)) 00738 } 00739 00740 /* ************************************************************************** 00741 Function : MakeSection () 00742 description: make different sections in the document (like headlines, text etc) 00743 *********************************************************************************/ 00744 void MakeSection(string Headline_s, string Text_s, string SectionStructure_s, int SectionStructureLevel_i){ 00745 /* local declaration */ 00746 string TitleText_s = "" 00747 OleAutoObj TableOfContents_ole 00748 OleAutoObj Range_ole 00749 OleAutoArgs autoArgs = create 00750 int SelStart_i = 0 00751 int SelEnd_i = 0 00752 string styleName = vbaGetStyleName(objDoc,wdStyleNormal) 00753 oleGet(objDoc, "TablesOfContents", TableOfContents_ole) 00754 00755 /* make Section Headline */ 00756 if (Headline_s != ""){ 00757 //TitleText_s = Headline_s 00758 TitleText_s = SectionStructure_s " " Headline_s 00759 //pasteAndApplyStyle(objSel, richText TitleText_s, styleName) 00760 print ".. "TitleText_s"....\n" 00761 pasteAndApplyStyle(objSel, richText TitleText_s,headingStyleNames[SectionStructureLevel_i]) //the section level is defined with this. the HeadingStyleNames[maxword] has all levels defined. 00762 } 00763 oleMethod(objSel, "TypeParagraph") 00764 oleGet(objSel, "Range", Range_ole) 00765 clear autoArgs 00766 put (autoArgs, "Range", Range_ole) 00767 // put (autoArgs, "Level", SectionStructureLevel_i + 1) 00768 put (autoArgs, "Level", SectionStructureLevel_i+1) 00769 put (autoArgs, "Entry", TitleText_s) 00770 oleMethod(TableOfContents_ole, "MarkEntry", autoArgs) 00771 endKey() 00772 if (Text_s != ""){ 00773 pasteAndApplyStyle(objSel, richText Text_s, bodyStyleNames[0]) 00774 oleMethod(objSel, "TypeParagraph") 00775 } 00776 00777 } 00778 00779 /* ************************************************************************** 00780 Complete section for filtering processing 00781 * **************************************************************************/ 00782 00783 //the rest of the stuff will be as in the following constants 00784 Array FilterArray 00785 const int OPERATOR = 0 00786 const int LEVEL = 1 00787 const int PARENT = 2 00788 const int FILTER = 3 00789 const int STRING = 4 00790 const int SIMPLE = 5 00791 00792 //constants for compound filters 00793 const int NONE = 0 00794 const int NOTop = 1 00795 const int ANDop = 2 00796 const int ORop = 3 00797 string Ops[]={"NONE", "NOT", "AND", "OR"} 00798 00799 //general globals 00800 int DeepestLevel 00801 int FilterCount 00802 string WholeThing 00803 00804 //This stuff is for tokenizing/ detokenizing 00805 Regexp DodgyChars = regexp "(\"|\\(|\\)|\\[|\\]|\\.|\\^|\\||\\$|\\+|\\*|\\\\)" 00806 Skip TokenSkip 00807 int NumberOfTokens 00808 bool ProcessTokens 00809 00810 string appName ="VBScript.RegExp" 00811 OleAutoObj RegExpObj = oleCreateAutoObject(appName) 00812 if (null (RegExpObj)) error "Cannot connect to OLE Application >"appName"<!" 00813 00814 OleAutoObj MatchesColl 00815 OleAutoObj MatchObj 00816 OleAutoObj SubMatchesColl 00817 OleAutoArgs args = create 00818 Regexp Escapes = regexp "(\"|\\(|\\)|\\[|\\]|\\.|\\^|\\||\\$|\\+|\\*|\\\\|?)" 00819 00820 void addEscapesForRegexp(string &txt) { 00821 if ( txt == "" ) return 00822 00823 Buffer b = create 00824 int i = 0 00825 00826 while ( Escapes txt[i:] ) { 00827 b += txt[i:i+start(0)-1] 00828 if( txt[i+start(0):i+end(0)] =="\\\\") b += "\\\\\\\\" 00829 elseif ( txt[i+start(0):i+end(0)] == txt[i:][match 0] ) b += "\\" txt[i+start(0):i+end(0)] 00830 else b += txt[i+start(0):i+end(0)] 00831 i += (end 0)+1 00832 } 00833 b += txt[i:] 00834 txt = stringOf b 00835 delete(b) 00836 } 00837 00838 string VBReplace(string inStr, FindStr, RepStr, bool IgnoreCase) { 00839 string Str="" 00840 clear args 00841 addEscapesForRegexp(FindStr) 00842 olePut(RegExpObj,"Pattern",FindStr) 00843 olePut(RegExpObj,"IgnoreCase",IgnoreCase) 00844 put(args, inStr) 00845 put(args, RepStr) 00846 oleMethod(RegExpObj,"Replace",args,Str) 00847 return Str 00848 } 00849 00850 void ReturnSubMatches( Skip PassedSkip, string inStr, FindPattern, int SubMatchNum, bool IgnoreCase) { 00851 string SubMatch 00852 clear args 00853 olePut(RegExpObj,"IgnoreCase",IgnoreCase) 00854 olePut(RegExpObj,"Global",true) 00855 int NumOfMatches=0,i,j=0 00856 00857 olePut(RegExpObj,"Pattern",FindPattern) 00858 put(args, inStr) 00859 oleMethod(RegExpObj,"Execute",args,MatchesColl) 00860 oleGet(MatchesColl,"Count",NumOfMatches) 00861 00862 if(NumOfMatches==0) return 00863 00864 for(i=0;i<NumOfMatches;i++) { 00865 clear args; put(args,i) 00866 oleGet(MatchesColl,"Item",args,MatchObj) 00867 00868 oleGet(MatchObj,"SubMatches",SubMatchesColl) 00869 clear args; put(args,SubMatchNum) 00870 oleGet(SubMatchesColl,"Item",args,SubMatch) 00871 00872 if(!null SubMatch) { 00873 if(!find(PassedSkip,SubMatch)) { 00874 put(PassedSkip,SubMatch,SubMatch) 00875 } 00876 } 00877 } 00878 MatchesColl =null 00879 MatchObj =null 00880 SubMatchesColl=null 00881 } 00882 00883 string ReturnFirstSubMatch( string inStr, FindPattern, int SubMatchNum, bool IgnoreCase) { 00884 string SubMatch 00885 clear args 00886 olePut(RegExpObj,"IgnoreCase",IgnoreCase) 00887 olePut(RegExpObj,"Global",false) 00888 int NumOfMatches=0,i,j=0 00889 00890 olePut(RegExpObj,"Pattern",FindPattern) 00891 put(args, inStr) 00892 oleMethod(RegExpObj,"Execute",args,MatchesColl) 00893 oleGet(MatchesColl,"Count",NumOfMatches) 00894 if(NumOfMatches==0) return "" 00895 clear args; put(args,0) 00896 oleGet(MatchesColl,"Item",args,MatchObj) 00897 00898 oleGet(MatchObj,"SubMatches",SubMatchesColl) 00899 clear args; put(args,SubMatchNum) 00900 oleGet(SubMatchesColl,"Item",args,SubMatch) 00901 00902 if(null SubMatch) return "" 00903 00904 MatchesColl =null 00905 MatchObj =null 00906 SubMatchesColl=null 00907 return SubMatch 00908 } 00909 00910 string ReturnFirstMatch( string inStr, FindPattern, bool IgnoreCase) { 00911 string MatchStr 00912 clear args 00913 olePut(RegExpObj,"IgnoreCase",IgnoreCase) 00914 olePut(RegExpObj,"Global",false) 00915 int NumOfMatches=0,i,j=0 00916 00917 olePut(RegExpObj,"Pattern",FindPattern) 00918 put(args, inStr) 00919 oleMethod(RegExpObj,"Execute",args,MatchesColl) 00920 oleGet(MatchesColl,"Count",NumOfMatches) 00921 if(NumOfMatches==0) return "" 00922 00923 clear args; put(args,0) 00924 oleGet(MatchesColl,"Item",args,MatchObj) 00925 oleGet(MatchObj,"Value",MatchStr) 00926 if(null MatchStr) return "" 00927 00928 MatchesColl =null 00929 MatchObj =null 00930 return MatchStr 00931 } 00932 00933 00934 void ReturnMatches( Skip PassedSkip, string inStr, FindPattern, bool IgnoreCase) { 00935 string MatchStr 00936 clear args 00937 olePut(RegExpObj,"IgnoreCase",IgnoreCase) 00938 olePut(RegExpObj,"Global",true) 00939 int NumOfMatches=0,i,j=0 00940 00941 olePut(RegExpObj,"Pattern",FindPattern) 00942 put(args, inStr) 00943 oleMethod(RegExpObj,"Execute",args,MatchesColl) 00944 oleGet(MatchesColl,"Count",NumOfMatches) 00945 00946 if(NumOfMatches==0) return 00947 00948 for(i=0;i<NumOfMatches;i++) { 00949 clear args; put(args,i) 00950 oleGet(MatchesColl,"Item",args,MatchObj) 00951 00952 oleGet(MatchObj,"Value",MatchStr) 00953 if(!null MatchStr) { 00954 if(!find(PassedSkip,MatchStr)) { 00955 put(PassedSkip,MatchStr,MatchStr) 00956 } 00957 } 00958 } 00959 MatchesColl =null 00960 MatchObj =null 00961 } 00962 // regular Expressions needed to recognize "simple" Filters 00963 Regexp REcolumnFilter = regexp "Column '(.*)' contains \"(.*)\"(.*)" 00964 Regexp REcontainsFilter = regexp "(.*) (CONTAINS|Contains) '(.*)' (.*)" 00965 Regexp REcontentsFilter = regexp "(CONTAINS|Contains) '(.*)'(.*)" 00966 Regexp REmultiValueFilter = regexp "(.*) (excludes|includes) (.*)" 00967 Regexp REemptyFilter = regexp "(.*) is (not |)empty" 00968 Regexp REcompareFilter = regexp "(.*) (>=|>|<=|<|!=|==) (.*)" 00969 Regexp REcurrentObjectFilter = regexp "(Exclude|Include) Object (.*)" 00970 Regexp REleavesFilter = regexp "(|Non-)Leaves" 00971 Regexp RElinksFilter = regexp "Has (no |)(in-|out-|in or out )links through (.*)" 00972 bool FilterError 00973 00974 00975 void printFilterError (string input, string err){ 00976 ack "ERROR on parsing filter string '"input"' (please redo your filter): \n"err"\n" 00977 FilterError = true 00978 } 00979 00980 00981 void DeTokenizeString(string &inp) { 00982 string Tok, OrigStr 00983 for OrigStr in TokenSkip do { 00984 Tok = (string key TokenSkip) 00985 inp = VBReplace(inp, Tok, OrigStr,false) 00986 } 00987 } 00988 00989 00990 // function to parse a "simple" Filter, that means, which is not combined of other Filters 00991 Filter parseSimpleFilter (string input){ 00992 if(ProcessTokens) DeTokenizeString(input) 00993 00994 if (REcolumnFilter input){ // any type of "Column" filters 00995 string params = input[match 3] 00996 string colName = input[match 1] 00997 string val = input[match 2] 00998 if (null params) return column (colName, val, false, false) 00999 else if (params == " (with regexps and case sensitive)") return column (colName, val, true, true) 01000 else if (params == " (with regexps)") return column (colName, val, false, true) 01001 else if (params == " (case sensitive)") return column (colName, val, true, false) 01002 else{ 01003 printFilterError (input, "unrecognized parameter to Column Filter >>"params"<<\n"//- 01004 "possible values are : '(with regexps)', '(case sensitive)', '(with regexps and case sensitive)' or nothing") 01005 } 01006 } 01007 else if (REcontainsFilter input){ // any type of Attribute contains filter 01008 if (input[match 4] == "[with regexps]") return contains (attribute input[match 1], input[match 3]) 01009 else if (null input[match 4]) 01010 return contains (attribute input[match 1], input[match 3], input[match 2] == "Contains") 01011 else{ 01012 printFilterError (input, "unrecognized parameter to Contains Filter >>"input[match 4]"<<\n"//- 01013 "possible values are : '[with regexps]' or nothing") 01014 } 01015 } 01016 else if (REcontentsFilter input){ // any type of "Any Text Attribute" contains filter 01017 if (input[match 3] == " [with regexps]") return contents (input[match 2]) 01018 else if (null input[match 3]) return contents (input[match 2], input[match 1] == "Contains") 01019 else{ 01020 printFilterError (input, "unrecognized parameter to Contains in any Text Attribute Filter >>"input[match 3]"<<\n"//- 01021 "possible values are : '[with regexps]' or nothing") 01022 } 01023 } 01024 else if (REmultiValueFilter input){ // both types of filter for multivalued attributes 01025 if (input[match 2] == "excludes") 01026 return excludes (attribute input[match 1], input[match 3]) 01027 else return includes (attribute input[match 1], input[match 3]) 01028 } 01029 else if (REemptyFilter input){ // is Empty and is not Empty filters 01030 if (null input[match 2]) 01031 return isNull (attribute input[match 1]) 01032 else return notNull (attribute input[match 1]) 01033 } 01034 else if (REcompareFilter input){ // any type of comarison filters 01035 string cmd = input[match 2] 01036 string thisAtt = input[match 1] 01037 if (thisAtt == "Object Number" or exists attribute thisAtt) { 01038 if (cmd == ">=") return (attribute input[match 1] >= input[match 3]) 01039 else if (cmd == ">") return (attribute input[match 1] > input[match 3]) 01040 else if (cmd == "<=") return (attribute input[match 1] <= input[match 3]) 01041 else if (cmd == "<") return (attribute input[match 1] < input[match 3]) 01042 else if (cmd == "!=") return (attribute input[match 1] != input[match 3]) 01043 else if (cmd == "==") return (attribute input[match 1] == input[match 3]) 01044 } 01045 else { 01046 printFilterError (input, "Attribute '" thisAtt "' does not exist") 01047 } 01048 } 01049 else if (REcurrentObjectFilter input){ // filter that includes/excludes current Object respectively any Object 01050 Object ThisObj =object (intOf (input[match 2])) 01051 if (null ThisObj) { 01052 printFilterError (input, "Object " input[match 2] " no longer exists.") 01053 } 01054 current = ThisObj 01055 if (input[match 1] == "Exclude") return excludeCurrent 01056 else return includeCurrent 01057 } 01058 else if (REleavesFilter input){ // filter to show only leaves 01059 if (null input[match 1]) return includeLeaves 01060 else return excludeLeaves 01061 } 01062 else if (RElinksFilter input){ // any Link related filters 01063 LinkFilter lf 01064 if (input[match 2] == "in-") lf = linkFilterIncoming 01065 else if(input[match 2] == "out-") lf = linkFilterOutgoing 01066 else lf = linkFilterBoth 01067 if (null input[match 1]) return hasLinks (lf, input[match 3]) 01068 else return hasNoLinks (lf, input[match 3]) 01069 } 01070 else printFilterError (input, "unrecognized Filter string") 01071 return null 01072 } 01073 01074 01075 Filter ProcessFilterParts() { 01076 int i,j,k, temp 01077 string str, FiltString 01078 bool b 01079 int ParentArray[FilterCount] 01080 // Stream out = write "C:\\Temp\\Debug.tsv" 01081 // out << "String\tOperator\tParent\tID\tSimple\tLevel\n" 01082 for(i=0;i<FilterCount;i++) { 01083 // str = (string get(FilterArray,i,STRING)) // cast get as string 01084 // out << str "\t" 01085 // temp = (int get(FilterArray,i,OPERATOR)) 01086 // out << Ops[temp] "\t" 01087 temp = (int get(FilterArray,i,PARENT)) 01088 ParentArray[i]=temp 01089 // out << temp "\t" i "\t" 01090 // b = (bool get(FilterArray,i,SIMPLE)) 01091 // out << b "\t" 01092 // temp =(int get(FilterArray,i,LEVEL)) 01093 // out << temp "\n" 01094 } 01095 // close out 01096 01097 int ThisLev, ThisOp, ThisPar, ParOp 01098 bool IsItSimple 01099 Filter ThisFilt 01100 01101 //check for simplest case 01102 IsItSimple = (bool get(FilterArray,0,SIMPLE)) 01103 if (IsItSimple) return parseSimpleFilter(WholeThing) 01104 01105 //make all the simple filters on the first pass 01106 for(i=DeepestLevel;i>0;i--) { 01107 for(j=0;j<FilterCount;j++) { 01108 ThisLev = (int get(FilterArray,j,LEVEL)) 01109 if(ThisLev ==i) { 01110 IsItSimple = (bool get(FilterArray,j,SIMPLE)) 01111 //look for simple filters and make them 01112 if(IsItSimple) { 01113 FiltString =(string get(FilterArray,j,STRING)) 01114 ThisFilt =parseSimpleFilter(FiltString) 01115 put(FilterArray, ThisFilt, ParentArray[j], FILTER) 01116 } 01117 } 01118 } 01119 } 01120 01121 01122 //combine the simple filters on the second pass 01123 Filter FirstPart, SecondPart 01124 for(k=DeepestLevel;k>0;k--) { 01125 for(i=0;i<FilterCount;i++) { 01126 ThisLev = (int get(FilterArray,i,LEVEL)) 01127 if(ThisLev ==k) { 01128 ThisOp = (int get(FilterArray,i,OPERATOR)) 01129 //look for AND find object with same parent and combine 01130 //object with same parent will always be below object with operator 01131 j=i+1 01132 FirstPart=(Filter get(FilterArray,i,FILTER)) 01133 //cope with meaningless brackets by looking for a filter at the next level down 01134 //the following is a semi frig 01135 if(null FirstPart and ThisOp>0) { 01136 FirstPart =(Filter get(FilterArray,i+1,FILTER)) 01137 int TempLev= (int get(FilterArray,i+1,LEVEL)) 01138 if((null FirstPart) or (TempLev-1!=ThisLev)) { 01139 ack "null filter passed can't recover" 01140 halt 01141 } 01142 } 01143 if(ThisOp == ANDop or ThisOp == ORop) { 01144 while(j<FilterCount) { 01145 if(ParentArray[i]==ParentArray[j]) { 01146 SecondPart =(Filter get(FilterArray,j,FILTER)) 01147 break 01148 } 01149 j++ 01150 } 01151 //cope with meaningless brackets by looking for a filter at the next level down 01152 //the following is a semi frig 01153 if(null SecondPart) { 01154 SecondPart =(Filter get(FilterArray,j+1,FILTER)) 01155 int TempLev= (int get(FilterArray,j+1,LEVEL)) 01156 if((null SecondPart) or (TempLev-1!=ThisLev)) { 01157 ack "null filter passed can't recover" 01158 halt 01159 } 01160 } 01161 01162 if(ThisOp == ANDop) ThisFilt = FirstPart && SecondPart 01163 else ThisFilt = FirstPart || SecondPart 01164 if(ParentArray[i]==-1) put(FilterArray, ThisFilt, 0, FILTER) 01165 else put(FilterArray, ThisFilt, ParentArray[i], FILTER) 01166 01167 } 01168 elseif(ThisOp == NOTop) { 01169 ThisFilt = ! FirstPart 01170 if(ParentArray[i]==-1) put(FilterArray, ThisFilt, 0, FILTER) 01171 else put(FilterArray, ThisFilt, ParentArray[i], FILTER) 01172 01173 } 01174 elseif(ThisOp == NONE) { 01175 //do nothing except for the mental case of two sets of meaningless brackets 01176 // if(ParentArray[i]!=-1) { 01177 // ParOp =(int get(FilterArray,ParentArray[i],OPERATOR)) 01178 // if(ParOp == NONE) put(FilterArray, ThisFilt, ParentArray[i], FILTER) 01179 // } 01180 } 01181 else { 01182 ack "error in operator part" 01183 halt 01184 } 01185 01186 } 01187 } 01188 } 01189 //Final filter will or should! rise to the top element 01190 ThisFilt =(Filter get(FilterArray,0,FILTER)) 01191 return ThisFilt 01192 } 01193 01194 01195 //attributes and enumerations can have brackets in which buggers things up totally 01196 void TokenizeString(string &input) { 01197 string Str = input 01198 bool Changed, dummy=false 01199 AttrDef ad 01200 AttrType at 01201 AttrBaseType abt 01202 int j,i 01203 string s, ThisToken, AtName 01204 char c 01205 01206 for ad in current Module do { 01207 at = ad.type 01208 abt = at.type 01209 if(ad.system) continue 01210 01211 //process attribute names (they can have brackets) 01212 AtName= ad.name 01213 if (DodgyChars AtName) { 01214 Changed=false 01215 ThisToken = "FCU" NumberOfTokens "K" 01216 NumberOfTokens++ 01217 //need to do a simple replace but DOORS is shit at regexps it just won't work 01218 //hence call a vbs script what an ass! 01219 input = VBReplace(input, AtName, ThisToken, false) 01220 01221 //add to skip with token key 01222 if (Str!=input) { 01223 ProcessTokens=true 01224 put(TokenSkip,ThisToken, AtName) 01225 } 01226 } 01227 01228 if (abt == attrEnumeration) { 01229 //process attribute enumerations (the main culprits) 01230 for (j=0; j<(at.size); j++){ 01231 s=at.strings[j] 01232 if (DodgyChars s) { 01233 Changed=false 01234 ThisToken = "FCU" NumberOfTokens "K" 01235 NumberOfTokens++ 01236 //need to do a simple replace but DOORS can't do regexps with escape chars in the middle 01237 //it just won't work, hence call a vb script: what an ass! 01238 input = VBReplace(input, s, ThisToken, false) 01239 01240 //add to skip with token key 01241 if (Str!=input) { 01242 ProcessTokens=true 01243 put(TokenSkip,ThisToken, s) 01244 } 01245 } 01246 } 01247 } 01248 } 01249 } 01250 01251 void ProcessFilter (string b, int Thelevel, int Parent){ 01252 int bCount = 0, i=0 01253 bool isInString = false 01254 Filter leftFilter = null 01255 int stopAt = length b 01256 bool NoBrackets=true 01257 int StartAt 01258 01259 while (i < stopAt){ 01260 if (b[i] == '\'' && (i == 0 || b[i-1] != '\\')) isInString = !isInString 01261 if (isInString == false){ 01262 if (b[i] == '('){ // found brackets 01263 StartAt =i 01264 NoBrackets=false 01265 bCount++ 01266 i = i+1 01267 01268 while (bCount>0 && i < stopAt){ 01269 if (b[i] == '\'' && (i == 0 || b[i-1] != '\\')) isInString = !isInString 01270 if (!isInString){ 01271 if (b[i] == '(') bCount++ 01272 if (b[i] == ')') bCount-- 01273 } 01274 i++ 01275 } 01276 //add the string to the array 01277 put(FilterArray, Thelevel, FilterCount, LEVEL) 01278 put(FilterArray, b[StartAt+1:i-2], FilterCount, STRING) 01279 put(FilterArray, false, FilterCount, SIMPLE) 01280 put(FilterArray, Parent, FilterCount, PARENT) 01281 put(FilterArray, null, FilterCount, FILTER) 01282 01283 //look for NOT this is only relevant at the start of the string 01284 if (b[0:2] == "NOT") { 01285 put(FilterArray, NOTop, FilterCount, OPERATOR) 01286 } 01287 //look for an AND/OR after the brackets 01288 elseif (i < stopAt-2 && (b[i:i+2]== "AND" or b[i+1:i+3] == "AND")){ 01289 put(FilterArray, ANDop, FilterCount, OPERATOR) 01290 } 01291 elseif (i < stopAt-2 && (b[i:i+1] == "OR" or b[i+1:i+2] == "OR")){ // priority 4 01292 put(FilterArray, ORop, FilterCount, OPERATOR) 01293 } 01294 else { 01295 put(FilterArray, NONE, FilterCount, OPERATOR) 01296 } 01297 FilterCount++ 01298 01299 //recurse to next level 01300 ProcessFilter(b[StartAt+1:i-2],Thelevel+1, FilterCount-1) 01301 } 01302 else i++ 01303 } 01304 else i++ 01305 } 01306 01307 if (NoBrackets){ 01308 //Simple filter 01309 put(FilterArray, NONE, FilterCount, OPERATOR) 01310 put(FilterArray, b, FilterCount, STRING) 01311 put(FilterArray, Thelevel, FilterCount, LEVEL) 01312 put(FilterArray, Parent, FilterCount, PARENT) 01313 put(FilterArray, true, FilterCount, SIMPLE) 01314 put(FilterArray, null, FilterCount, FILTER) 01315 FilterCount++ 01316 } 01317 if(Thelevel>DeepestLevel) DeepestLevel = Thelevel 01318 } 01319 01320 Filter parseFilter (string input){ 01321 FilterCount=0 01322 DeepestLevel=0 01323 FilterArray = create(1,1) 01324 WholeThing = input 01325 TokenSkip = createString 01326 NumberOfTokens=0 01327 ProcessTokens=false 01328 TokenizeString(input) 01329 //print input 01330 ProcessFilter (input, 1, -1) 01331 Filter F = ProcessFilterParts 01332 delete TokenSkip 01333 delete FilterArray 01334 return F 01335 } 01336 01337 // END INCLUDE 01338 01339 /* ************************************************************************** 01340 end of section for filtering processing 01341 * **************************************************************************/ 01342 /* ************************************************************************** 01343 Function: CheckModuleOpen () 01344 Description: to verify the module selected is opened or not 01345 * **************************************************************************/ 01346 bool CheckModuleOpen(string ModuleName_s) 01347 { 01348 ModName_ ModuleName_mn = module(ModuleName_s) 01349 if (open module ModuleName_s){ 01350 m = data(moduleVersion(ModuleName_mn)) 01351 current = m 01352 /*print "Module " ModuleName_s " is already open.\n"*/ 01353 return true 01354 } 01355 else{ 01356 m = read(ModuleName_s, false) 01357 put(OpenModules_sk, ModuleName_s, m) 01358 if (null m){ 01359 return false 01360 } 01361 else{ 01362 current = m 01363 return true 01364 } 01365 } 01366 } 01367 01368 /* ************************************************************************** 01369 Function: getRange () 01370 Description: portion of a document that's contained in the specified object 01371 * **************************************************************************/ 01372 OleAutoObj getRange(OleAutoObj obj) 01373 { 01374 OleAutoObj objRange = null 01375 vbaCheckRes(oleGet(obj,cPropertyRange,objRange))//Range object that represents the portion of a document that's contained in the specified object 01376 01377 if (null objRange) 01378 { 01379 ack "Unable to get range object" 01380 clearWordState 01381 } 01382 01383 return objRange 01384 } 01385 /* ************************************************************************** 01386 Function: wordMakeSizedTableVBA () 01387 Description: create table with no.of rows and columns 01388 * **************************************************************************/ 01389 OleAutoObj wordMakeSizedTableVBA(int noRows, int noCols,string TableBookMarking_b) 01390 { 01391 01392 OleAutoObj objTable = null 01393 OleAutoObj objRange = null 01394 string s_Bookmarking = null 01395 01396 // make a table maxCols,rows 01397 collapseSelection 01398 01399 if (noRows == 0 || noCols == 0) 01400 { 01401 return 01402 } 01403 01404 objRange = getRange objSel 01405 01406 clear objArgBlock 01407 put(objArgBlock, objRange) 01408 put(objArgBlock, noRows) 01409 put(objArgBlock, noCols) 01410 if (noRows!=null && noCols!=null) 01411 { 01412 vbaCheckRes(oleMethod(objTables, cMethodAdd, objArgBlock,objTable)) 01413 } 01414 01415 if (null objTable) 01416 { 01417 ack "Failed to make table" 01418 clearWordState 01419 } 01420 01421 i_Count1++ 01422 /* table book-marking created */ 01423 //if(TableBookMarking_b == true) 01424 01425 if(TableBookMarking_b != ""|| TableBookMarking_b!= null) 01426 { 01427 01428 OleAutoObj objBookMarks = null 01429 oleGet(objDoc, "Bookmarks", objBookmarks) 01430 clear objArgBlock 01431 //insert the bookmark 01432 string s_Bookmarking = "Table""_"i_Count1 TableBookMarking_b"" 01433 01434 s_Tablename=s_Bookmarking 01435 put(objArgBlock, s_Bookmarking) 01436 vbaCheckRes(oleMethod(objBookmarks, cMethodAdd, objArgBlock)) 01437 } 01438 else 01439 s_Tablename = null 01440 01441 01442 closeIfNonNull objRange 01443 collapseSelection 01444 01445 return objTable 01446 } 01447 /* ************************************************************************** 01448 Function: styleIndex () 01449 Description: 01450 * **************************************************************************/ 01451 01452 int styleIndex(Object o) 01453 { 01454 int styleLevel = (level o) 01455 int styleLevel1 = styleLevel 01456 if (styleLevel > maxWordLevel) 01457 { 01458 styleLevel = maxWordLevel 01459 } 01460 if(SectionStructureLevel_i1 != null or SectionStructureLevel_i1 == 0 ) 01461 { 01462 styleLevel = SectionStructureLevel_i1-offset_i+styleLevel+1 01463 } 01464 //styleLevel-- 01465 01466 return styleLevel 01467 } 01468 /* ********************************************************************************************** 01469 function: wordGetNumberedCellVBA() 01470 description: Heading style and body styles are defined and assigned for attributes in different levels 01471 **********************************************************************************************/ 01472 OleAutoObj wordGetNumberedCellVBA(OleAutoObj objTable, int rowNo, int cellNo) 01473 { 01474 OleAutoObj objCell = null 01475 clear objArgBlock 01476 put(objArgBlock, rowNo) 01477 put(objArgBlock, cellNo) 01478 01479 vbaCheckRes(oleMethod(objTable, cMethodCell, objArgBlock, objCell)) 01480 01481 if (null objCell) 01482 { 01483 ack "Failed to get cell handle" 01484 clearWordState 01485 } 01486 01487 return objCell 01488 } 01489 /* ********************************************************************************************** 01490 function: getStyleForAttribute() 01491 description: Heading style and body styles are defined and assigned for attributes in different levels (currently the default style is taken for all) 01492 **********************************************************************************************/ 01493 string getStyleForAttribute(Object o, string aName) 01494 { 01495 //string styleName = paraStyleGetAttributeMap_(o, aName) 01496 if (null o) 01497 { 01498 return bodyStyleNames[0] 01499 } 01500 string styleName = paraStyleGetAttributeMap_(o, aName) 01501 if (!null styleName) 01502 { 01503 return styleName 01504 } 01505 int styleLevel 01506 if (cell o) 01507 { 01508 styleLevel = cellHeadingLevel - 1 01509 } 01510 else 01511 { 01512 styleLevel = styleIndex o 01513 } 01514 01515 if (aName == AHeading) 01516 { 01517 return headingStyleNames[styleLevel] 01518 } 01519 else 01520 { 01521 return bodyStyleNames[styleLevel] 01522 } 01523 01524 } 01525 01526 /* *********************************************************************** 01527 function: wordSetCellContentsVBA() 01528 Description: sets the table cells with the data from the selected object attribute from the selected module and the view. 01529 **********************************************************************************/ 01530 01531 void wordSetCellContentsVBA(OleAutoObj objCell, Object o, string s) 01532 { 01533 if (null s) 01534 { 01535 return 01536 } 01537 01538 int styleLevel 01539 01540 if (null o) 01541 { 01542 styleLevel = 0 01543 } 01544 else 01545 { 01546 styleLevel = styleIndex o 01547 } 01548 01549 vbaCheckRes(oleMethod(objCell, cMethodSelect)) 01550 collapseSelectionBackwards 01551 01552 pasteAndApplyStyle(objSel, richText s, getStyleForAttribute(o,"")) 01553 01554 //This removes a carriage return from the table cell 01555 collapseSelection 01556 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace)) 01557 } 01558 01559 /* *********************************************************************** 01560 function: nextCellVBA() 01561 Description: rows will be inserted in table format one after the other 01562 **********************************************************************************/ 01563 OleAutoObj nextCellVBA(OleAutoObj objTable, objCell) 01564 { 01565 OleAutoObj nextCell = null 01566 01567 if (null objCell) 01568 { 01569 01570 nextCell = wordGetNumberedCellVBA(objTable,1,1) 01571 01572 } 01573 else 01574 { 01575 vbaCheckRes(oleGet(objCell, cPropertyNext, nextCell)) 01576 } 01577 01578 if (null nextCell) 01579 { 01580 ack "Unable to get handle on next cell" 01581 clearWordState 01582 } 01583 01584 closeIfNonNull objCell 01585 01586 return nextCell 01587 } 01588 /* *********************************************************************** 01589 function: insertBlankRow() 01590 Description: rows will be inserted in table format one after the other 01591 **********************************************************************************/ 01592 OleAutoObj insertBlankRow(OleAutoObj objTable, OleAutoObj objCell) 01593 { 01594 01595 Column c 01596 01597 for c in m do 01598 { 01599 objCell = nextCellVBA(objTable,objCell) 01600 vbaCheckRes(oleMethod(objCell, cMethodSelect)) 01601 } 01602 01603 return objCell 01604 } 01605 01606 /* *********************************************************************** 01607 function: pasteHeading() 01608 Description: 01609 **********************************************************************************/ 01610 string pasteHeading(OleAutoObj objSelection, Object o, bool doNumbers) 01611 { 01612 string styleName = getStyleForAttribute(o,AHeading) 01613 string errmess = null 01614 if (doNumbers) 01615 { 01616 string s = (number o) " " 01617 errmess = pasteAndApplyStyle(objSelection, richText s, styleName) 01618 if (null errmess) 01619 { 01620 collapseSelection 01621 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace)) 01622 vbaCheckRes(olePut(objSel, cPropertyStyle, wdStyleNormal)) 01623 errmess = pasteAndApplyStyle(objSelection, richTextWithOle o.AHeading, styleName) 01624 } 01625 return errmess 01626 } 01627 else 01628 { 01629 01630 return pasteAndApplyStyle(objSelection, richTextWithOle o.AHeading, styleName) 01631 } 01632 } 01633 /* *********************************************************************** 01634 function: wordDumpBodyVBA() 01635 Description: 01636 **********************************************************************************/ 01637 void wordDumpBodyVBA(Object o, string ObjValue) 01638 { 01639 string errMess 01640 01641 if (!hasCopyableText o) 01642 { 01643 return 01644 } 01645 01646 collapseSelection 01647 01648 Buffer textBuffer = create 01649 if (issueWarnings && containsUnregisteredOle(o.ALongText)) { 01650 warningBox "Object " (identifier o) " contains one or more unregistered OLE objects in '" ALongText "'.\n\nThese OLE objects will be exported as pictures." 01651 } 01652 01653 if (ObjValue!=null) 01654 { 01655 textBuffer = ObjValue 01656 errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o, "")) 01657 01658 } 01659 else 01660 { 01661 textBuffer = richTextWithOle o.ALongText 01662 errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o, ALongText)) 01663 } 01664 01665 delete(textBuffer) 01666 if (!null errMess) 01667 { 01668 logError("Error pasting object text", errMess, o) 01669 } 01670 01671 collapseSelection 01672 } 01673 void wordDumpTableAttributeVBA(Object o) 01674 { 01675 string errMess = "" 01676 if (!hasCopyableTableAttributes(o)) 01677 { 01678 return 01679 } 01680 string attribName = o.(reserved AMainColumnAttribute) 01681 Buffer textBuffer = create 01682 textBuffer = richTextWithOle o.attribName 01683 if (0 < length textBuffer) { 01684 if (issueWarnings && containsUnregisteredOle(o.attribName)) { 01685 warningBox "Object " (identifier o) " contains one or more unregistered OLE objects in '" attribName "'.\n\nThese OLE objects will be exported as pictures." 01686 } 01687 errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o, attribName)) 01688 } 01689 delete(textBuffer) 01690 if (!null errMess) 01691 { 01692 logError("Error pasting "attribName" of cell", errMess, o) 01693 } 01694 collapseSelection 01695 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace)) 01696 } 01697 01698 void wordDumpTableCellMarkerVBA(OleAutoObj objCell, Object o) 01699 { 01700 vbaCheckRes(oleMethod(objCell, cMethodSelect)) 01701 collapseSelectionBackwards 01702 01703 pasteAndApplyStyle(objSel, richText cTableMarkerString, 01704 getStyleForAttribute(o, AHeading)) 01705 01706 collapseSelection 01707 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace)) 01708 } 01709 /* *********************************************************************** 01710 function: wordDumpCellVBA() 01711 Description: 01712 **********************************************************************************/ 01713 void wordDumpCellVBA(OleAutoObj objCell, Object o, bool doNumber,string ObjValue) 01714 { 01715 string errMess = "" 01716 //Check cell access 01717 if (!canRead(o)) 01718 { 01719 return 01720 } 01721 vbaCheckRes(oleMethod(objCell, cMethodSelect)) 01722 collapseSelectionBackwards 01723 01724 //Get the attribute associated with the table (main column attribute) 01725 string attributeName = o.(reserved AMainColumnAttribute) 01726 if (null attributeName) 01727 { 01728 bool isPicture = hasPicture o 01729 bool hasText = hasCopyableText o 01730 bool hasHead = hasCopyableHeading o 01731 01732 if (isPicture) 01733 { 01734 hasText = false 01735 } 01736 01737 if (!hasText && !hasHead && !isPicture) 01738 { 01739 if (doNumber) 01740 { 01741 string s = number o 01742 01743 pasteAndApplyStyle(objSel, richText s, 01744 getStyleForAttribute(o,AHeading)) 01745 collapseSelection 01746 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace)) 01747 } 01748 01749 return 01750 } 01751 01752 01753 if (hasHead) 01754 { 01755 errMess = pasteHeading(objSel, o, doNumber) 01756 01757 if (!null errMess) 01758 { 01759 logError("Error pasting object heading of cell", errMess, o) 01760 } 01761 01762 collapseSelection 01763 01764 if (!hasText) 01765 { 01766 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace)) 01767 } 01768 } 01769 if (isPicture) 01770 { 01771 /* picture objects cannot have text */ 01772 if (hasCopyablePicture o) 01773 { 01774 // wordDumpPictureVBA(o,objSel,false) 01775 return 01776 } 01777 } 01778 if (hasText) 01779 { 01780 if (ObjValue!=null) 01781 { 01782 wordDumpBodyVBA(o, ObjValue) 01783 } 01784 else 01785 { 01786 wordDumpBodyVBA(o,null) 01787 } 01788 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace)) 01789 } 01790 } 01791 else 01792 { 01793 wordDumpTableAttributeVBA(o) 01794 } 01795 01796 } 01797 01798 /* *********************************************************************** 01799 function: wordDumpNamedCellVBA() 01800 Description: 01801 **********************************************************************************/ 01802 void wordDumpNamedCellVBA(OleAutoObj objCell, Object o, string attrInCell, string ObjValue) 01803 { 01804 Buffer textBuffer = create 01805 if (!canRead(o.attrInCell)) 01806 { 01807 return 01808 } 01809 01810 if (null (richTextWithOle o.attrInCell)) 01811 { 01812 return 01813 } 01814 01815 string errMess 01816 01817 vbaCheckRes(oleMethod(objCell, cMethodSelect)) 01818 collapseSelectionBackwards 01819 if (ObjValue==null) 01820 { 01821 01822 fullAttributeValueWithOle_(o,attrInCell,true,textBuffer) 01823 errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o,attrInCell)) 01824 } 01825 else 01826 { 01827 textBuffer =ObjValue 01828 errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o,attrInCell)) 01829 01830 } 01831 delete(textBuffer) 01832 if (!null errMess) 01833 { 01834 logError("Error pasting column attribute into table cell", errMess, o) 01835 } 01836 01837 collapseSelection 01838 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace)) 01839 } 01840 /* *********************************************************************** 01841 function: GetValue() 01842 Description: to fetch the value from the selected object and with the attribute name 01843 **********************************************************************************/ 01844 string GetValue(Object obj,string AttributeName_s, string s_Scriptpath) 01845 { 01846 string tsSub2 = null 01847 string tsSub = null 01848 01849 if(AttributeName_s == "Main") 01850 { 01851 if( obj."Object Heading""" == null) 01852 { 01853 tsSub2 = richTextWithOle obj."Object Text""" 01854 } 01855 else 01856 { 01857 tsSub2 = richTextWithOle obj."Object Heading""" 01858 } 01859 01860 } 01861 else if(AttributeName_s == "Object ID" || AttributeName_s == "Object Identifier") 01862 { 01863 tsSub2 = identifier(obj) 01864 } 01865 else 01866 { 01867 AttrDef ad = find(current Module, AttributeName_s) 01868 if(ad != null) 01869 { 01870 tsSub2 = obj.AttributeName_s"" 01871 } 01872 } 01873 if (s_Scriptpath!=null) 01874 { 01875 01876 tsSub2 = identifier(obj) 01877 s_Scriptpath = "\nattrDXLName3="tsSub2"" s_Scriptpath 01878 tsSub2 = eval_(s_Scriptpath) 01879 } 01880 01881 return tsSub2 01882 } 01883 /* *********************************************************************** 01884 function: exportTableLayoutRowHeader() 01885 Description: 01886 **********************************************************************************/ 01887 OleAutoObj exportTableLayoutRowHeader(Object o, OleAutoObj objTable, objCell) 01888 { 01889 Column c 01890 string s 01891 01892 for c in m do 01893 { 01894 objCell = nextCellVBA(objTable, objCell) 01895 01896 if (main c) 01897 { 01898 if (!canRead o) 01899 { 01900 // insert read locked string, as per DOORS display 01901 wordSetCellContentsVBA(objCell,o,cReadLockedDataMarker) 01902 } 01903 else 01904 { 01905 if (table o) 01906 { 01907 wordDumpTableCellMarkerVBA(objCell, o) 01908 } 01909 else 01910 { 01911 wordDumpCellVBA(objCell,o,includeHeadingNumbers && (!cell o),null) 01912 } 01913 } 01914 } 01915 else 01916 { 01917 string attrInCol = attrName c 01918 01919 if (isDumpableAttribute attrInCol) 01920 { 01921 wordDumpNamedCellVBA(objCell,o,attrInCol,null) 01922 } 01923 else 01924 { 01925 if (attrInCol == "Object Identifier") 01926 { 01927 s = text(c,o) 01928 } 01929 else 01930 { 01931 if (issueWarnings && containsUnregisteredOle(c, o)) { 01932 warningBox "Object " (identifier o) " contains one or more unregistered OLE objects.\n\nThese OLE objects will be exported as pictures." 01933 } 01934 s = richTextWithOle(c,o) 01935 } 01936 01937 if (null s) 01938 { 01939 continue 01940 } 01941 01942 wordSetCellContentsVBA(objCell,o,s) 01943 } 01944 } 01945 } 01946 01947 return objCell 01948 } 01949 /* *********************************************************************** 01950 function: exportTableLayoutRow() 01951 Description: 01952 **********************************************************************************/ 01953 OleAutoObj exportTableLayoutRow(Object o, OleAutoObj objTable, objCell, string StrColumnBookMarking_s[],int NumOfColumns_i,string StrColumn_s1[],bool b_FPresent) 01954 { 01955 Column c 01956 string s 01957 string ObjValue 01958 string colName_s 01959 string s_ParamsValue 01960 int i = 0 01961 01962 for c in m do 01963 { 01964 ObjValue ="" 01965 string s_Bookmarking1 = "" 01966 if(StrColumnBookMarking_s[i] == "true" || StrColumnBookMarking_s[i] == "True") 01967 { 01968 for s_ParamsValue in BookMarking do 01969 { 01970 01971 if (main c) 01972 { 01973 colName_s = "Main" 01974 } 01975 else 01976 { 01977 if (StrColumn_s1[i]!=null) 01978 { 01979 01980 colName_s = StrColumn_s1[i] 01981 } 01982 else 01983 { 01984 colName_s = attrName c 01985 } 01986 } 01987 01988 string s_key = key(BookMarking) 01989 bool keyMatches_b= matches(colName_s,s_key) 01990 if(keyMatches_b == true) 01991 { 01992 01993 if(reg2 s_ParamsValue) 01994 { 01995 string s_ParamsValue1 = s_ParamsValue[match 1] 01996 s_ParamsValue = GetValue(o,s_ParamsValue1,null) 01997 } 01998 if (StrColumn_s1[i]==null) 01999 { 02000 if(s_Bookmarking1 != null) 02001 { 02002 s_Bookmarking1 = s_Bookmarking1"_"s_ParamsValue 02003 } 02004 else 02005 { 02006 s_Bookmarking1 = s_ParamsValue 02007 } 02008 } 02009 else 02010 { 02011 // the bookmark has to be created by taking the field name for bookmark name 02012 s_Bookmarking= StrColumn_s1[i] 02013 if(s_Bookmarking != null) 02014 { 02015 02016 s_Bookmarking1 = s_Bookmarking1"_"s_ParamsValue 02017 } 02018 else 02019 { 02020 s_Bookmarking1 = s_ParamsValue 02021 } 02022 02023 } 02024 } 02025 } 02026 02027 } 02028 i++ 02029 02030 objCell = nextCellVBA(objTable, objCell) 02031 string FunctionList_s 02032 if (b_FPresent ==true) 02033 { 02034 string s_FunctionList1 = null 02035 string attrInCol = attrName c 02036 for FunctionList_s in FunctionList do 02037 { 02038 string AttributeName_s = key(FunctionList) 02039 if(attrInCol== AttributeName_s) 02040 { 02041 s_FunctionList1 = FunctionList_s 02042 ObjValue = GetValue(o,AttributeName_s,s_FunctionList1) 02043 break 02044 } 02045 02046 } 02047 02048 } 02049 if (main c) 02050 { 02051 if (!canRead o) 02052 { 02053 wordSetCellContentsVBA(objCell,o,cReadLockedDataMarker) 02054 02055 } 02056 02057 else 02058 { 02059 if (ObjValue!=null) 02060 { 02061 wordDumpCellVBA(objCell,o,includeHeadingNumbers && (!cell o),ObjValue) 02062 } 02063 wordDumpCellVBA(objCell,o,includeHeadingNumbers && (!cell o),null) 02064 } 02065 } 02066 else 02067 { 02068 string attrInCol = attrName c 02069 if (isDumpableAttribute attrInCol) 02070 { 02071 if (ObjValue!=null) 02072 { 02073 wordDumpNamedCellVBA(objCell,o,attrInCol,ObjValue) 02074 } 02075 else 02076 { 02077 wordDumpNamedCellVBA(objCell,o,attrInCol,null) 02078 } 02079 } 02080 else 02081 { 02082 if (attrInCol == "Object Identifier") 02083 { 02084 s = text(c,o) 02085 } 02086 else 02087 { 02088 if (issueWarnings && containsUnregisteredOle(c, o)) { 02089 warningBox "Object " (identifier o) " contains one or more unregistered OLE objects.\n\nThese OLE objects will be exported as pictures." 02090 } 02091 s = richTextWithOle(c,o) 02092 } 02093 02094 if (null s) 02095 { 02096 continue 02097 } 02098 02099 wordSetCellContentsVBA(objCell,o,s) 02100 } 02101 } 02102 if(s_Bookmarking1 != "") 02103 { 02104 02105 vbaCheckRes(oleMethod(objCell, cMethodSelect)) 02106 vbaCheckRes(oleGet(objCell, "Range", objCellRange)) 02107 OleAutoObj objBookMarks = null 02108 oleGet(objDoc, "Bookmarks", objBookmarks) 02109 clear objArgBlock 02110 put(objArgBlock, s_Bookmarking1) 02111 vbaCheckRes(oleMethod(objBookmarks, cMethodAdd, objArgBlock)) 02112 } 02113 } 02114 02115 return objCell 02116 } 02117 /* ************************************************************************************************************** 02118 function : convertMillimetersToPoints () 02119 Description: conversion of data 02120 ****************************************************************** ******************************************************/ 02121 int convertMillimetersToPoints( int milliMeters ) { 02122 // points = mm * ( 72.0 Points per Inch ) / ( 25.4 mm per Inch ) 02123 return intOf( realOf( milliMeters ) * ( 72.0 / 25.4 ) ) 02124 } 02125 /* ************************************************************************************************************** 02126 function : SetColumnWidth () 02127 Description: to set the column width as defined by the user in the XML configuration file 02128 ****************************************************************** ******************************************************/ 02129 void SetColumnWidth(OleAutoObj objColumn, int ColumnWidth_i){ 02130 clear objArgBlock 02131 put (objArgBlock, ColumnWidth_i) 02132 put (objArgBlock, 0) 02133 oleMethod(objColumn, "SetWidth", objArgBlock) // setwidth is a method used to set the column or cell width in a table 02134 } 02135 /* ************************************************************************************************************** 02136 function : AutoFitBehavior () 02137 Description: based on table cells contents or based on width of the document window, it resizes the table 02138 ****************************************************************** ******************************************************/ 02139 void AutoFitBehavior(OleAutoObj Table_ole){ 02140 clear objArgBlock 02141 put (objArgBlock, 1) 02142 checkRes (oleMethod (Table_ole, "AutoFitBehavior", objArgBlock)) 02143 } 02144 02145 /* ************************************************************************************************************** 02146 function : create_View () 02147 Description: if the Type=view this function is called and it will export the columns /attribute data into the word document 02148 ****************************************************************** ******************************************************/ 02149 void create_View(string StrColumn_s[],string StrColumn_s1[], string TableBookMarking_b,int ColWidth_i[], int NumOfColumns_i, bool AutoWidth_b, string StrColumnBookMarking_s[], string StrColHyperLinking_s[], bool b_FPresent){ 02150 02151 /* local Declarations */ 02152 int i //iterator 02153 string sErrorMessage = "" //Error Message 02154 string currObjType 02155 string nextObjType 02156 Column c //Column 02157 int NumberOfColumns_i //Number of Columns in Module 02158 int NumOfRows_i = 1 //Number of Rows 02159 int n = 0 //actual number of columns in view 02160 02161 int CountObjects_i = 0 02162 bool IsResetFormat_b 02163 OleAutoObj ViewTable_ole //OLE Object of ViewTable 02164 OleAutoObj Rows_ole //OLE Object of Rows 02165 OleAutoObj ActualCell_ole //OLE Object of actual cell 02166 OleAutoObj Columns_ole //OLE Object of Columns 02167 OleAutoObj Column_ole //OLE Object of Column 02168 02169 OleAutoArgs autoArgs =create //create autoArgs 02170 string StrColumn_s2[100] 02171 string s_FunctionList1 02172 string FunctionList_s 02173 string ObjValue 02174 02175 Object o = current Object 02176 m = current Module 02177 bool offest_b = false 02178 if (NumOfColumns_i < 1){ 02179 return "No Column match!" 02180 } 02181 for (i=0; i< NumOfColumns_i; i++) { 02182 if (StrColumn_s[i] != "Main" and StrColumn_s[i] != "Object Identifier" ) 02183 { 02184 if ( (exists attribute (StrColumn_s[i])) == false ){ 02185 sErrorMessage = sErrorMessage "Attribute " (StrColumn_s[i])" not exists!\n" 02186 } 02187 } 02188 } 02189 02190 02191 02192 if ( sErrorMessage != ""){ 02193 ack sErrorMessage 02194 halt 02195 } 02196 02197 /* delete all Columns in Moduleview */ 02198 for c in current Module do{ 02199 n++ 02200 } 02201 for i in 0:n do{ 02202 delete(column 0) 02203 } 02204 02205 /* Show selected Columns */ 02206 for (i = 0; i < NumOfColumns_i; i++){ 02207 c = insert(column i) 02208 if (StrColumn_s[i] != "Main") 02209 { 02210 attribute(c, StrColumn_s[i]) 02211 // GSTCS 442 implementation 02212 if (StrColumn_s1[i]!= null) 02213 { 02214 StrColumn_s2[i] = StrColumn_s1[i] 02215 } 02216 02217 else 02218 { 02219 StrColumn_s2[i] = StrColumn_s[i] 02220 } 02221 02222 } 02223 else 02224 { 02225 main(c) 02226 StrColumn_s2[i] = "Main" 02227 02228 } 02229 } 02230 02231 02232 /* Create Table with x Colums an y rows */ 02233 ViewTable_ole = wordMakeSizedTableVBA(1, NumOfColumns_i,TableBookMarking_b) 02234 02235 oleGet(ViewTable_ole, cPropertyRows, Rows_ole) 02236 oleGet(ViewTable_ole, cPropertyColumns, Columns_ole) 02237 02238 ActualCell_ole = wordGetNumberedCellVBA (ViewTable_ole, 1, 1) 02239 02240 if ( bMultipleHeader == false) 02241 { 02242 /* Add new Row */ 02243 oleMethod (Rows_ole, cMethodAdd) 02244 NumOfRows_i++ 02245 02246 /* Generate Title Row */ 02247 for (i = 0; i < NumOfColumns_i; i++){ 02248 ActualCell_ole = wordGetNumberedCellVBA(ViewTable_ole, 1, i+1) 02249 wordSetCellContentsVBA(ActualCell_ole, null, StrColumn_s2[i]) 02250 if(StrColHyperLinking_s[i] == "true") 02251 { 02252 02253 vbaCheckRes(oleMethod(ActualCell_ole, cMethodSelect)) 02254 collapseSelectionBackwards 02255 //This removes a carriage return from the table cell 02256 collapseSelection 02257 OleAutoObj objCellRange = null 02258 vbaCheckRes(oleGet(ActualCell_ole, "Range", objCellRange)) 02259 //delete(autoArgs) 02260 //Retrieve the bookmarks collection 02261 OleAutoObj objBookMarks = null 02262 oleGet(objDoc, "Bookmarks", objBookmarks) 02263 clear objArgBlock 02264 //insert the bookmark, with a specified tablebookmark name and the column count concatenated 02265 string s_Bookmarking=s_Tablename"Column"i_Count"" 02266 put(objArgBlock, s_Bookmarking) 02267 vbaCheckRes(oleMethod(objBookmarks, cMethodAdd, objArgBlock)) 02268 i_Count++ 02269 02270 } 02271 } 02272 setRowBorder() 02273 setRowFormatBoldGray() 02274 IsResetFormat_b = true 02275 } 02276 for o in m do{ 02277 if(offest_b == false) 02278 { 02279 offset_i = level(o) 02280 print offset_i 02281 offest_b = true 02282 } 02283 02284 CountObjects_i++ 02285 } 02286 02287 if (CountObjects_i == 0) 02288 { 02289 oleMethod(objSel,"MoveRight") 02290 oleMethod(objSel,"MoveDown") 02291 return 02292 } 02293 /* reset CountObject */ 02294 CountObjects_i = 0 02295 02296 02297 for o in m do 02298 { 02299 /* increase CountObject */ 02300 CountObjects_i++ 02301 02302 if (CountObjects_i > MAXROWNUMBER) 02303 { 02304 break 02305 } 02306 02307 if (exportCheckProgress) 02308 { 02309 break 02310 } 02311 exportStepProgress 02312 02313 if (row o) 02314 { 02315 continue 02316 } 02317 if (tableContents m) 02318 { 02319 if (table o) 02320 { 02321 continue 02322 } 02323 } 02324 else 02325 { 02326 if (cell o) 02327 { 02328 continue 02329 } 02330 } 02331 if ( (exists attribute ("ObjType")) == false) 02332 { 02333 currObjType = "R" 02334 nextObjType = "X" 02335 02336 if ((!null next o) and (level(o) < level(next o))) 02337 { 02338 currObjType = "H" 02339 if (!null next next o) 02340 { 02341 nextObjType = "H" 02342 } 02343 } 02344 } 02345 else 02346 { 02347 currObjType = o."ObjType""" 02348 if (!null next o) 02349 { 02350 nextObjType = (next o)."ObjType""" 02351 } 02352 else 02353 { 02354 nextObjType = "X" 02355 } 02356 } 02357 // Check if current object is a Header 02358 if (currObjType == "H") 02359 { 02360 //ActualCell_ole = exportTableLayoutRowHeader(o, ViewTable_ole, ActualCell_ole) 02361 ActualCell_ole = exportTableLayoutRowHeader(o, ViewTable_ole, ActualCell_ole) 02362 if (IsResetFormat_b) 02363 { 02364 setRowFormatNormal() 02365 } 02366 setRowBorder() 02367 if ((!null next o) and (nextObjType != "H")) 02368 IsResetFormat_b = true 02369 } 02370 else 02371 { 02372 // export the cell contents 02373 if (b_FPresent == true) 02374 { 02375 ActualCell_ole = exportTableLayoutRow(o, ViewTable_ole, ActualCell_ole,StrColumnBookMarking_s,NumOfColumns_i,StrColumn_s1,b_FPresent) 02376 } 02377 02378 else 02379 { 02380 ActualCell_ole = exportTableLayoutRow(o, ViewTable_ole, ActualCell_ole,StrColumnBookMarking_s,NumOfColumns_i,StrColumn_s1,null) 02381 } 02382 if (IsResetFormat_b) 02383 { 02384 setRowFormatNormal() 02385 } 02386 setRowBorder() 02387 } 02388 if ((!null next o) and (nextObjType == "H") and (level(next(o)) == 1)) 02389 { 02390 02391 oleMethod (Rows_ole, cMethodAdd) 02392 NumOfRows_i++ 02393 ActualCell_ole = insertBlankRow(ViewTable_ole, ActualCell_ole) 02394 setRowFontNormal() 02395 02396 } 02397 // Add new Row (Do not add row if last object (of the current set)) 02398 if (!null next o) 02399 { 02400 oleMethod (Rows_ole, cMethodAdd) 02401 NumOfRows_i++ 02402 if ((next o)."Object Text""" != "") 02403 { 02404 setRowFontNormalNextRow() 02405 } 02406 } 02407 02408 02409 } // End loop over all objects of current Module 02410 02411 if (AutoWidth_b==true) 02412 { 02413 clear autoArgs 02414 put (autoArgs, 1) 02415 oleMethod(ViewTable_ole, "AutoFitBehavior", autoArgs) 02416 } 02417 else 02418 { 02419 for (i = NumOfColumns_i-1 ; i >= 0; i--) 02420 { 02421 clear autoArgs 02422 put(autoArgs, i+1) 02423 oleMethod(Columns_ole, cMethodItem, autoArgs, Column_ole) 02424 if (ColWidth_i[i] > 0) 02425 { 02426 /* Convert Millimeters input to points */ 02427 //ColWidth_i[i] = convertMillimetersToPoints(ColWidth_i[i]) 02428 SetColumnWidth(Column_ole, ColWidth_i[i]) 02429 02430 } 02431 else 02432 { 02433 clear autoArgs 02434 put(autoArgs, 1) 02435 oleMethod(Column_ole, "AutoFit") 02436 } 02437 } 02438 } 02439 02440 /* if MAXROWNUMBER is reached print Hint */ 02441 if (CountObjects_i > MAXROWNUMBER){ 02442 //oleMethod (Rows_ole, cMethodAdd) 02443 NumOfRows_i++ 02444 ActualCell_ole = insertBlankRow(ViewTable_ole, ActualCell_ole) 02445 setRowFontNormal() 02446 wordSetCellContentsVBA(ActualCell_ole, null, "View exceeds max Numbers of Rows, only " MAXROWNUMBER " are displayed.") 02447 wordMergeRowVBA() 02448 oleGet(objSel, "Font", Font_ole) 02449 olePut(Font_ole, "Bold", true) 02450 setRowBorder() 02451 } 02452 02453 02454 02455 oleMethod(objSel,"MoveRight") 02456 oleMethod(objSel,"MoveDown") 02457 02458 // To close the tables array 02459 closeIfNonNull ViewTable_ole 02460 } 02461 /* ******************************************************* 02462 *function : FunctionforParam () 02463 *Description: the function to read the parameters mentioned for the function evocation(function post processing node) 02464 ************************************************************/ 02465 string FunctionforParam(OleAutoObj FParamList_ole, int NumOfParams_i) 02466 { 02467 OleAutoObj Params_ole=null 02468 int ParamIterator_i =0 02469 02470 string Param_s="" 02471 string sParameters ="" 02472 Buffer bParam= create 02473 02474 02475 if(NumOfParams_i != null) 02476 { 02477 for (ParamIterator_i = 0; ParamIterator_i < NumOfParams_i; ParamIterator_i++) 02478 { 02479 clear autoArgs 02480 put(autoArgs, ParamIterator_i) 02481 oleMethod(FParamList_ole, "Item", autoArgs, Params_ole) 02482 clear autoArgs 02483 put(autoArgs, "Param") 02484 oleMethod(Params_ole, "getAttribute", autoArgs, Param_s) 02485 02486 if(bParam ""!=null) 02487 { 02488 bParam = bParam"@#$%"Param_s 02489 } 02490 02491 else 02492 { 02493 02494 bParam =Param_s 02495 } 02496 sParameters = stringOf bParam 02497 02498 } 02499 delete bParam 02500 } 02501 02502 return sParameters 02503 02504 } 02505 /* ***************************************************************** 02506 function : ProcessTable () 02507 Description: the table attribute and the elements init will be processed like column text, width etc 02508 ******************************************************************/ 02509 02510 void ProcessTable(OleAutoObj Table_ole) 02511 { 02512 /* local declarations */ 02513 string ModuleName_s 02514 string Filtertext_s 02515 02516 string Type_s 02517 string StrColumn_s[100] 02518 string StrColumn_s1[100] 02519 02520 string TableStyle_s 02521 string Module_s 02522 string Filter_s 02523 string AutoWidth_s 02524 string Ancestors_s 02525 string Descendants_s 02526 OleAutoObj Columns_ole 02527 OleAutoObj ColumnList_ole 02528 OleAutoObj Column_ole 02529 string PrintTableInfo_s 02530 OleAutoObj FParamList_ole 02531 int NumOfColumns_i 02532 int ColWidth_i[100] 02533 bool AutoWidth_b 02534 int ColumnsIterator_i 02535 string Columnwidth_s //GSTCS 442 02536 int Columnwidth_i //GSTCS 442 02537 int NumOfParams_i 02538 string Attrname_s 02539 string Fieldname_s 02540 string ColHyperLinking_s 02541 string StrColHyperLinking_s[100] 02542 string ParamValue_s 02543 OleAutoObj BookMarkingAttr_ole 02544 OleAutoObj ParamList_ole 02545 int Param_i =0 02546 int ParamsIterator_i 02547 OleAutoObj Params_ole 02548 string Param_s 02549 string ColBookMarking[100] 02550 string TableBookMarking_s= null 02551 // bool TableBookMarking_b = false 02552 string TableBookMarking_b 02553 OleAutoObj FileList_ole 02554 OleAutoObj FunctionList_ole 02555 string sParamstr 02556 string FilePath_s ="" 02557 string FunctionList_s 02558 string s_FunctionList 02559 string ObjValue 02560 bool b_Tablebookmark = false 02561 02562 styleName = vbaGetStyleName(objDoc,wdStyleNormal) 02563 02564 /* get Path of Module */ 02565 clear autoArgs 02566 put( autoArgs, "Module") 02567 oleMethod(Table_ole, "getAttribute", autoArgs, ModuleName_s) 02568 clear autoArgs 02569 put( autoArgs, "Filtertext") 02570 oleMethod(Table_ole, "getAttribute", autoArgs, Filtertext_s) 02571 clear autoArgs 02572 put( autoArgs, "Ancestors") 02573 oleMethod(Table_ole, "getAttribute", autoArgs, Ancestors_s) 02574 02575 clear autoArgs 02576 put( autoArgs, "Descendants") 02577 oleMethod(Table_ole, "getAttribute", autoArgs, Descendants_s) 02578 clear autoArgs 02579 put( autoArgs, "Description") 02580 oleMethod(Table_ole, "getAttribute", autoArgs, Description_s) 02581 clear autoArgs 02582 put( autoArgs, "Type") 02583 oleMethod(Table_ole, "getAttribute", autoArgs, Type_s) 02584 02585 02586 clear autoArgs 02587 put( autoArgs, "PrintTableInfo") 02588 oleMethod(Table_ole, "getAttribute", autoArgs, PrintTableInfo_s) 02589 02590 clear autoArgs 02591 put( autoArgs, "TableBookmarking") 02592 oleMethod(Table_ole, "getAttribute", autoArgs, TableBookMarking_s) 02593 02594 /*currently the tablestyle is not used*/ 02595 clear autoArgs 02596 put(autoArgs, "Style") 02597 oleMethod(Table_ole, "getAttribute", autoArgs, TableStyle_s) 02598 02599 if (TableBookMarking_s!=null || TableBookMarking_s!="") 02600 { 02601 b_Tablebookmark =true 02602 TableBookMarking_b = TableBookMarking_s 02603 02604 } 02605 02606 else 02607 { 02608 b_Tablebookmark =false 02609 02610 } 02611 02612 /* get autoStyle for table */ 02613 02614 clear autoArgs 02615 put(autoArgs, "Columns") 02616 oleMethod(Table_ole, "selectSingleNode", autoArgs, Columns_ole) 02617 02618 clear autoArgs 02619 put (autoArgs, "Autowidth") 02620 oleMethod(Columns_ole, "getAttribute", autoArgs, AutoWidth_s) 02621 02622 02623 clear autoArgs 02624 put(autoArgs, "Column") 02625 oleMethod(Columns_ole, "selectNodes", autoArgs, ColumnList_ole) 02626 02627 oleGet(ColumnList_ole, "Length", NumOfColumns_i) 02628 02629 02630 if (!CheckModuleOpen(ModuleName_s)) 02631 { 02632 print "Can not open Module " ModuleName_s ".\n" 02633 return 02634 } 02635 02636 02637 filtering off 02638 02639 /* get Filter */ 02640 if (!null Filtertext_s || Filtertext_s != "") 02641 { 02642 f = parseFilter(Filtertext_s) 02643 if ((Ancestors_s == "true") || (Ancestors_s == "True") || (Ancestors_s == "1")) 02644 { 02645 ancestors(true) 02646 } 02647 else 02648 { 02649 ancestors(false) 02650 } 02651 if ((Descendants_s == "true") || (Descendants_s == "True") || (Descendants_s == "1")) 02652 { 02653 descendants(true) 02654 } 02655 else 02656 { 02657 descendants(false) 02658 } 02659 /* activate Filter */ 02660 set (m,f,accepted,rejected) 02661 filtering on 02662 } 02663 else 02664 { 02665 Filtertext_s = "No Filter defined" 02666 } 02667 if ( PrintTableInfo_s =="true") 02668 { 02669 /* print Modulename */ 02670 Module_s = "Module: " ModuleName_s "\n" 02671 pasteAndApplyStyle(objSel, richText Module_s, bodyStyleNames[0]) 02672 /* print Filtername */ 02673 Filter_s = "Filter: " Filtertext_s "\t Ancestors: " Ancestors_s "\t Descendants: " Descendants_s "\n" 02674 pasteAndApplyStyle(objSel, richText Filter_s, bodyStyleNames[0]) 02675 02676 } 02677 else 02678 { 02679 //string s_errmess = "PrintTableinfo is false \n" 02680 //pasteAndApplyStyle(objSel, richText s_errmess, bodyStyleNames[0]) 02681 } 02682 02683 if ((!null AutoWidth_s) and ((AutoWidth_s == "true") or (AutoWidth_s == "True") or (AutoWidth_s == "1"))){ 02684 AutoWidth_b = true 02685 } 02686 else{ 02687 AutoWidth_b = false 02688 } 02689 /* get Columns */ 02690 for (ColumnsIterator_i = 0; ColumnsIterator_i < NumOfColumns_i; ColumnsIterator_i++) 02691 { 02692 clear autoArgs 02693 put(autoArgs, ColumnsIterator_i) 02694 oleMethod(ColumnList_ole, "Item", autoArgs, Column_ole) 02695 clear autoArgs 02696 02697 put(autoArgs, "Attributename") 02698 oleMethod(Column_ole, "getAttribute", autoArgs,Attrname_s) 02699 StrColumn_s[ColumnsIterator_i] = Attrname_s 02700 02701 clear autoArgs 02702 put(autoArgs, "FieldName") 02703 oleMethod(Column_ole, "getAttribute", autoArgs, Fieldname_s) //GSTCS 442 02704 StrColumn_s1[ColumnsIterator_i] = Fieldname_s 02705 02706 clear autoArgs 02707 put(autoArgs, "Columnwidth") 02708 oleMethod(Column_ole, "getAttribute", autoArgs, Columnwidth_s) //GSTCS 442 02709 if (Columnwidth_s!=null) 02710 { 02711 Columnwidth_i = intOf(Columnwidth_s) 02712 ColWidth_i[ColumnsIterator_i] = Columnwidth_i 02713 } 02714 02715 clear autoArgs 02716 put(autoArgs, "ColHyperLinking") 02717 oleMethod(Column_ole, "getAttribute", autoArgs, ColHyperLinking_s) 02718 02719 clear autoArgs 02720 put(autoArgs, "Function_Post_Processing") 02721 oleMethod(Column_ole, "selectSingleNode", autoArgs, FunctionList_ole) 02722 02723 if (FunctionList_ole != null) 02724 { 02725 02726 b_FPresent = true 02727 clear autoArgs 02728 put(autoArgs, "Params") 02729 oleMethod(FunctionList_ole, "selectNodes", autoArgs, FParamList_ole) 02730 if(FParamList_ole != null) 02731 { 02732 02733 oleGet(FParamList_ole, "Length", NumOfParams_i) 02734 sParamstr= FunctionforParam(FParamList_ole,NumOfParams_i) 02735 } 02736 02737 02738 clear autoArgs 02739 put(autoArgs, "Filepath") 02740 oleMethod(FunctionList_ole, "selectSingleNode", autoArgs, FileList_ole) 02741 oleGet(FileList_ole, "text", FilePath_s) 02742 FunctionList_s = "\nattrDXLName1 = \"" sParamstr "\"\nattrDXLName2 = \"" Attrname_s "\" \n#include <"FilePath_s">" 02743 put(FunctionList,Attrname_s,FunctionList_s) 02744 02745 } 02746 if(!null ColHyperLinking_s) 02747 { 02748 StrColHyperLinking_s[ColumnsIterator_i] = ColHyperLinking_s 02749 } 02750 else 02751 { 02752 StrColHyperLinking_s[ColumnsIterator_i] = "false" 02753 } 02754 02755 clear autoArgs 02756 put(autoArgs, "BookMarkingAttr") 02757 oleMethod(Column_ole, "selectSingleNode", autoArgs, BookMarkingAttr_ole) 02758 if(BookMarkingAttr_ole != null) 02759 { 02760 02761 clear autoArgs 02762 put(autoArgs, "Params") 02763 oleMethod(BookMarkingAttr_ole, "selectNodes", autoArgs, ParamList_ole) 02764 if(ParamList_ole != null) 02765 { 02766 02767 oleGet(ParamList_ole, "Length", Param_i) 02768 } 02769 02770 02771 if(Param_i != 0) 02772 { 02773 for (ParamsIterator_i = 0; ParamsIterator_i < Param_i; ParamsIterator_i++) 02774 { 02775 02776 clear autoArgs 02777 put(autoArgs, ParamsIterator_i) 02778 oleMethod(ParamList_ole, "Item", autoArgs, Params_ole) 02779 clear autoArgs 02780 put(autoArgs, "Param") 02781 oleMethod(Params_ole, "getAttribute", autoArgs, Param_s) 02782 if (Fieldname_s != null) 02783 { 02784 //put(BookMarking,Fieldname_s"_"ParamsIterator_i"",Param_s) 02785 put(BookMarking,Fieldname_s"_"ParamsIterator_i"",Param_s) 02786 } 02787 else 02788 { 02789 //put(BookMarking,Attrname_s"_"ParamsIterator_i"",Param_s) 02790 put(BookMarking,Attrname_s"_"ParamsIterator_i"",Param_s) 02791 } 02792 ColBookMarking[ColumnsIterator_i]="true" 02793 } 02794 //ColBookMarking[ColumnsIterator_i] = "true" 02795 } 02796 } 02797 else 02798 { 02799 ColBookMarking[ColumnsIterator_i] = "false" 02800 } 02801 02802 } 02803 if ((Type_s == "View") || (Type_s == "V") || (Type_s == "v")) 02804 { 02805 if (b_Tablebookmark==true ) 02806 { 02807 create_View(StrColumn_s,StrColumn_s1,TableBookMarking_b,ColWidth_i,NumOfColumns_i,AutoWidth_b,ColBookMarking,StrColHyperLinking_s,b_FPresent) 02808 } 02809 else 02810 { 02811 02812 create_View(StrColumn_s,StrColumn_s1,null,ColWidth_i,NumOfColumns_i,AutoWidth_b,ColBookMarking,StrColHyperLinking_s,b_FPresent) 02813 } 02814 } 02815 } 02816 bool process_leaves( int deep, Object oLeaf, Column col, int Ycoord, Skip refList, string colGroup, string Attribute_s[], string Heading_s[], Array &arrResult) 02817 { 02818 string s, strValue, strNewGroup 02819 int refIdx 02820 Regexp matchHeading = regexp Heading_s[deep-1] // Note: array started by 0, but from user point ov view we start by 1 02821 Regexp matchAttribute = regexp Attribute_s[deep-1] // Note: array started by 0, but from user point ov view we start by 1 02822 02823 if (debug == 1) 02824 { 02825 print "process_leaves:\t"Ycoord"\t"colGroup"\n" 02826 } 02827 02828 while ( ! null oLeaf) 02829 { 02830 if (leaf oLeaf) 02831 { 02832 s = oLeaf."Object Heading" 02833 if ( s == "") // if heading is empty use text as value 02834 { 02835 s = oLeaf."Object Text" 02836 } 02837 02838 if ((length(Attribute_s[deep-1]) > 1 ) && matchAttribute s ) 02839 { 02840 strNewGroup=new_col_group(colGroup, s) 02841 02842 strValue = oLeaf.(attrName col)"" 02843 02844 if (debug == 1) 02845 { 02846 print "\t\t"s"\t"strValue"\n" 02847 } 02848 02849 // check if heading is already known. 02850 // If yes, print value in same column as before 02851 // otherwise append column 02852 if (find(refList,strNewGroup,refIdx)) 02853 { 02854 put(arrResult,strValue, refIdx, Ycoord) 02855 } 02856 else 02857 { 02858 if (arrResultX_size >= 255) 02859 { 02860 strError = "Sorry, but the script supports no more than 255 columns (attributes).\nPlease add an appropriate filter!" 02861 return false 02862 } 02863 put(refList,strNewGroup,arrResultX_size) 02864 if (! null colGroup) // fill first row 02865 { 02866 put(arrResult,colGroup,arrResultX_size+0,0) 02867 } 02868 put(arrResult,s,arrResultX_size+0,1) // add title to 2nd row 02869 put(arrResult,strValue, arrResultX_size++, Ycoord) // and finally the value 02870 } 02871 } 02872 } 02873 else 02874 { 02875 s = oLeaf."Object Heading" 02876 strNewGroup=new_col_group(colGroup, s) 02877 if ((length(Heading_s[deep-1]) > 1 ) && matchHeading s ) 02878 { 02879 if (!process_leaves( deep+1, first oLeaf, col, Ycoord, refList, strNewGroup, Attribute_s, Heading_s, arrResult )) 02880 { 02881 return false 02882 } 02883 } 02884 } 02885 oLeaf = next sibling oLeaf 02886 } // while 02887 return true 02888 } // process_leaves 02889 02890 void Transpose(string Value_s, string Attribute_s[], string Heading_s[], Object oFather, Array &arrResult) 02891 { 02892 Module mSource = current 02893 Column c 02894 string s, s1, s2 02895 string strMasterHeading = oFather."Object Heading" 02896 const string strEmpty = "" 02897 string strError 02898 Object oChild = first oFather 02899 Object oGrandChild 02900 Object oRoot 02901 Object oLeaf 02902 02903 bool mainSeen = false 02904 int NoOfValueColumns = 0 02905 bool PrintValueTitle = true 02906 bool OnlyOneValueColumn = true 02907 02908 arrResultX = 0; 02909 arrResultY = 0; 02910 arrResultX_size = 0; 02911 arrResultY_size = 0; 02912 02913 02914 // 02915 // now get some values from the GUI 02916 strMatchValues = Value_s 02917 02918 // 02919 // Before we start with the real work, it must be ensured 02920 // that at least two sub chapter levels exist 02921 if (null oChild) 02922 { 02923 strError = "Current object has no children.\n" 02924 } 02925 // else if (null first oChild) 02926 // { 02927 // strError = "Current object has no grand children.\n" 02928 // } 02929 else 02930 { 02931 Skip refList = create 02932 string strTitle 02933 oRoot = oChild // oRoot is the first child and we have to start here for each value 02934 arrResultY = 0 02935 int deep = 0; 02936 02937 // If we have to print the column header of the values field in the first column, 02938 // we have to start in column 2 with the chapter titles, otherwise in column 1 02939 if (PrintValueTitle) 02940 { 02941 arrResultX_size = 2; 02942 } 02943 else 02944 { 02945 arrResultX_size = 1; 02946 } 02947 02948 for c in mSource do // Loop over all columns 02949 { 02950 oChild = oRoot 02951 deep = 2 02952 // as long as we do not see the main column all columns are skipped 02953 // after the main column has been processed, all further columns are treaded as value columns 02954 02955 if (main c) // print table headers 02956 { 02957 mainSeen = true 02958 arrResultY = 2 // 1st row group, 2nd row title 02959 continue 02960 } 02961 02962 if ( !mainSeen) 02963 { 02964 continue 02965 } 02966 02967 strTitle = (title c) 02968 if ( ! matches(strMatchValues, strTitle)) 02969 { 02970 continue; 02971 } 02972 02973 NoOfValueColumns++ 02974 02975 while ( ! null oChild) 02976 { 02977 arrResultX=0 02978 if (PrintValueTitle) 02979 { 02980 put(arrResult,strTitle, arrResultX++, arrResultY) 02981 } 02982 s = oChild."Object Heading" 02983 if(s == "") 02984 { 02985 s = oChild."Object Text" 02986 02987 } 02988 put(arrResult,s, arrResultX++, arrResultY) 02989 oGrandChild = first oChild 02990 02991 if (!process_leaves(deep+1,oGrandChild, c, arrResultY, refList, strMasterHeading, Attribute_s, Heading_s, arrResult)) 02992 { 02993 break; 02994 } 02995 02996 oChild = next sibling oChild 02997 arrResultY++ 02998 }// while child 02999 03000 if (OnlyOneValueColumn ) 03001 { 03002 break 03003 } 03004 } // column 03005 03006 arrResultY_size = arrResultY 03007 } 03008 } //DoApply 03009 string GetLevelNumber(string Level_s, int Level_i){ 03010 Buffer Level_buf = create 03011 int len = length(Level_s) 03012 int i 03013 int LevelCount_i= 0 03014 string ReturnLevel_s 03015 for (i = 0; i < len; i++){ 03016 if(Level_s[i] == '.'){ 03017 LevelCount_i++ 03018 } 03019 if(LevelCount_i < Level_i) 03020 Level_buf += Level_s[i] 03021 else{ 03022 ReturnLevel_s = stringOf(Level_buf) 03023 break 03024 } 03025 } 03026 return ReturnLevel_s 03027 } 03028 void ProcessTranspose(OleAutoObj Transpose_ole){ 03029 OleAutoObj Heading_ole 03030 OleAutoObj Attribute_ole 03031 OleAutoObj RegexpList_ole 03032 OleAutoObj Regexp_ole 03033 OleAutoObj Value_ole 03034 string ModuleName_s 03035 string Filtertext_s 03036 string Ancestors_s 03037 string Descendants_s 03038 string Description_s 03039 string Regexp_s 03040 string Level_s 03041 string Value_s 03042 string ObjectNo_s 03043 string sLastValue 03044 string SheetName_s 03045 int NumberOfRegexp_i 03046 int Iterator_i 03047 int Iterator_x 03048 int Iterator_y 03049 int ObjectNo_i 03050 string Heading_s[10] = {".*",".*",".*",".*",".*",".*",".*",".*",".*",".*"} 03051 string Attribute_s[10] = {".*",".*",".*",".*",".*",".*",".*",".*",".*",".*"} 03052 Object EntryObject_o 03053 Array arrResult = create(1,1) 03054 03055 clear autoArgs 03056 put( autoArgs, "Module") 03057 oleMethod(Transpose_ole, "getAttribute", autoArgs, ModuleName_s) 03058 clear autoArgs 03059 put( autoArgs, "Filtertext") 03060 oleMethod(Transpose_ole, "getAttribute", autoArgs, Filtertext_s) 03061 clear autoArgs 03062 put( autoArgs, "Ancestors") 03063 oleMethod(Transpose_ole, "getAttribute", autoArgs, Ancestors_s) 03064 clear autoArgs 03065 put( autoArgs, "Descendants") 03066 oleMethod(Transpose_ole, "getAttribute", autoArgs, Descendants_s) 03067 clear autoArgs 03068 put( autoArgs, "Description") 03069 oleMethod(Transpose_ole, "getAttribute", autoArgs, Description_s) 03070 clear autoArgs 03071 put( autoArgs, "ObjectNo") 03072 oleMethod(Transpose_ole, "getAttribute", autoArgs, ObjectNo_s) 03073 clear autoArgs 03074 put( autoArgs, "SheetName") 03075 oleMethod(Transpose_ole, "getAttribute", autoArgs, SheetName_s) 03076 ObjectNo_i = str2int(ObjectNo_s) 03077 clear autoArgs 03078 put(autoArgs, "Heading") 03079 oleMethod(Transpose_ole, "selectSingleNode", autoArgs, Heading_ole) 03080 clear autoArgs 03081 put(autoArgs, "Regexp") 03082 oleMethod(Heading_ole, "selectNodes", autoArgs, RegexpList_ole) 03083 oleGet(RegexpList_ole, "Length", NumberOfRegexp_i) 03084 for (Iterator_i = 0; Iterator_i < NumberOfRegexp_i; Iterator_i++){ 03085 clear autoArgs 03086 put(autoArgs, Iterator_i) 03087 oleMethod(RegexpList_ole, "Item", autoArgs, Regexp_ole) 03088 clear autoArgs 03089 put (autoArgs, "Text") 03090 oleMethod(Regexp_ole, "getAttribute", autoArgs, Regexp_s) 03091 clear autoArgs 03092 put (autoArgs, "Level") 03093 oleMethod(Regexp_ole, "getAttribute", autoArgs, Level_s) 03094 Level_i = str2int(Level_s)-1 03095 Heading_s[Level_i] = Regexp_s 03096 } 03097 clear autoArgs 03098 put(autoArgs, "Attribute") 03099 oleMethod(Transpose_ole, "selectSingleNode", autoArgs, Attribute_ole) 03100 clear autoArgs 03101 put(autoArgs, "Regexp") 03102 oleMethod(Attribute_ole, "selectNodes", autoArgs, RegexpList_ole) 03103 oleGet(RegexpList_ole, "Length", NumberOfRegexp_i) 03104 for (Iterator_i = 0; Iterator_i < NumberOfRegexp_i; Iterator_i++){ 03105 clear autoArgs 03106 put(autoArgs, Iterator_i) 03107 oleMethod(RegexpList_ole, "Item", autoArgs, Regexp_ole) 03108 clear autoArgs 03109 put (autoArgs, "Text") 03110 oleMethod(Regexp_ole, "getAttribute", autoArgs, Regexp_s) 03111 clear autoArgs 03112 put (autoArgs, "Level") 03113 oleMethod(Regexp_ole, "getAttribute", autoArgs, Level_s) 03114 Level_i = str2int(Level_s)-1 03115 Attribute_s[Level_i] = Regexp_s 03116 } 03117 clear autoArgs 03118 put(autoArgs, "Value") 03119 oleMethod(Transpose_ole, "selectSingleNode", autoArgs, Value_ole) 03120 clear autoArgs 03121 put(autoArgs, "Attribute") 03122 oleMethod(Value_ole, "getAttribute", autoArgs, Value_s) 03123 03124 /* open module */ 03125 if (!CheckModuleOpen(ModuleName_s)){ 03126 print "Can not open Module " ModuleName_s ".\n" 03127 return 03128 } 03129 if (!exists attribute Value_s){ 03130 ack ("Attribute " Value_s " doesn't exists, Skip this Transpose.") 03131 return 03132 } 03133 03134 /* set filter */ 03135 filtering off 03136 if (!null Filtertext_s || Filtertext_s != ""){ 03137 f = parseFilter(Filtertext_s) 03138 if ((Ancestors_s == "true") || (Ancestors_s == "True") || (Ancestors_s == "1")){ 03139 ancestors(true) 03140 } 03141 else{ 03142 ancestors(false) 03143 } 03144 if ((Descendants_s == "true") || (Descendants_s == "True") || (Descendants_s == "1")){ 03145 descendants(true) 03146 } 03147 else{ 03148 descendants(false) 03149 } 03150 /* activate Filter */ 03151 set (m,f,accepted,rejected) 03152 filtering on 03153 } 03154 else{ 03155 Filtertext_s = "No Filter defined" 03156 } 03157 EntryObject_o = object(ObjectNo_i, m) 03158 if (!null EntryObject_o){ 03159 /* call transpose */ 03160 Transpose(Value_s, Attribute_s, Heading_s, EntryObject_o, arrResult) 03161 /* new Worksheet in Excel */ 03162 if (!null SheetName_s){ 03163 ExcelNewSheet(SheetName_s) 03164 } 03165 else{ 03166 ExcelNewSheet("") 03167 } 03168 /* Print in Excel Sheet */ 03169 for arrResultY in 1:arrResultY_size do{ 03170 sLastValue = "" 03171 for arrResultX in 1:arrResultX_size do{ 03172 string s = get(arrResult, arrResultX-1, arrResultY-1) 03173 03174 // In case only one Value column is porcessed, we do 03175 // not print the title of the Value column in the first column 03176 03177 if (arrResultX > 1) 03178 { 03179 // for the first (group) line print only a value if it 03180 // differs from the previuos column 03181 if ((s != sLastValue) || (arrResultY > 1)) 03182 { 03183 ExcelPut(arrResultX-1,arrResultY,s) 03184 sLastValue = s 03185 } 03186 } 03187 else if (arrResultY == 3) 03188 { 03189 ExcelPut(1,1,s) 03190 } 03191 } 03192 } 03193 } 03194 else{ 03195 ack("Object not found!") 03196 return 03197 } 03198 delete arrResult 03199 } // ProcessTranspose 03200 03201 03202 /* ***************************************************************** 03203 function : HandleSection () 03204 Description: XMl file reading for looping of sections information and table etc 03205 ******************************************************************/ 03206 void HandleSection(OleAutoObj Section_ole, int SectionStructureLevel_i){ 03207 /* SectionStructureLevel denotes the Level of the Section. Example: 3.2.1 has Level 3 */ 03208 int NumOfTables_i //Number of Tables defines in XML 03209 int NumOfSections_i //Number of Sections in this Section 03210 int Iterator_i 03211 string Headline_s //Headline for Chapter/Section 03212 string Text_s //Plaintext 03213 Buffer SectionStructure_s = create //String of Sections Structure 03214 OleAutoObj TableList_ole //List of Tables 03215 OleAutoObj SectionList_ole //List of Section in Chapter 03216 OleAutoObj Table_ole //Table 03217 SectionStructureLevel_i =0 03218 int SectionIterator_i 03219 OleAutoObj TransposeList_ole 03220 OleAutoObj Transpose_ole 03221 int NumOfTranspose_i 03222 03223 bool InitExcel_b = false 03224 SectionStructureLevel_i1 = SectionStructureLevel_i 03225 Level_i =SectionStructureLevel_i1 03226 clear autoArgs 03227 put(autoArgs,"Headline") 03228 oleMethod(Section_ole, "getAttribute", autoArgs, Headline_s) 03229 /* Get Text */ 03230 clear autoArgs 03231 put(autoArgs,"Text") 03232 oleMethod(Section_ole, "getAttribute", autoArgs, Text_s) 03233 /* Get Table List */ 03234 clear autoArgs 03235 put(autoArgs,"Table") 03236 oleMethod(Section_ole, "selectNodes", autoArgs, TableList_ole) 03237 /* get Section List */ 03238 clear autoArgs 03239 put(autoArgs,"Section") 03240 oleMethod(Section_ole, "selectNodes", autoArgs, SectionList_ole) 03241 03242 03243 03244 if (!InitWord_b){ 03245 /* Init Word */ 03246 InitWord() 03247 InitWord_b = true 03248 } 03249 03250 //if (Headline_s != "") 03251 // { 03252 MakeSection(Headline_s, Text_s, stringOf(SectionStructure_s),SectionStructureLevel_i) 03253 // } 03254 03255 /* get Numbers of Tables in Section */ 03256 oleGet(TableList_ole, "Length", NumOfTables_i) 03257 if (NumOfTables_i > 0){ 03258 for (Iterator_i = 0; Iterator_i < NumOfTables_i; Iterator_i++){ 03259 clear autoArgs 03260 put(autoArgs, Iterator_i ) 03261 oleMethod(TableList_ole, "Item", autoArgs, Table_ole) 03262 ProcessTable(Table_ole) 03263 } 03264 } 03265 03266 /* get Number of Transpose in Section */ 03267 03268 /* get Number of Sections */ 03269 oleGet(SectionList_ole, "Length", NumOfSections_i) 03270 if (NumOfSections_i > 0){ 03271 for (SectionIterator_i = 0; SectionIterator_i < NumOfSections_i; SectionIterator_i++){ 03272 clear autoArgs 03273 put(autoArgs, SectionIterator_i ) 03274 oleMethod(SectionList_ole, "Item", autoArgs, Section_ole) 03275 HandleSection(Section_ole, SectionStructureLevel_i + 1) 03276 } 03277 } 03278 } 03279 /* ***************************************************************** 03280 function : GetFilterFromXML () 03281 Description: XMl file reading for fetching the filters, section information 03282 ******************************************************************/ 03283 void GetFilterFromXML(){ 03284 /* local declaration */ 03285 03286 int NumOfSections_i //Number of all Sections in Chapter 03287 int IterateSection_i //Section iterator 03288 OleAutoObj SectionList_ole //List of Section in Chapter 03289 OleAutoObj Section_ole //actual Section 03290 03291 int MacroIterator_i 03292 int NumOfMacros_i 03293 OleAutoObj Macronames_ole 03294 OleAutoObj Macros_ole 03295 OleAutoObj MacrosList_ole 03296 string Macroname_s 03297 OleAutoObj TransposeList_ole 03298 int NumOfTranspose_i 03299 int Iterator_i 03300 OleAutoObj Transpose_ole 03301 bool InitExcel_b = false 03302 03303 /* Get List of Sections */ 03304 clear autoArgs 03305 put(autoArgs, "Section") 03306 oleMethod(Root_ole, "selectNodes", autoArgs, SectionList_ole) 03307 03308 /* Get Number of Sections */ 03309 oleGet(SectionList_ole, "length", NumOfSections_i) 03310 03311 /* iterate over all Sections */ 03312 for (IterateSection_i = 0; IterateSection_i < NumOfSections_i; IterateSection_i++) 03313 { 03314 clear autoArgs 03315 put(autoArgs,IterateSection_i) 03316 oleMethod(SectionList_ole, "Item", autoArgs, Section_ole) 03317 03318 HandleSection(Section_ole,0) 03319 } 03320 03321 clear autoArgs 03322 put(autoArgs,"Transpose") 03323 oleMethod(Root_ole, "selectNodes", autoArgs, TransposeList_ole) 03324 03325 oleGet(TransposeList_ole, "Length", NumOfTranspose_i) 03326 if (NumOfTranspose_i > 0) 03327 { 03328 if (!InitExcel_b){ 03329 ExcelInit(true) 03330 InitExcel_b=true 03331 } 03332 for (Iterator_i = 0; Iterator_i < NumOfTranspose_i; Iterator_i++){ 03333 clear autoArgs 03334 put(autoArgs, Iterator_i ) 03335 oleMethod(TransposeList_ole, "Item", autoArgs, Transpose_ole) 03336 ProcessTranspose(Transpose_ole) 03337 } 03338 } 03339 //GSTCS-445 implementation for call back hook of macros 03340 clear autoArgs 03341 put(autoArgs, "Macros") 03342 oleMethod(Root_ole, "selectSingleNode", autoArgs, Macros_ole) 03343 if (Macros_ole!=null) 03344 { 03345 03346 clear autoArgs 03347 put(autoArgs, "macronames") 03348 oleMethod(Macros_ole, "selectNodes", autoArgs, MacrosList_ole) 03349 if (MacrosList_ole!=null) 03350 { 03351 oleGet(MacrosList_ole, "Length", NumOfMacros_i) 03352 03353 for (MacroIterator_i = 0; MacroIterator_i < NumOfMacros_i;MacroIterator_i++) 03354 { 03355 clear autoArgs 03356 put(autoArgs, MacroIterator_i) 03357 oleMethod(MacrosList_ole, "Item", autoArgs, Macronames_ole) 03358 clear autoArgs 03359 put(autoArgs, "macroname") 03360 oleMethod(Macronames_ole, "getAttribute", autoArgs, Macroname_s) 03361 03362 if (Macroname_s!="" || Macroname_s!=null) 03363 { 03364 clear objArgBlock 03365 put (objArgBlock, "MacroName", Macroname_s) 03366 checkRes (oleMethod (objWord, "Run", objArgBlock)) 03367 03368 } 03369 } 03370 } 03371 } 03372 //clear objArgBlock 03373 //put (objArgBlock, "MacroName", "CreateHyperlinK") 03374 //checkRes (oleMethod (objWord, "Run", objArgBlock)) 03375 03376 UpdateTOC() 03377 } 03378 03379 /* ***************************************************************** 03380 function : initXML () 03381 Description: XMl file reading 03382 ******************************************************************/ 03383 bool initXML(){ 03384 03385 string Template_s 03386 string BaselineEnabled_s 03387 03388 /* Load XML with filter description */ 03389 clear autoArgs 03390 put(autoArgs,ConfigFileName_s) 03391 oleMethod(xmldoc, "Load", autoArgs) 03392 03393 /* Get root element from xmldoc */ 03394 oleGet(xmldoc, "documentElement", Root_ole) 03395 03396 if (null Root_ole) 03397 { 03398 ack "Can not get root element in XML configuration file.\n\nConfig file: "ConfigFileName_s"\n\nPlease check wellformess of XML file and validate it with an XML Editor!" 03399 return false 03400 } 03401 03402 /* get Template File */ 03403 clear autoArgs 03404 put(autoArgs, "Template") 03405 oleMethod(Root_ole, "getAttribute", autoArgs, TemplateFileName_s) 03406 /* check Template */ 03407 if ((TemplateFileName_s != "") and (canOpenFile(TemplateFileName_s, false))) 03408 { 03409 TemplateFileName_s = TemplateFileName_s 03410 } 03411 else 03412 { 03413 ack("Template should be in openable mode\n" ) 03414 halt 03415 return false; 03416 03417 } 03418 03419 clear autoArgs 03420 put(autoArgs, "Target") 03421 oleMethod(Root_ole, "getAttribute", autoArgs, Target_s) 03422 03423 clear autoArgs 03424 put(autoArgs, "BaselineEnabled") 03425 oleMethod(Root_ole, "getAttribute", autoArgs, BaselineEnabled_s) 03426 if (BaselineEnabled_s!=null and ((BaselineEnabled_s == "true") or (BaselineEnabled_s == "True") or (BaselineEnabled_s == "1"))) 03427 { 03428 Baseline_b=true 03429 03430 } 03431 return true 03432 } 03433 03434 /* *********************************************************************** 03435 Function: Export () 03436 Description: Export function triggered when click on "export to word" internally calls different functions to expoprt the object into word and finally gives the message for the user. 03437 ************************************************************************/ 03438 void Export(DB db){ 03439 Module OpenModule_m 03440 Module CurrentModule_m = current 03441 bool bSaved = false 03442 View View_vw 03443 string info_s 03444 03445 istart = getTickCount_ () 03446 03447 /* save current view */ 03448 View_vw = view(currentView(current Module)) 03449 /* get configuration file*/ 03450 ConfigFileName_s = get(dbeConfigFileList) 03451 if (!matches("(xml|XML)$", ConfigFileName_s)) 03452 { 03453 infoBox("Please select a valid XMl configuration file.") 03454 return 03455 } 03456 03457 /* hide GUI */ 03458 //hide dbProjectReportGUI 03459 /* Load XML and Template */ 03460 03461 if (initXML()) 03462 { 03463 //templateName = TemplateFileName_s 03464 03465 03466 GetFilterFromXML() 03467 /* open current view in Module */ 03468 if (!null Target_s) 03469 { 03470 /* Save Word Document */ 03471 clear autoArgs 03472 put(autoArgs, Target_s) 03473 oleMethod(objDoc, "SaveAs", autoArgs) 03474 /*Check if Save was successful */ 03475 oleGet(objDoc, "Saved", bSaved) 03476 if (!bSaved) 03477 { 03478 info_s=Target_s " is write protected. Document not saved.\n" 03479 } 03480 } 03481 current = CurrentModule_m 03482 load(View_vw) 03483 delete autoArgs 03484 int iend = getTickCount_() 03485 //iend = dateOf(intOf(today())) 03486 03487 int iDiff = (iend)-(istart) 03488 ack ("The timespent to generate the report " iDiff "miliseconds\n") 03489 infoBox "Project Report successfully generated.\n" 03490 } 03491 } 03492 03493 /* ***************************************************************************************** 03494 function : GetConfigFile() 03495 description: for testing purpose set the module attribute and the value to be populated on DBE 03496 **************************************************************************** */ 03497 void GetConfigFile(){ 03498 Module Mod = current 03499 if (exists attribute XML_CONFIG_ATTRIBUTE){ 03500 string XmlConfig_s = Mod.XML_CONFIG_ATTRIBUTE 03501 if (! null XmlConfig_s){ 03502 set(dbeConfigFileList, XmlConfig_s) 03503 } 03504 } 03505 } 03506 /* ******************************************************** 03507 Function :initGUI 03508 description: Initial GUI to fetch the config file 03509 *********************************************************** */ 03510 void initGUI() 03511 { 03512 dbProjectReportGUI = create ("Export Sample Project Report", styleCentered | styleFixed) //empty dialogbox creation 03513 03514 dbeConfigFileList = fileName(dbProjectReportGUI, "XML-Configuration-File: ","", "*.xml", "Extended Markup Language", true) //dialog box for capturing a file name 03515 GetConfigFile() 03516 03517 msgDBE = label(dbProjectReportGUI," ") //label in the DB 03518 ok(dbProjectReportGUI, "Export to Word", Export) //Ok button 03519 hide dbProjectReportGUI 03520 show(dbProjectReportGUI) //enable the DB, suspend the dxl 03521 //hide dbProjectReportGUI 03522 } 03523 /* end of functions */ 03524 03525 /**************************************************************/ 03526 /* Start of the script */ 03527 /**************************************************************/ 03528 03529 //istart = intOf(dateAndTime(today)) 03530 03531 /* Create OLE-Object xmldoc - the XML properties are used to initialize the OLE object */ 03532 xmldoc = oleCreateAutoObject("Msxml2.DOMDocument") 03533 olePut(xmldoc, "async", false) //Specifies whether asynchronous download is permitted. 03534 olePut(xmldoc, "resolveExternals", true) //Indicates whether external definitions, resolvable namespaces, document type definition (DTD) external subsets, and external entity references, are to be resolved at parse time, independent of validation. 03535 03536 /*GUI initialization to fetch the configuration file*/ 03537 initGUI()
1.7.4