Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy data to an Excel file
Message
From
03/05/2000 13:27:17
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
03/05/2000 13:19:20
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00365662
Message ID:
00365668
Views:
16
>I am using VFP6.0 and attempting to copy a large table to an Excel file. For some reason it stops at around 16,300 records and does not copy anymore. Is there something else I can do?
>
>Thanks, Chris


Chris,
As far as I remember copy to method copies only first 16384 records. If your table has LTE 65536 recs than you could copy to csv or tab delimited and get from excel. If exceeds it or want to control from VFP you would do a series of adding sheets and pasting data in excel. Below is a sample test code for workaround large table transfer :
Clear all
* Create a test cursor
Create cursor testcursor (Rcno i,cType c(10), nType i, dType d)
Rand(-1)
For ix = 1 to 200000 && Create 200000 recs cursor
	Insert into testcursor values ;
		(recco()+1,sys(2015), int(rand()*1000), date()-int(rand()*100))
Endfor

#Define lnPerSheet 30000
Set sysformats on
Set safety off

lnTotal = reccount()
Wait window nowait "Pls wait sending data to Excel..."
Start = seconds()
oExcel = createobject("Excel.application")
With oExcel
	.workbooks.add && Add a new workbook
	lnMaxRows = .ActiveWorkBook.ActiveSheet.Rows.Count && Get max row count
	lnNeededSheets = ceiling( lnTotal / (lnMaxRows - 1) ) && 1 row header
	? "Total Pages : "+padr(lnNeededSheets,3," ")
	With .ActiveWorkBook
		lnCurrentSheetCount = .sheets.count
		.sheets.add(,.sheets(lnCurrentSheetCount),;
		  lnNeededSheets - lnCurrentSheetCount) && Add new sheets after old ones
		For ix = 1 to .sheets.count
			With .sheets.item(ix)
				.name = "Page "+padl(ix,3,"0")
				.activate
				=InsertGroup(ix, lnMaxRows-1)
			Endwith
		Endfor
		.sheets.item(1).activate
	Endwith
	.visible = .t.
Endwith
? "Total Elapsed : ",seconds() - start

Function InsertGroup
Lparameters tnSheetNumber, tnMaxRows
Local jx, lnPasteStart, lnPassCount, lnPasteRecco
* VFP copies 16384 rows at max - 1 header row
lnPasteStart = ( tnSheetNumber - 1 ) * tnMaxRows + 1
lnPasteEnd = min(reccount(), tnMaxRows * tnSheetNumber)
lnPassCount = ceiling( (lnPasteEnd-lnPasteStart+1) / (16384 - 1))
For jx = 1 to lnPassCount
	lnPasteStart = (tnSheetNumber - 1)*tnMaxRows + (jx-1) * 16383 + 1 
	Copy to tempxl type xls for between(recno(),lnPasteStart,lnPasteEnd)
	With oExcel
		.workbooks.Open(sys(5)+curdir()+"TEMPXL.XLS")
		If jx > 1
			.ActiveWorkBook.ActiveSheet.Rows(1).delete && Delete header row
		Endif
		.ActiveWorkBook.ActiveSheet.Cells(1,1).CurrentRegion.Copy
		.workbooks(1).sheets.Item(tnSheetNumber).activate
		lcRangeToPaste = "A"+ltrim(str(iif(jx=1, 1, 2)+(jx-1)*16383))
		.workbooks(1).ActiveSheet.Range(lcRangeToPaste).PasteSpecial()
		_Cliptext = "" && Empty clipboard
		.workbooks(2).close(.f.)   && Close - no save
	Endwith
	Erase "TEMPXL.XLS"
Endfor

? "Page no : "+;
	padl(tnSheetNumber,3," ")+;
	"/"+;
	padr(lnNeededSheets,3," ")+ ;
	"   Elapsed : ",seconds() - start
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