Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change MSword table cell background programatically
Message
 
To
06/07/2009 22:28:00
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01410445
Message ID:
01410478
Views:
49
This message has been marked as the solution to the initial question of the thread.
>Can I change the background of a table's cell background programmatically in MS Word document.
>
>I am building a matrix that need to have different color based on query result.
>
>Thanks

Sure, try this:
#define wdTextureNone    0
#define wdColorAutomatic -16777216

LOCAL oWord AS Word.Application
oWord = CREATEOBJECT("Word.Application")
oWord.Documents.Add()
oWord.Visible = .t.
oWord.ActiveDocument.Tables.Add(oWord.Selection.Range,3,3) && Add 3x3 grid 
WITH oWord.ActiveDocument.Tables(1)
     .Style = "Table Grid"
     .ApplyStyleHeadingRows = .t.
     .ApplyStyleLastRow     = .f.
     .ApplyStyleFirstColumn = .t.
     .ApplyStyleLastColumn  = .f.
     .ApplyStyleRowBands    = .t.
     .ApplyStyleColumnBands = .f.
ENDWITH


oWord.ActiveDocument.Tables(1).Cell(1,2).Select()  && Select cell we want to change
oWord.Selection.Shading.Texture                = wdTextureNone
oWord.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
oWord.Selection.Shading.BackgroundPatternColor = -553582746

oWord.ActiveDocument.Tables(1).Cell(2,1).Select()
oWord.Selection.Shading.Texture                = wdTextureNone
oWord.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
oWord.Selection.Shading.BackgroundPatternColor = -553582746

oWord.ActiveDocument.Tables(1).Cell(2,3).Select()
oWord.Selection.Shading.Texture                = wdTextureNone
oWord.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
oWord.Selection.Shading.BackgroundPatternColor = -553582746

oWord.ActiveDocument.Tables(1).Cell(3,2).Select()
oWord.Selection.Shading.Texture                = wdTextureNone
oWord.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
oWord.Selection.Shading.BackgroundPatternColor = -553582746
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform