Wait window nowait "Creating Word Document.Please wait..." * Word constants header file #include "wdconst.h" #Define NL chr(13) #Define TABULATE chr(9) * VFP3-5 *lnFields=_CopyDataToClipBoard(home()+"samples\data\employee","first_name,last_name,title,hire_date,notes") * VFP6 lnFields=_CopyDataToClipBoard(_samples+"\data\employee","first_name,last_name,title,hire_date,notes") *** 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 * Initialize some vars If type("oWordDocument") = "U" Public oWordDocument Endif If type("goTable") = "U" Public goTable Endif If type("gHwndWord") = "U" Public gHwndWord Endif * Initialize some vars * Word object creation Declare integer GetForegroundWindow in WIN32API Declare short IsWindow in WIN32API integer If type("oWordDocument") = "O" ; and type("gHwndWord") = "N" ; and IsWindow(gHwndWord) # 0 && Check if word window is alive oWordDocument=getobject(, "Word.application") && Get word object Else oWordDocument=createobject("word.application") && Create word object Endif * Word object creation With oWordDocument .documents.add && New file .Application.DefaultTableSeparator = "~" With .ActiveDocument .PageSetup.Orientation = wdOrientLandscape .Range.Paste .Range.ConvertToTable(wdSeparateByTabs,,lnFields,,wdTableFormatContemporary,,,,,,,,,.f.) .Range.Find.Execute("~",,,,,,,,,"^p",wdReplaceAll) && Restore memo para marks Endwith .visible = .t. && Show word app .Activate Endwith Wait clear gHwndWord = GetForegroundWindow() && Save word window handle Clear dlls **** Set the LocaleId to the previous value =sys(3006,val(nlLocaleId)) Return ******************************************************************* * Insert a table in Word at specified bookmark - 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 * VFP3-6 compatible lcType = type(field(ix)) luValue = eval(field(ix)) Do case Case lcType = "D" lcValue = dtoc(luValue) Case lcType = "T" lcValue = ttoc(luValue) Case lcType = "N" lcValue = padl(luValue,20," ") Case lcType = "L" lcValue = iif(luValue,"Yes","No") Case lcType $ "M" && Replace paragraph marks with "~" lcValue = strtran(luValue, chr(13)+chr(10), "~") Case lcType $ "C" lcValue = luValue Otherwise lcValue = "" Endcase Return alltrim(lcValue)Cetin