Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Interacting with Word, using wordbasic
Cetin Basoz, February 16, 1998
Here is two sample functions one is just for using wordbasic and the second is using wordbasic in mailmerge. Wordbasic PEMs are defined in wrdbasic.hlp located in winword directory. This help file contains the arguments as named arguments which are not suitable for calling via VFP. In files section...
Summary
Here is two sample functions one is just for using wordbasic and the second is using wordbasic in mailmerge. Wordbasic PEMs are defined in wrdbasic.hlp located in winword directory. This help file contains the arguments as named arguments which are not suitable for calling via VFP. In files section there is a file called "positions.exe". It contains the "position.hlp" which in turn contains the correct argument positions suitable to pass as a parameter from VFP. function wordinsertdata * * Sample Word.basic interface for VFP * * Cetin Basoz * * It's strictly forbidden to modify this file without written permission of author * * Was kidding of course * * Any modification could be done for between(mModification,BOF(),EOF()) * * Inserts a database via ODBC into word and does some formatting, find&replace etc * PUBLIC oWordDocument start=seconds() *** set the LOCALEID to English nlLocaleId=sys(3004) && Save local id =sys(3006,1033) && We will be sending instructions in English wait window nowait "Creating Word Document..." oWordDocument=createobject("word.basic") && Create word object with oWordDocument .appshow && Show word app - Word 7.0 support .filenewdefault && New file, default template *!* .Format = 31, .Style = 511, .LinkToSource = 0, Linktosource = 1 for table link *!* .SQLStatement1 = "", *!* .PasswordDoc = "", *!* .PasswordDot = "", *!* .DataSource = "", *!* .From = "", *!* .To = "", *!* .IncludeFields = 1 cDSN = "DSN=Visual FoxPro Tables;UID=;PWD=;" cSourceDb = "SourceDB=C:\Program Files\vfp50\SAMPLES\DATA\Testdata.dbc" cSourceType = ";SourceType=DBC;" cOther = "Exclusive=No;BackgroundFetch=No;Collate=Machine;" cSQLStatement = "SELECT customer.company,customer.contact, customer.maxordamt FROM customer" .InsertDatabase(31,511,0, ; cDSN+cSourceDb+cSourceType+cOther, ; cSQLStatement,,,,,,,1) .startofdocument && Top of doc .editfind("Maxordamt","Max.Order Amt.",0,0,0,0,0,0,,1,,1) && Replace "MaxOrdAmt" with "Max.Order Amt." .editgoto("t") && Locate first table .endofrow && Goto last cell .tableselectcolumn && Select the last column .rightpara && Align right .tableselecttable && Select the table nRows = .selinfo(15) && Ask the rowcount to word nCharsInTable = .GetSelEndPos() - .GetSelStartPos() && Count chars written in table. Might be 1 char wrong. .EndOfDocument && Go to end of doc .insertpara && Press enter .formatfont(10,,1) && 10 points, Black .insert("VFP wrote "+; ltrim(str(nRows))+; " rows and "+; ltrim(str(nCharsInTable))+; " chars in data table.") && Write rowcount and charcount for table. .insert(chr(13)+chr(10)+"Time elapsed :"+str(seconds()-start,7,3)+" seconds.") && Start with another .insertpara = chr(13)+chr(10) -> CR/LF endwith wait clear erase &cInsertFile **** Set the LocaleId to the previous value =sys(3006,val(nlLocaleId)) Function wordmailmerge * * Sample Word.basic interface for VFP * * Cetin Basoz * * It's strictly forbidden to modify this file without written permission of author * * Was kidding of course * * Any modification could be done for between(mModification,BOF(),EOF()) * * Mailmerge version of word basic example * PUBLIC oWordDocument *** set the LOCALEID to English nlLocaleId=sys(3004) && Save local id =sys(3006,1033) && We will be sending instructions in English use home()+"samples\data\customer" && test table wait window nowait "Creating Word Document..." ftmpFile = "tmpsheet" && Temporary xls filename cInsertFile = "c:\temp\"+ftmpFile+".xls" cRange = ftmpFile+"!R1C1:R"+ltrim(str(reccount()))+"C"+ltrim(str(fcount())) && Cell range copy to (ftmpFile) type xl5 && Create the xls from table oWordDocument=createobject("word.basic") && Create word object with oWordDocument .appshow && Show word app - Word 7.0 support .filenewdefault && New file, default template .toggleportrait && Toggle page orientation (This is a toggle !) Portrait -> Landscape .insertfile(cInsertFile,cRange,0) && Insert excel sheet .filesaveas("mmergedoc",0) && Save as a word doc for mailmerge .fileclose(1) && Close saving .filenewdefault && New file, default template .MailMergeOpenDataSource("mmergedoc.doc") && Set saved file as data source for mailmerge (Directly a table could be set via ODBC) .MailMergeEditMainDocument && Activate the main document .Insert("Dear ") && Start writing .InsertMergeField("Contact") && Insert a merge field .Insert(",") .InsertPara .InsertMergeField("Company") .InsertPara .InsertMergeField("Address") .InsertPara .InsertMergeField("PostalCode") .Insert(" ") .InsertMergeField("City") .Insert(" - ") .InsertMergeField("Country") .InsertPara .InsertPara .Insert("You've fullfilled your maximum order amount (") .InsertMergeField("maxordamt") .Insert("$). I can't understand how you did it. So we can talk about it.") .InsertPara .Insert("Thanks.") .InsertPara .Insert("Yours sincerely") .InsertPara .InsertPara .Insert("Çetin Basöz") .InsertPara .Insert("cetin@neptune.imst.deu.edu.tr") endwith * InsertWordField could also be used but FP is more capable of it so we should have transfered the needed already * Here the control is passed to word. Sitting and waiting for further process. wait clear erase &cInsertFile **** Set the LocaleId to the previous value =sys(3006,val(nlLocaleId))
Cetin Basoz, Engineerica Inc.
Çetin is Engineerica's lead developer and also administering "Institute of Marine Sciences and Technology-Izmir" computer division. He specializes in using Visual FoxPro, .NET and SQL server. He is using Foxbase, Foxpro and Visual FoxPro since 80's, .NET since 2004. He has been a Microsoft MVP 1999-2010. His expertise has been used in prototyping, development, training and testing. Now he continues his carrier on VFP and C#.Net doing mostly Silverlight RIA applications. Though Çetin is well known for his programming skills, very few people know that he is also a licensed Medical Doctor. After practicing medicine for about ten years Çetin switched careers and went to his true passion - software programming.
More articles from this author
Cetin Basoz, September 20, 2000
This will get you the RGB equivalent from a color number. These are 2 little functions doing it different ways. You may try which one fits better your needs. The first one uses the 256 syntax to get the color. The second one is using the BITAND and BITRSHIFT approach.
Cetin Basoz, August 9, 2000
With grids it's a little problematic to show different images or container objects per row. You might have only image filenames stored in a table or you might want to show something like a time table with shape controls where you only store start-end values as numeric. Grid shows the same thing on a...
Cetin Basoz, April 26, 2001
Well it started when I found it hard to check rtf files for MSDN subscription index. In last few shipments there were also an MDB in 'UN-SUPPED' directory but my Access is too perfect to use an MDB so I decided to get Access data to VFP tables.
Cetin Basoz, January 6, 1998
Databases have a little different header from tables thus making it impossible to copy them online through SQL or "copy to". The code below accomplishes this opening the DBC readonly and creating a copy of it using lowlevel IO.
Cetin Basoz, June 1, 2001
Introduction Any data that could be represented in an hierarchical way is a candidate for a treeview listing. This article will show you how to use the MS Active X treeview control in your own applications in a simple way, populate it fast and apply drag&drop to it. Note that this control is ...