>#include "wdconst.h" >#Define NL Chr(13) >#Define TABULATE Chr(9) >Select first_name,last_name,notes ; > from (_samples+'data\employee') ; > where Title = 'Sales' ; > into Cursor Tempreport >lnFields = _CopyDataToClipBoard('TempReport') >Use In 'TempReport' > >lcSourceDoc = Sys(5)+Curdir()+'Source.doc' > >*** set the LOCALEID to English >nlLocaleId=Sys(3004) && Save local id >=Sys(3006,1033) && sending instructions in English >*** set the LOCALEID to English > >Local oWordDocument >oWord=Createobject("word.application") && Create word object >With oWord > .documents.Add && New file or open a template > With .ActiveDocument > .Range.Paste > .Range.ConvertToTable(wdSeparateByTabs) > .Range.Find.Execute("~",,,,,,,,,Chr(13),wdReplaceAll) && Restore memo para marks > .SaveAs(lcSourceDoc) > .Close(wdSaveChanges) && Close saving > EndWith > _cliptext = "" > > .documents.Add > With .ActiveDocument.Mailmerge > .OpenDataSource(m.lcSourceDoc) && Set file as data source for mailmerge > .EditMainDocument && Activate the main document > > * Write mailmerge text thinking not using a template > .Application.Selection.TypeText("Dear,"+Chr(13)) > With .Application.Selection.Font > .Name = 'Times New Roman' > .Italic = .T. > .Size = 14 > Endwith > .Fields.Add(.Application.Selection.Range, 'First_Name') > .Application.Selection.TypeText(',') > .Fields.Add(.Application.Selection.Range, 'Last_Name') > With .Application.Selection.Font > .Name = 'Times New Roman' > .Italic = .F. > .Size = 10 > Endwith > .Application.Selection.TypeText(NL+NL+'Please update your info and send back. Current notes are as follows:'+NL+NL) > With .Application.Selection.Font > .Name = 'Arial' > .Size = 12 > .Color = Rgb(0,0,255) > Endwith > .Fields.Add(.Application.Selection.Range, 'Notes') > > * Send to a new doc - to check what we get > .Destination = wdSendToNewDocument > .Execute > > Endwith > .Visible = .T. && Show word app > .Activate && Make it the active foreground app >*!* m.lcPageList = "3,6-7" >*!* .ActiveDocument.Printout(.t.,,wdPrintRangeOfPages,,,,,1,m.lcPageList) >Endwith > >**** Set the LocaleId to the previous value >=Sys(3006,Val(nlLocaleId)) > >******************************************************************* >* Insert a table in Word - NonODBC safe way >******************************************************************* >Function _CopyDataToClipBoard > Lparameters tcCursorName > > lcOldAlias = Alias() && Save alias > Select (m.tcCursorName) > 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 > 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 = "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