Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding text from a specific position
Message
De
13/06/2002 08:49:46
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
13/06/2002 02:48:57
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00667789
Message ID:
00667875
Vues:
19
>I am trying to add some text from a specific location from my Word document. I have some code like this:
>
>
>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
>
>
>Basically, I am trying to print a few records in a row by showing the Title followed by the first name in bold. However, Word doesn't like it. I believe I have to define a range. How do I do that?
>
>Also, I have defined my Word document in 3 columns. So, I would like all that text to be within those columns and start from the upper part. Is there a way to specify that?

Michel,
It'd be loDocument.Range

I think below code does what you wnat. I'm not sure I understood last paragraph. If you mean you want it in a table then comment 'ConvertToText' line :
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.
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