Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to print a WORD doc using a Report in VFP 5.0
Message
From
23/04/1998 16:11:51
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
23/04/1998 09:29:35
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
00094296
Message ID:
00094459
Views:
19
>Hi:
>
> I have a table where store the full path and document's filename, I need to print the data from the table and at the end to print that WORD doc correspondent.
> Can you help me?
>
> Thanks.
Isn't this second time I'm replying to this ? Assuming my memory leak and benefit of others here is my suggestions and sample :
-Printing via report needs the doc be in a general field and it would be extremely slow.
-Instead do the reverse. That is :
  1. Create a word object.
  2. Open word doc.No appshow so it's like report...to printer noconsole
  3. Insert VFP data
  4. Print via word
  5. Exit no save
    1. This way you also have the chance to insert other objects such as bmp, excel worksheet etc directly to word.doc anywhere you want. Below a sample doing it :
      *!*	First a word.doc is created and saved. Also a bookmark (plsinserthere) is added for VFP marking data placement.
      *!*	(Bookmarks such as header,footer etc could make an existing word.doc behave like a report).
      *!*	Then opened as an existing word.doc and first 10 recs from employee table are inserted at bookmark.
      *!*	File is printed and exited (no save).
      *!*	Some lines are commented to show word.basic or VBA counterparts.
      
      #define NL chr(13)
      PUBLIC oWordDocument
      
      *** set the LOCALEID to English
      nlLocaleId=sys(3004)		&& Save local id
      =sys(3006,1033)				&& We will be sending instructions in English 
      use home()+"samples\data\employee"		&& test table
      wait window nowait "Creating Word Document..."
      
      oWordDocument=createobject("word.application")	&& Create word object
      with oWordDocument.wordbasic			&& Word.basic and VBAword commands are used
      *	.appshow							&& Show word app
      	.filenewdefault        				&& New file, default template
      	.insert("This is our existing word document. Data from VFP will be inserted starting after repeating our comments."+NL)
      	.insert("First a word.doc is created and saved. Also a bookmark (plsinserthere) is added for VFP marking data placement.")
      	.insert("(Bookmarks such as header,footer etc could make an existing word.doc behave like a report).")
      	.insert("Then opened as an existing word.doc and first 10 recs from employee table are inserted at bookmark.")
      	.insert("File is printed and exited (no save).")
      	.insert("Some lines are commented to show word.basic or VBA counterparts."+NL+"*****************"+NL)
      	.editbookmark("PlsInsertHere",,1)   && Added our bookmark
      	* oWordDocument.activedocument.bookmarks.add(cBookmark) - VB syntax && .goto for go .delete for delete etc
      	.insert("*********************"+NL+"VFP data ends here. Any other comments....")
      	.filesaveas(curdir()+"oursample.doc") && Save so this will be our existing doc.
      	.fileclose(1)							&& Close file saving
      	.fileopen(curdir()+"oursample.doc")		&& Open "existing" doc.
      	.editbookmark("PlsInsertHere",,,,1)   	&& Go to our bookmark
      	scan while recno() <= 10
      		.formatfont(12,,5)					&& 12 points, magenta - just to identify VFP data
      		.insert(ltrim(str(recno()))+"-"+trim(employee.last_name)+","+employee.first_name+NL) && Insert employee name
      		.insert(employee.notes+NL+NL)  		&& Insert employee notes
      	endscan
      	wait window nowait "Printing now.."
      	oWordDocument.activedocument.printout(0)	&& Print REPORT,no background - .fileprint(0) wordbasic way
      	wait window "Word finished printing." nowait
      	.fileexit(2)	&& Exit no save, so old doc intact
      endwith
      =sys(3006,val(nlLocaleId))
      
      release oWordDocument
      
      * Below is mailmerge way
      *!*		cDSN = "DSN=Visual FoxPro Tables;UID=;PWD=;"
      *!*		cSourceDb = "SourceDB=C:\Program Files\vfp50\SAMPLES\DATA\Testdata.dbc"
      *!*		cSourceType = ";SourceType=DBC;"
      *!*		cOther = "Exclusive=No;BackgroundFetch=No;Collate=Machine;"
      
      *!*		cSQLStatement = "SELECT * FROM customer"
      *!*		.InsertDatabase(35,511,1, ;
      *!*			cDSN+cSourceDb+cSourceType+cOther, ;
      *!*			cSQLStatement,,,,,,,1)			&& 35,511 table autoformat values 1 link to source
      *!*		.filesaveas("xxmmergedoc",0)			&& Save as a word doc for mailmerge
      *!*		.fileclose(1)						&& Close saving
      *!*		.filenewdefault        				&& New file, default template
      *!*		.MailMergeOpenDataSource("xxmmergedoc.doc")  && Set saved file as data source for mailmerge (Directly a table could be set via ODBC)
      *!*		.MailMergeEditMainDocument			&& Activate the main document
      *!*		.Insert("Dear ")                    && Start writing
      *!*		.InsertMergeField("Contact")        && Insert a merge field
      *!*		.Insert(",")
      *!*		.....
      *!*		.mailmergetoprinter
      
      **** Set the LocaleId to the previous value
      Hope it helps
      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
Previous
Reply
Map
View

Click here to load this message in the networking platform