FrancescoDiMuro

Word UDF...

11 posts in this topic

Good morning everyone :)
I was talking about this UDF in this thread, but for not confusing "arguments", I opened a new thread...
So, the issue I'm having, is the format of the table, that you can see in the image above... Can you help me out please? Thanks :) 
Text of the previous post:

Quote

Talking about Word UDF, I have a 2D array ( returned by a ListView ), and I would like to create a report with this array, inside a Word table... I tried with this, but texts are a bit untidy... Can you help me out, please? :) 

 

Local $oWord = _Word_Create(False)
            If @error Then
                MsgBox($MB_ICONERROR, "Errore!", "Errore durante la creazione dell'oggetto Word." & @CRLF & "Errore: " & @error)
            Else
                ; The field alreay exists, but would be nice if I can create it... I thought at _FileCreate() :) 
                Local $oDoc = _Word_DocOpen($oWord, $sCartellaModelli & "\Esportazione_Modello.doc")
                If @error Then
                    MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'aggiunta di un nuovo documento Word." & "Errore: " & @error)
                Else
                    Local $oRange = _Word_DocRangeSet($oWord, 0)
                    If @error Then
                        MsgBox($MB_ICONERROR, "Errore!", "Errore durante il settaggio del range nel documento Word." & @CRLF & "Errore: " & @error)
                    Else
                        _Word_DocTableWrite($oRange, $aListView, Default)
                        If @error Then
                            MsgBox($MB_ICONERROR, "Errore!", "Errore durante la creazione della tabella." & @CRLF & "Errore: " & @error & "Informazioni: " & @extended)
                        Else
                            _Word_DocSaveAs($oDoc, $sCartellaEsportazioni & "\Esportazione_di_prova.doc")
                        EndIf
                    EndIf
                EndIf
            EndIf

And this is the actual result:
Cattura.PNG


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites



SUPER BUMP! :D 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

Can you please post an example how the report should look like?


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

#4 ·  Posted (edited)

BTW: To make your code a bit more readable I suggest following changes:

Local $oWord = _Word_Create(False)
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "Errore durante la creazione dell'oggetto Word." & @CRLF & "Errore: " & @error)
; The field alreay exists, but would be nice if I can create it... I thought at _FileCreate() :) 
Local $oDoc = _Word_DocOpen($oWord, $sCartellaModelli & "\Esportazione_Modello.doc")
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'aggiunta di un nuovo documento Word." & "Errore: " & @error)
Local $oRange = _Word_DocRangeSet($oWord, 0)
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "Errore durante il settaggio del range nel documento Word." & @CRLF & "Errore: " & @error)
_Word_DocTableWrite($oRange, $aListView, Default)
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "Errore durante la creazione della tabella." & @CRLF & "Errore: " & @error & "Informazioni: " & @extended)
_Word_DocSaveAs($oDoc, $sCartellaEsportazioni & "\Esportazione_di_prova.doc")
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "..." & @CRLF & "Errore: " & @error & "Informazioni: " & @extended)

 

Edited by water

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

@water
Good morning :)
The report should look like a table containing a header, with names of columns of the data the report is representing... 
Header 1|Header 2
Data 1.1 | Data 2.1
Data 1.2 | Data 2.2
So on...
I have 15 columns ( SQLite table ), and some descriptions are quite long...

3 minutes ago, water said:

 

BTW: To make your code a bit more readable I suggest following changes:

 

Thanks for the suggestion :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

So the data in the screenshot you posted above is correct but the formatting needs some brush up?


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

Absolutely yes @water! 
O.T.: I don't know why sometimes tags on users doesn't work... :/ 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Function _Word_DocTableWrite returns the table object. The format of this object needs to be modified.
Details can be found here: https://msdn.microsoft.com/en-us/library/ff195902(v=office.14).aspx

Example:

Local $oTable = _Word_DocTableWrite($oRange, $aListView, Default)
$oTable.Columns.SetWidth(100) ; Sets the width of all columns to 50 points

BTW:
1 Centimeter = 28.3464567 Points
1 Point = 0.0352777778 Centimeters

Edited by water

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

#9 ·  Posted (edited)

@water
Just a little question...
Is the procedure you wrote above to create a blank report, which in insert a table, correct? 
The range and other stuffs?
It's the first time I'm using, so I want to do it in the right way :)
Thanks for your help! :D 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites

#10 ·  Posted

As you want to create a completely new report I would change _Word_DocOpen to _Word_DocAdd:

