Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mailmerge
Message
From
28/08/2002 09:24:56
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Miscellaneous
Thread ID:
00694358
Message ID:
00694405
Views:
15
>That's not exactly the problem. On the fly I create a datasource in MS Word. After creating my datasource I edit my datasource. This action gives me an entry to a word-document containing 1 table including my header record.
>
>The next step is expanding this table and fill all te cells with data.
>
>oTable = oWord.Activedocument.Tables[1]
>oRow = oTable.Rows[2] && The first row contains header information
>
>SELECT myQuery
>SCAN
> FOR nField = 1 TO FCOUNT()
> oRow.Cells[nField].Range.InsertAfter( EVAL( FIELDS( nField )))
> ENDFOR
> oRow = oTable.Rows.Add()
>ENDSCAN
>oRow.Delete()
>
>This routine is very slow when I have to process 5000 records containing 21 fields. I need a solution to create in MS Word on the fly a datasource containing all my data.
>
>The template used for the mailmerge is created by the user. I don't know the exact details of this letter.
>
>Sander

Oh my this is not a mailmerge. This sounds like a table insertion into word in an expensive way and yes it'd be dog slow. If I understood you right try this (sorry couldn't strip needed part for you - but key is InsertDatabase) :
select ... into table (lcFreeTableName)	&& Select recs into a temp table

lcFreeTable = alias()
lcDefDir = sys(5)+curdir()
* Prepare DSN strings
cDSN = "DSN=FoxPro Files;DBQ="+lcDefDir+";DefaultDir="+lcDefDir+";"
cSourceDB = ""
cSourceType = ""
cOther = "DriverId=536;MaxBufferSize=512;PageTimeout=5;"
cDataSource = dbf(lcFreeTable)
cSQLStatement = "SELECT * FROM "+lcFreeTableName+".dbf"

* Save caption names to array aFieldAndCaptionNames
DIMENSION aFieldAndCaptionNames[fcount(),2]
FOR ix = 1 to fcount()
	aFieldAndCaptionNames[ix,1] = field(ix)
ENDFOR
USE

SELECT field_name,label_grid from (DefaultDataPath + LookupData) ;
	where file_name = tcTableName ;
	into cursor myDD2

FOR ix = 1 to alen(aFieldAndCaptionNames,1)
	aFieldAndCaptionNames[ix,2] = trim(aFieldAndCaptionNames[ix,1]) && if !locatable use default
	LOCATE for field_name = aFieldAndCaptionNames[ix,1]
	if !eof()
		aFieldAndCaptionNames[ix,2] = trim(label_grid)
	endif
ENDFOR
USE

.Bookmarks(tcBookmarkName).Range.Collapse(wdCollapseEnd)
* Insert table data to word
oRange = .Range(.Bookmarks(tcBookmarkName).Range.Start, .Bookmarks(tcBookmarkName).Range.End)
oRange.InsertDatabase( ;
		wdTableFormatContemporary, 47, 0, ;
		cDSN+cSourceDB+cSourceType+cOther, ;
		cSQLStatement, ,,,,, cDataSource,,,1)
oRange = .NULL.
* Set the heading row fieldnames to label_grid captions from dd2 table
WITH .tables(tnTableNumber)
	FOR ix = 1 to alen(aFieldAndCaptionNames,1)
		_SetCellHeading(ix,aFieldAndCaptionNames[ix,2])
	ENDFOR
ENDWITH
erase (lcFreeTableName+".*") && Erase temp file(s)
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