Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
COPY TO TYPE XL5 limitation?
Message
From
26/10/2000 06:28:04
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
26/10/2000 03:26:59
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00422500
Message ID:
00434468
Views:
14
Daniel,
Nice code but only passes 1st limitation and would fail on 2nd limitation. AFAIK a sheet has 65536 rows with current Excel version. If your data is say 200000 records then it should need to be divided into sheets or books. Also it's slow as you said just for one sheet. For one sheet there's a native way :
-Excel can read dBaseIII, fox2x, csv etc files and they do not have reccount limitation (except system capasities of 1billion).
-Excel could saveas .xls after read if desired.
The fastest way I found to export 65535+ recs is to divide into books. Each 65535 section took about 1.5-3 secs on Athlon 650. For getting them all in one book was more problematic that after first sheet, sheet.copy-paste takes about 17-20 secs for additional sheets (with only 4 column table-supplied below). But good side in Excel w/o automation it even chokes with 65535 recs :)
* LTE 65535 recs
oExcel = createobject("Excel.application")
Copy to temp type fox2x
With oExcel
 .workbooks.Open(sys(5)+curdir()+"temp.dbf")
 .visible = .t.
Endwith
* GT 65535
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

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
  .ActiveWorkBook.Close(.f.) && Close no save
  lnNeededSheets = ceiling( lnTotal / lnMaxRows ) && 1 row header
  ? "Total Pages : "+padr(lnNeededSheets,3," ")
  Copy to temp for recno()<=lnMaxRows-1 type fox2x && One for header
  .workbooks.open(sys(5)+curdir()+"temp") && Open saved
  ? "Page no :   1/"+;
    padr(lnNeededSheets,3," ")+ ;
    "   Elapsed : ",seconds() - start
  If lnNeededSheets > 1
    With .ActiveWorkBook
      lnCurrentSheetCount = .sheets.count
      If lnNeededSheets > lnCurrentSheetCount
        .sheets.add(,.sheets(lnCurrentSheetCount),;
          lnNeededSheets - lnCurrentSheetCount) && Add new sheets after old ones
      Endif
      For ix = 2 to lnNeededSheets
        With .sheets.item(ix)
          .name = "Page "+padl(ix,3,"0")
          .activate
          =InsertGroup(ix, lnMaxRows)
        Endwith
      Endfor
      .sheets.item(1).activate
    Endwith
  Endif
  .visible = .t.
Endwith
? "Total Elapsed : ",seconds() - start

Function InsertGroup
Lparameters tnSheetNumber, tnMaxRows
Local lnPasteStart, lcTempFile
lnPasteStart = ( tnSheetNumber - 1 ) * tnMaxRows
lcTempFile = sys(2015)+".txt"
Copy to (lcTempFile) delimited with TAB for between(recno(),lnPasteStart,lnPasteStart+tnMaxRows)
_Cliptext = filetostr(lcTempFile)
Erase (lcTempFile)
*expression.TextToColumns(Destination, DataType, TextQualifier, ConsecutiveDelimiter, Tab, Semicolon, Comma, Space, Other, OtherChar, FieldInfo, DecimalSeparator, ThousandsSeparator)
With oExcel
  .workbooks(1).sheets.Item(tnSheetNumber).activate
  .workbooks(1).ActiveSheet.Range("A1").PasteSpecial()
  _Cliptext = "" && Empty clipboard
  ? "Pasted from ", lnPasteStart,' to ',min(lnPasteStart+tnMaxRows-1, reccount()), "elapsed", seconds() - start
Endwith

? "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
Next
Reply
Map
View

Click here to load this message in the networking platform