FrancescoDiMuro Posted June 16, 2017 Share Posted June 16, 2017 (edited) Good morning everyone I am working on a little script, which takes some data from a SQLite DB and should create a sort of report, inserting rows in a Word Document... I arrived at the point of: _Word_DocTableWrite() and, I don't know how to set the range parameter? What does that specify? Thanks a lot for the help EDIT: Managed to write a table in the Word document, but now I get an error when I save the document with _Word_DocSaveAs(), with error 2. Which are possible causes? Thanks a lot, again EDIT 2: ... And, how can I set a border to the table? Maybe, with a sort of auto-formatting for text ( larger is the text, larger is the height/width of the table's cell ). Thanks EDIT 3 ( bug ): Including the parameter $WdSaveChanges in the function _Word_DocSaveAs(), a save dialog box appears, and it should not do it, as it's written in the MSDN documentation: wdSaveChanges -1 Save pending changes automatically without prompting the user. Thanks again for everyone will answer to me Edited June 16, 2017 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted June 16, 2017 Share Posted June 16, 2017 Which version of MS Word do you run? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted June 16, 2017 Share Posted June 16, 2017 The range parameter specifies the location in your Word document where to insert the table. Use _Word_DocRangeSet to define this location. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted June 16, 2017 Share Posted June 16, 2017 _Word_DocTableWrite returns the table object. Use the Borders property to set all kind of formatting for the table: https://msdn.microsoft.com/en-us/library/office/ff823239.aspx My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 16, 2017 Author Share Posted June 16, 2017 (edited) Hi @water ! Thank you for your replies I run Office 2016 For the EDIT 3, is that a bug? Thanks Francesco EDIT: Is there a way to have a dynamic height/width of table's cells, based on the content? Thank you so much, it works perfectly! Edited June 16, 2017 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted June 16, 2017 Share Posted June 16, 2017 Need to check. Either a problem with MS Word or with the UDF My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 16, 2017 Author Share Posted June 16, 2017 (edited) 9 minutes ago, water said: Need to check. Either a problem with MS Word or with the UDF I don't need to set any extra parameter in _Word_DocSaveAs(), but, just to inform you Thank you Edited June 16, 2017 by FrancescoDiMuro Now it's explained better! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted June 16, 2017 Share Posted June 16, 2017 But you did at least set parameter 1 ($oDoc)? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 16, 2017 Author Share Posted June 16, 2017 I made a big mess, sorry @water! The "issue" occurs in the function _Word_Quit(), not in _Word_DocSaveAs(). Sorry! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted June 16, 2017 Share Posted June 16, 2017 What is the value of @error and @extended after calling _WordQuit? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Subz Posted June 16, 2017 Share Posted June 16, 2017 Basic example with borders and saving doc into @ScriptDIr #include <MsgBoxConstants.au3> #include <Word.au3> Local Const $wdLineStyleSingle = 1 Local Const $wdBorderBottom = -3 ;~ A bottom border. Local Const $wdBorderDiagonalDown = -7 ;~ A diagonal border starting in the upper-left corner. Local Const $wdBorderLeft = -2 ;~ A left border. Local Const $wdBorderRight = -4 ;~ A right border. Local Const $wdBorderTop = -1 ;~ A top border. Local Const $wdGray25 = 16 ;~ Shade 125 of gray color. ; Create application object Local $oWord = _Word_Create() If @error Then Exit Local $oDoc = _Word_DocAdd($oWord) If @error Then Exit Local $asArray[3][3] = [[1, 2, 3], ["a", "b", "c"], ["x", "y", "z"]] Local $oRange = _Word_DocRangeSet($oDoc, -2) Local $oTable = _Word_DocTableWrite($oRange, $asArray, 0) If @error Then Exit With $oTable ;Apply borders around table .Borders($wdBorderTop).LineStyle = $wdLineStyleSingle .Borders($wdBorderBottom).LineStyle = $wdLineStyleSingle .Borders($wdBorderLeft).LineStyle = $wdLineStyleSingle .Borders($wdBorderRight).LineStyle = $wdLineStyleSingle .Rows(1).Shading.BackgroundPatternColorIndex = $wdGray25 EndWith _Word_DocSaveAs($oDoc, @ScriptDir & "\Filename.docx", $WdFormatDocumentDefault) _Word_DocClose($oDoc) _Word_Quit($oWord) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 16, 2017 Author Share Posted June 16, 2017 Now seems all fixed I don't know why! If the issue occurs again, I will let you know! Thanks for your help @water! Have a super wonderful day! Francesco Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 16, 2017 Author Share Posted June 16, 2017 @Subz Thank you for your reply! I managed to do what I was trying to do with my script! Thank you and have a good day! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted June 16, 2017 Share Posted June 16, 2017 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 16, 2017 Author Share Posted June 16, 2017 (edited) Hey @water, and If I would like to set the position and the size of an image, inserted with Local $objLogo1 = _Word_DocPictureAdd($objWordDoc, @ScriptDir & "\Images\Logo_Haupt.jpg", False, True, $objWordDocRange) what do I have to do? I tried with With $objLogo1 .ScaleWidth 1.0, False ; ... EndWith even with parenthesis, but, I dind't managed to do what I was trying to do Thanks for your precious knowledge Edited June 16, 2017 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted June 16, 2017 Share Posted June 16, 2017 Should be: With $objLogo1 .ScaleWidth = 100 ; percent of the shape's original width ; ... EndWith What is "False" for? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 16, 2017 Author Share Posted June 16, 2017 Sorry for that! I'm not prepared as you are on Word objects I was looking here https://msdn.microsoft.com/en-us/library/office/ff195610.aspx Now I'm trying with .Width property Thanks again! I'll ask here in case! Have a good evening! Francesco Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
water Posted June 16, 2017 Share Posted June 16, 2017 I see. You are calling a Shape method where I was using a InlineShape property. For Shape your could should look like: With $objLogo1 .ScaleWidth(1.0, 0) ; ... EndWith Be aware that the MsoTriState data type is a bit different: https://msdn.microsoft.com/de-de/library/office/ff860737.aspxmsoCTrue 1 not supported msoFalse 0 False msoTriStateMixed -2 not supported msoTriStateToggle -3 not supported msoTrue -1 True My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - 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