Local $oWord = _Word_Create(False)
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "Errore durante la creazione dell'oggetto Word." & @CRLF & "Errore: " & @error)
; Create a new empty document
Local $oDoc = _Word_DocAdd($oWord)
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'aggiunta di un nuovo documento Word." & "Errore: " & @error)
Local $oRange = _Word_DocRangeSet($oWord, 0)
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "Errore durante il settaggio del range nel documento Word." & @CRLF & "Errore: " & @error)
_Word_DocTableWrite($oRange, $aListView, Default)
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "Errore durante la creazione della tabella." & @CRLF & "Errore: " & @error & "Informazioni: " & @extended)
_Word_DocSaveAs($oDoc, $sCartellaEsportazioni & "\Esportazione_di_prova.doc")
If @error Then Exit MsgBox($MB_ICONERROR, "Errore!", "..." & @CRLF & "Errore: " & @error & "Informazioni: " & @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

#11 ·  Posted

Hey @water! Thank you for your help :) I'll update you as soon as possible ( as I develop this thing in my software )!
Again, a big thanks! :D
Have a good day :)
Francesco :D 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

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

  • Similar Content

    • anoig
      By anoig
      Hi all, 

      First, I want to give a huge shout-out to the community. I'm completely self-taught, and have never had to actually ask a question before because the forum is that good at answering questions and explaining things. However, I'm kind of stumped here, and I've been stuck on this problem for almost a full day.

      I'm working on a script to populate drafts of deeds at work. I have the main GUI and  a function (ctrl($n) and read()) for adding fields to find and data to replace it with to an array for later use with _word_docfindreplace. All of that works. However, due to the way I have the forms set up, I need to create additional fields and info based on the data that's there. Specifically, if there's only one buyer, I need to add the field [Buyer1&2] and the data in $aArray_Base for [Buyer 1]. I also need to add a field [Buyer 2] and have a blank data set in the next column over in the array, and I need to do the same for the Seller. To this end, the function parties() sets boolean variables $2buyers and $2sellers accordingly. Then, I have buyers() and sellers() to populate the data. 

      The problem that I'm running into is that each function works... when ONLY the buyer 1 name field is filled, and when ONLY the seller 1 field is filled.

      So if I fill Buyer 1 Name and save it, the data is populated correctly. But when I fill Buyer 1 and Seller 1 name, only the buyer 1 data populates correctly. Worse, when I fill several fields, neither populate correctly. I have no idea why this happens. I've added messageboxes to debug throughout the entire process and can't pinpoint what's causing the issue. The entire script is below. The function(s) in question are buyers() and sellers(). Only Sellers() has messageboxes throughout.

      Can someone help walk me through what might be causing this and help me find a solution? Thanks a ton in advance, and sorry for the wall of text.
      -Anoig
       
    • water
      By water
      My computer has been upgraded from Office 2010 to Office 2016.
      Are there any features of Office 2013 or Office 2016 which you now want to see in the Excel, Word or Outlook UDF?
    • Jury
      By Jury
      As near as I can ascertain using the Word UDF the paragraph count does not count the numbered paragraphs in a document but counts something like all paragraphs (numbered , un-numbered, indented) minus empty lines.  Is there any easy way of getting the first level numbered paragraph numbers?  You'll see in my test document there are just 7 numbered paragraphs.
      #include <Word.au3> #include <Array.au3> Local $oWord = _Word_Create() Local $sDocument = @MyDocumentsDir & "\test.docx" Local $oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, True) $oRange = $oDoc.Range $sText = $oRange.Text $aLines = StringSplit($sText, @CR) _ArrayDisplay($aLines) $wdPropertyParas = 24 $sParas = $oDoc.BuiltInDocumentProperties($wdPropertyParas).Value $sParas = $sParas ConsoleWrite($sParas & @CRLF)  
      test.docx
    • Shane0000
      By Shane0000
      a Shift + Enter line break for Word 2007. is chr(11)
      #include <word.au3> $sText = 'Test' & @LF & 'Test' & @CR & 'Test' & @CRLF & 'test' & chr(10) & 'test' & chr(13) & 'test' $oWord = _Word_Create() $oDoc = _Word_DocAdd($oWord) $oRange = $oDoc.Range $oRange.InsertAfter ($sText) $iEnd = $oRange.End _Word_DocSaveAs($oDoc,'c:\test.doc') hehe dancing all around chr(11)