Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OLE automation with MS-Word
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00193971
Message ID:
00194325
Views:
27
Ranjan,

I'm not sure what's not working in your code, here is some code from an app of mine that converts a cursor into a Word Table:
lparameters raColumnHeaders, pnColumns

* raColumnHeaders = array of header text to put in the first row
* pnColumns = number of columns in the array/current work area

dimension raColumnHeaders[pnColumns]

local loRange, loTable, loCell, i, j, lnRecno

lnRecno = recno()

with this.moWord.Selection
   loRange = .Range
   loTable = this.moWord.ActiveDocument.Tables.Add( loRange, reccount() + 1, pnColumns )
   for j = 1 to pnColumns
      loCell = loTable.Cell( 1, j )
      loCell.Range.InsertAfter( raColumnHeaders[j] )
   endfor

   for i = 1 to reccount()
      goto i

      scatter to laRow
      for j = 1 to pnColumns
         if ( type( "laRow[j]" ) == "C" )
            laRow[j] = alltrim( laRow[j] )
         endif
         loCell = loTable.Cell(i+1,j)
         loCell.Range.InsertAfter( laRow[j] )
      endfor
   endfor

endwith

goto lnRecno

this.TableAutoFit( loTable )

return loTable


* TableAutoFit method:
lparameter roTable

local loColumn, loRow

for each loRow in roTable.Rows
   loRow.SpaceBetweenColumns = 6
endfor

for each loColumn in roTable.Columns
   loColumn.AutoFit()
endfor
>In order to print a huge report I have created a link with Word.
>When starting the print I notice some strange behaviour within the document that is being created.
>If Word is visible everything works like a charm. However, I don't want to bore my user with Word flashing in front of his eyes so I decided to created the report in the background.
>
>This is when things get vague. When creating tables and leaving them things work fine as long as Word is visible. If Word is not visible the creation of the matrix goes wrong.
>
>Where is my routine going wrong???
>
>Can anyone please help.
>
>Ron Brahma
>
>*********************************************
>testObject = CREATEOBJECT("Word.Application")
>* the dot-file is only used as a template use something else (if you want to...
>testObject.documents.add('c:\temp\test.dot')
>
>testObject.visible= .T.
>=to_word()
>testObject.selection.typetext('You should not be in the matrix' + chr(13))
>
>testObject.visible= .F.
>=to_word()
>testObject.selection.typetext('You should not be in the matrix' + chr(13))
>
>testObject.visible= .T.
>
>return
>
>procedure to_word
>testObject.activedocument.tables.add(testObject.selection.range, 1, 2)
>testObject.selection.typetext(alltrim('This is the first column'))
>testObject.selection.MoveRight(12) &&wdCell
>testObject.selection.typetext(alltrim('This is the second column'))
>
>if testObject.selection.cells.count > 0
> * Make sure you are NOT inside the table
> testObject.selection.movedown(5, 1) &&wdLine, count
>endif
>
>* leave the matrix
>testObject.selection.movedown(5, 1) &&wdLine, count
>RETURN
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform