Deye

Target a single cell in a word table

5 posts in this topic

#1 ·  Posted

Hi,

I  need a good idea or a small example on how to target the find replace for a single cell 
for instance if there is a "zero" that needs to be found and replaced then its a problem when other cells contain zeros 

Didn't really yet get to find out more of the possibility's available ..  looking

TIA
 

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

And here is a basic example:
nb: The StringReplace Chr(7) removes the cell end ascii character Bel

#include <Word.au3>
Local $sWord = @ScriptDir & "\Word.docx"
Local $oWord = _Word_Create()
Local $oDoc = _Word_DocOpen($oWord, $sWord)
If StringReplace($oDoc.Tables(1).Cell(2,2).Range.Text, Chr(7), "") = 0 Then $oDoc.Tables(1).Cell(2,2).Range.Text = 1

 

Edited by Subz
1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted

Thanks I'm reading the table from array and replacing like so :

Func _replace($table, $row, $col, $find = "", $replace = '')
        $oDoc.Tables($table).Cell($row, $col + 1).Range.Text = $replace
EndFunc   ;==>_replace

but now, how do i keep the alignment formatting of the cell after the replace takes place ..

Share this post


Link to post
Share on other sites

#5 ·  Posted

Example:
https://msdn.microsoft.com/en-us/library/office/ff835817.aspx

#include <Word.au3>
Local $sWord = @ScriptDir & "\Word.docx"
Local $oWord = _Word_Create()
Local $oDoc = _Word_DocOpen($oWord, $sWord)
Local $oTables = $oDoc.Tables
If StringReplace($oDoc.Tables(1).Cell(2,2).Range.Text, Chr(7), "") = 0 Then
    $oDoc.Tables(1).Cell(2,2).Range.Text = 1
    $oDoc.Tables(1).Cell(2,2).Range.ParagraphFormat.Alignment = 1
EndIf

 

1 person likes this

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