Jump to content

Recommended Posts

Posted

Hi @Miloud

This code is what I use to read a Word Document Table with 5 columns:
 

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

; Create application object
Local $oWord = _Word_Create(False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Test2.docx", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF", "Error opening '\Test2.docx'." & @CRLF & _
        "@error = " & @error & ", @extended = " & @extended)

Local $asResult = _Word_DocTableRead($oDoc, 1, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF", _
        "Error reading the table to an array." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Global $result = "|"

Local $iRows = UBound($asResult, $UBOUND_ROWS)
Local $iCols = UBound($asResult, $UBOUND_COLUMNS)


For $i = 1 To $iRows -1
    For $j = 1 To $iCols -1
        $result &= $asResult[$i][$j]&","
    Next
    $result = StringTrimRight($result,1)
    $result &= "|"
Next

_Word_Quit($oWord)

To do what you need is something very similar to this but using  _Word_DocTableWrite check the help file if you feel this is not enough.

Regards
Alien.

Posted (edited)

Thank you @AutoBert @Juvigy

  and @alien4u

Here is approximately what I wanted :

#include <_ClipPutHTML.au3>
#include <Array.au3>

$sPlainTextStr='1' & @TAB & '2' & @tab & '3' & @CRLF & '4' & @TAB & '5' & @TAB & '6'
$sHTMLStr=toTable($sPlainTextStr)
_ClipPutHTML($sHTMLStr,$sPlainTextStr)

Func toTable($sPlainTextStr)
   $x=StringReplace($sPlainTextStr, @TAB, '</td><td>',0,2 )
   $x=StringReplace($x, @CRLF, '</td></tr><tr><td>')
   $x='<table border="1"><tr><td>'&$x&'</td></tr></table>'
   ;MsgBox(0,0,$x)
   Return $x
EndFunc

Thanks to

 

Edited by Miloud
Posted

@Miloud
This is a way to do something thinking in HTML but you need to stop thinking like that because you need it for a Word document so you need to think in Microsoft Office Objects and Word UDF the one I use in the example in my previous post.

If you look at the example on the Help File for _Word_DocTableWrite you got what you need, if you take my example like a Template you just have to do minors changes.

That way is the correct way to do it and also the efficient way to do it.

Regards
Alien.

Posted (edited)
  On 4/11/2016 at 2:45 PM, alien4u said:

@Miloud
This is a way to do something thinking in HTML but you need to stop thinking like that because you need it for a Word document so you need to think in Microsoft Office Objects and Word UDF the one I use in the example in my previous post.

If you look at the example on the Help File for _Word_DocTableWrite you got what you need, if you take my example like a Template you just have to do minors changes.

That way is the correct way to do it and also the efficient way to do it.

Regards
Alien.

Expand  

Thanks @Alien4u,

In fact I need it for a gui application which gets data from an sqlite table,

what I needed was in fact the option 'copy '

I may (and sure shall) think as you said for the option 'get for word' which is needed too :)

Sans titre.png

Edited by Miloud
Posted (edited)

If you can make sql queries to the database you don't need "Copy"(no ClipPut, no ClipGet needed)  you only need make a query to the sqlite database and save your query result to a variable or array and then write that to the Word Document.

If you are taking the values from a GUI because you can't access SQLite Database then you will need "Copy" things one by one as far as I know, but again is the same approach because you "Copy" then ClipGet to a variable or Array, then "Copy" again and when you are done copying you Write all your data to the Word Document in the same way I already told you.

Kind Regards
Alien.

 

Edited by alien4u
Typo Fixed

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...