Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a table in Word
Message
From
14/06/2001 06:28:52
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00519108
Message ID:
00519216
Views:
15
This message has been marked as the solution to the initial question of the thread.
>I made the following code work as for as 3 rows x 3 columns by brute force and making all separators TABS. But I thought the CHR(13) was supposed to work as far as starting a new row.

Mark,
NL works as a new row starter.
Below we're first setting 2 bookmarks and then placing 2 different tables to those bookmarks.
Bookmarks are important because word always enumarates tables with their order and no name property for tables. Once put your only way to find a specific table is either bookmarks or track its order in document.
Warning: I do not directly print Cell text in VFP _screen and be carefull when using them - 2 chars are added to text (chr(2)+chr(7)). lcCellText = .. clears nonprintable chars before printing in VFP.
#include wdconst.h
#Define CHR_TAB	chr(9)
#Define CHR_CR	chr(13)
Local loWord, lcMyTable

lcMyTable1 = "Parameters" + CHR_TAB + "Limit" + CHR_TAB + "Average" + CHR_CR ;
  + "Chlorine"   + CHR_TAB + "13.5"  + CHR_TAB + "10"      + CHR_CR ;
  + "Boron"      + CHR_TAB + "55.8"  + CHR_TAB + "45"      + CHR_CR

lcTempFile = sys(2015)+'.tmp'
Use employee
Copy fields First_name, last_name, Title ;
  to (lcTempFile) type delimited with TAB
lcMyHeader = chrtran('First Name,Last Name,Job Title',',',chr(9))+chr(13)+chr(10)
lcMyTable2=lcMyHeader+ChrTran(FileToStr(lcTempFile),'"','')
Erase (lcTempFile)

loWord   = newobject('word.application')
With loWord
  .Documents.Add()
  With .Selection
    .EndKey(wdStory)
    .InsertParagraphAfter()
  Endwith
  .ActiveDocument.Bookmarks.Add('StringTable') && Bookmark table positions
  With .Selection
    .EndKey(wdStory)
    .InsertParagraphAfter()
  Endwith
  .ActiveDocument.Bookmarks.Add('EmployeeTable')

  PutWordTable(loWord,lcMyTable2, 'EmployeeTable') && Add in reverse order - using bookmarks
  PutWordTable(loWord,lcMyTable1, 'StringTable')
  Clear
  ListTable2VFP(.ActiveDocument.Tables(1))
  ListTable2VFP(.ActiveDocument.Tables(2))
  .Visible = .t.
Endwith

Function ListTable2VFP
Lparameters toTable
With toTable
  For ix = 1 to .Rows.Count
    ?
    For jx = 1 to .Columns.Count
      lcCellText = chrtran( .Rows(ix).Cells(jx).Range.Text , chr(13)+chr(10)+chr(2)+chr(7), '' )
      ??  padr(lcCellText, 30) + '| '
    Endfor
  Endfor
  ?
  ?
Endwith


Function PutWordTable
Lparameters toWord, tcTable, tcBookmarkName
With toWord.ActiveDocument
  .Bookmarks(tcBookmarkName).Select
  With .Application.Selection
    .Collapse(wdCollapseEnd)	&& Go to end of bookmark
    If .Information(wdWithInTable) && If we're in a table
      .MoveEnd(wdTable)
      .Collapse(wdCollapseEnd)	&& Get out of table
      .InsertParagraph()			&& Split table
      .Collapse(wdCollapseEnd)	&& Clear selection
    Endif
    .Text = tcTable
    loTable = .ConvertToTable(wdSeparateByTabs,,,,wdTableFormatColorful2,.f.,,,,,,.f.,,.f.)
    .Collapse(wdCollapseEnd)
  Endwith
Endwith
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform