dopeness

Writing to a new column using _Word_DocTableWrite()

8 posts in this topic

Right now I'm developing a program. I'm trying to write some data to a new column but it's just getting written into a new row.

I've provided an image. The green section is ok, it's supposed to be in that column, but the red isn't. The red is supposed to be in the next column.

https://s32.postimg.org/r65uu66zp/aaaaaaaaaaa.png

 

The code I have is:

$referencesArray[0] = "some text with new line breaks."
$referencesArray[1] = "some more text with new line breaks."
;Isn't this supposed to write into a new column on each ref array??
Local $newarray[2][2] = [ [ $referencesArray[0] ],[ $referencesArray[1] ] ]

 

Share this post


Link to post
Share on other sites



_Word_DocTableWrite only takes a "simple" array. No nested arrays.
Try something like this If you want to let Word do the line breaks = start a new row.

Local $aDocTable[1][2] = [["some text with new line breaks.", "some more text with new line breaks."]]

Or split the text into an array and fill $aDocTable row by row.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks a lot for the response, I'll test it now and let you know if it works.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok that didn't work. It put the referencesArray[1] first line on the next column, but its not at the top, more in the middle. The rest of referencesArray[1] was put back in the first column with the referencesArray[0] data. Any ideas?

 

Edit 2: I tried filling the array with this code:

 

$split1 = StringSplit($referencesArray[0], @CR)
        $split2 = StringSplit($referencesArray[1], @CR)
        Local $dataput[1][10]
        For $i = 1 To UBound($split1)-1 Step 1
            If Not Mod($i,2) = 0 Then
                $dataput[0][$i] = $split1[$i]
            Else
                $dataput[0][$i] = $split2[$i] & @CR
            EndIf

            If $i = 6 Then
                ExitLoop
            EndIf
        Next


        _Word_DocTableWrite($f, $dataput, 0)

But no luck. I know my logic is terribly wrong lol, can some one help?

Edited by dopeness

Share this post


Link to post
Share on other sites

Will try tomorrow as soon as I return to my office.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You need something like this:

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <Word.au3>

; Create application object
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableRead Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open the test document
Local $oDoc = _Word_DocAdd($oWord)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableRead Example", _
        "Error opening new document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Create a table from an array
Local $sIn1 = "NL1" & @CRLF & "NL2"
Local $sIN2 = "b1" & @CRLF & "b2" & @CRLF & "b3"
Local $aTemp1 = StringSplit($sIn1, @CRLF,  $STR_ENTIRESPLIT)
Local $aTemp2 = StringSplit($sIn2, @CRLF,  $STR_ENTIRESPLIT)
Local $iRows = ($aTemp1[0] > $aTemp2[0]) ? $aTemp1[0] : $aTemp2[0]
Local $aOut[$iRows][2]
For $i = 1 To $aTemp1[0]
    $aOut[$i - 1][0] = $aTemp1[$i]
Next
For $i = 1 To $aTemp2[0]
    $aOut[$i - 1][1] = $aTemp2[$i]
Next
Local $oRange = _Word_DocRangeSet($oDoc, -2)
Local $oTable = _Word_DocTableWrite($oRange, $aOut, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableRead Example", _
        "Error creating the table." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hmm that actually looks like it can work! Thanks a lot man, I'll test it out and let you know how it goes. Also, Autoit supports ternary operators?! Themoreyouknow.jpg

Share this post


Link to post
Share on other sites

Yes. Ternary operators have been implemented with AutoIt 3.3.10.0 (according to the help file):

Quote

Added: C++ style ternary operators: Local $fResult = ("foo" = "bar") ? True : False.

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now