Jump to content

Target a single cell in a word table


Recommended Posts

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
 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 ..

Link to comment
Share on other sites

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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