Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Truncated memo fields with INSERT DATABASE in Word 2000
Message
De
12/01/2000 06:21:28
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
11/01/2000 20:11:06
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00315252
Message ID:
00316791
Vues:
15
>John, Cetin,
>
>Both good ideas. I had thought of using the ADO approach, but was resisting it because of all the work involved in re-programming a working app. And, truth be told, because I don't really know how. Guess it's time I learned. Maybe it would save me the pain of dealing with MS's rather cavalier approach to ODBC drivers.
>
>Just off the top of my head can't think of a quick and dirty VBA way (like Insert Database) to get an ADO record set into a Word table with associated table formatting. Suggestions? Cetin, your idea would resolve that issue; I thing I'll try it.
>
>Thanks, guys.


Ray,
I'm a newbie for ADO so I'll leave it to whom I also started with reading his article :)
For clipboard transfer w/o ODBC sample code is below if that helps :
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
Ç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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform