>SELECT Title,FirstName FROM Employee INTO CURSOR Temp >loDocument=toWord.ActiveDocument >SCAN >loDocument.insertafter(Title) >loDocument.insertafter(CHR(13)) >loDocument.font.bold=.T. >loDocument.insertafter(FirstName) >loDocument.font.bold=.F. >loDocument.insertafter(CHR(13)+CHR(13)) >ENDSCAN >>
Wait window nowait "Creating Word Document.Please wait..." * Word constants header file #include "wdconst.h" #Define NL chr(13) #Define TABULATE chr(9) lnFields=_CopyDataToClipBoard("employee","title, first_name-(' '+last_name) as name,space(1) as Separator") *** set the LOCALEID to English nlLocaleId=sys(3004) && Save local id =sys(3006,1033) && We will be sending instructions in English *** set the LOCALEID to English oWordDocument=createobject("word.application") && Create word object With oWordDocument .documents.add && New file With .ActiveDocument .Range.Paste * .Range.ConvertToTable(wdSeparateByTabs,,lnFields,,wdTableFormatGrid1,,,,,,,,,.f.) .Range.ConvertToTable(wdSeparateByTabs,,lnFields) .Range.Find.Execute("~",,,,,,,,,chr(13),wdReplaceAll) && Restore memo para marks Endwith With .ActiveDocument.Tables(1) .Columns(2).Select .Application.Selection.Font.Bold = .t. .ConvertToText(wdSeparateByParagraphs) && Convert back to text separated with paragraraphs Endwith .visible = .t. && Show word app .Activate Endwith Wait clear **** Set the LocaleId to the previous value =sys(3006,val(nlLocaleId)) Return ******************************************************************* * NonODBC safe way ******************************************************************* Function _CopyDataToClipBoard Lparameters tcTableName, tcFieldList lcOldAlias = Alias() && Save alias Select &tcFieldList ; from (tcTableName) ; nofilter into cursor crsTemp && Select recs into a cursor If reccount("crsTemp")=0 Use in "crsTemp" Return Endif Select crsTemp lnFields = fcount() lcTempFileName = "X"+sys(2015)+".tmp" handle = fcreate(lcTempFileName) && Create a temp file *!* && Write header line *!* FOR ix = 1 to lnFields *!* =fwrite(handle, field(ix)) *!* IF ix < lnFields *!* =fwrite(handle, TABULATE) *!* ENDIF *!* ENDFOR *!* =fwrite(handle, NL) Scan && Start scan..endscan For ix = 1 to lnFields =fwrite(handle, TypeConvert(ix) ) If ix < lnFields =fwrite(handle, TABULATE) Endif Endfor =fwrite(handle, NL) Endscan lnSize=fseek(handle,0,2) =fseek(handle,0,0) _Cliptext = fread(handle, lnSize) && Read file to clipboard =fclose(handle) Erase (lcTempFileName) * Prepare text copied to clipboard in VFP which is much faster than Word OLE Use in "crsTemp" If !empty(lcOldAlias) Select (lcOldAlias) Endif Return lnFields Function TypeConvert Lparameters tnField lcType = type(field(ix)) If lcType = 'G' Return '' Endif luValue = eval(field(ix)) Do case Case lcType = "L" lcValue = iif(luValue,"Yes","No") Case lcType $ "M" && Replace paragraph marks with "~" lcValue = strtran(luValue, chr(13)+chr(10), "~") Otherwise lcValue = trans(luValue) Endcase Return alltrim(lcValue)PS:Could use ODBC transfer to keep shorter but I find this one safe.