spoo Posted August 1, 2019 Share Posted August 1, 2019 Hi All, 1. I want to search for a unique number in the word document. lets say 34-3330 2. After finding the number i want to search for a key word "MSN INVOLVED" , upwards starting from the location of 34-3330 (ie. MSN involved keyword will be above 34-3330 number) 3.Get the first table occurrence with "MSN INVOLVED " keyword > check if the MSN involved table as no data >if table has "NO data involved keyword" then ignore the table >look for the next MSN involved Table ->if entries present then retrieve it. Problem : My code always gives me the very first table from the top with MSN involved keyword. Please find the attached test.docx #include <Array.au3> #include <MsgBoxConstants.au3> #include <Word.au3> ; Create application object Local $oWord = _Word_Create() ; Open the test document Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Test.docx", Default, Default, True) ;search for the number $oRangeFound = _Word_DocFind($oDoc, "34-3330") $oSearchRange = _Word_DocRangeSet($oDoc, $oRangeFound, $wdSection, -1, $wdWord, 1) $oMSNFound = _Word_DocFind($oDoc, "MSN Involved",$oSearchRange,Default,True) $oSearchRange1 = _Word_DocRangeSet($oDoc, $oMSNFound, $wdParagraph, 1, $wdParagraph, 3) $oTables=$oSearchRange1.Tables Local $asResult1 = _Word_DocTableRead($oDoc, $oTables(1), 1) _ArrayDisplay($asResult1, "Word UDF: _Word_DocTableRead Example") test.docx Link to comment Share on other sites More sharing options...
water Posted August 1, 2019 Share Posted August 1, 2019 Wouldn’t be Excel the better tool to work with tables? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
spoo Posted August 1, 2019 Author Share Posted August 1, 2019 (edited) @water Word Document is provided by the Customer. so no other go. we will have to fetch the Table data from word. Edited August 1, 2019 by spoo Link to comment Share on other sites More sharing options...
water Posted August 1, 2019 Share Posted August 1, 2019 Use function _Word_DocTableRead to read the whole table into an array and then do all further processing with this array. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
spoo Posted August 2, 2019 Author Share Posted August 2, 2019 @water by suggesting reading the whole table into the array are you trying to say pull all the tables present in the word documents into the array? there are multiple Tables with the same name. Please refer the attached test docx. i want table 1.2 I have used _WordDocTableRead and it work well but problem is I'm finding it difficult to search for the immediate next table (Upwards) with table name MSN Involved when "NO data involved " text is found in the table. Link to comment Share on other sites More sharing options...
water Posted August 2, 2019 Share Posted August 2, 2019 The tables have an index. So in your document this is from 1 to 5. Read the needed tables into separate arrays and then work with those arrays. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
spoo Posted August 6, 2019 Author Share Posted August 6, 2019 @water Thank you. Here is the working code. $oSearchRange1 = _Word_DocRangeSet($oDoc, $oRangeFound, $wdSection, -1, $wdWord, 1) ;Search for MSN Involved $oMSNFound = _Word_DocFind($oDoc, "MSN involved", $oSearchRange1,Default,False) $oSearchRange = _Word_DocRangeSet($oDoc, $oMSNFound, $wdParagraph, 1, $wdParagraph, 3) $oTables=$oSearchRange.Tables Local $asMSN = _Word_DocTableRead($oDoc, $oTables(1), 1) _ArrayDisplay($asMSN) While $asMSN[2][0] == "NO data involved" $oMSNFound = _Word_DocFind($oDoc, "MSN involved", $oMSNFound,Default,False) $oSearchRange = _Word_DocRangeSet($oDoc, $oMSNFound, $wdParagraph, 1, $wdParagraph, 3) $oSearchRange.Select $oTables=$oSearchRange.Tables Local $asMSN = _Word_DocTableRead($oDoc, $oTables(1), 1) $oMSNFound = _Word_DocFind($oDoc, "MSN involved", $oMSNFound,Default,False) _ArrayDisplay($asMSN) Wend Link to comment Share on other sites More sharing options...
water Posted August 6, 2019 Share Posted August 6, 2019 My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now