Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Export to excel Slowwwwwwww
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00503903
Message ID:
00503906
Vues:
24
Is there a fast way to append a whole cursor/table to for example worksheet 3 starting at row 6? like :
oExcel.Worksheet(3).InsertDBF(6,1)


Hello,

Here is one solution based on Cetin Basoz's contributions: I hope it helps.

Kevin

************************************************

** First create your cursor and then run Cetin's table2clipboard() program
=zTable2ClipBoard()
#include "vfp_excel.h"
oExcel = createobject("Excel.Application")
WITH oExcel
.visible = .t.
.Workbooks.Add
WITH .ActiveWorkbook.ActiveSheet
** Here you can go to any row/column before pasting
.Paste
** here , I also go through and look for memo fields and set the width to 40 and turn on autowrap (not shown)
.Range("A1").Select
.Cells.Select
.Cells.Columns.AutoFit
ENDWITH (.activesheet)
endwith (oExcel)

Now Cetin's table2clipboard program:

*!* FUNCTION zTable2ClipBoard
lcTempFileName = "X"+sys(2015)+".tmp"
handle = fcreate(lcTempFileName) && Create a temp file
#DEFINE TABULATE chr(9)
#DEFINE NL chr(13)

FOR ix = 1 to fcount()
=fwrite(handle, field(ix))
IF ix < fcount()
=fwrite(handle, TABULATE)
ENDIF
ENDFOR
=fwrite(handle, NL)
SCAN && Start scan..endscan
FOR ix = 1 to fcount() && Write field values
=fwrite(handle, typeconvert(ix) )
IF ix < fcount()
=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)

FUNCTION typeconvert
LPARAMETERS ix
*!* LPARAMETERS tnField
lcType = type(field(ix))
IF lcType = "G"
lcField = field(ix)
RETURN transform(&lcField)
ENDIF
luValue = eval(field(ix))
DO case
case isnull(luValue) && added due to error in Oracle with null fields
lcValue=""
CASE lcType = "D"
lcValue = dtoc(luValue)
CASE lcType = "T"
lcValue = ttoc(luValue)
CASE lcType $ "NY"
lcValue = padl(luValue,20," ")
CASE lcType = "L"
lcValue = iif(luValue,"Yes","No")
CASE lcType $ "M" && Replace paragraph marks with "~"
lcValue = strtran(luValue, chr(13)+chr(10), space(5))
*!* lcValue = strtran(luValue, chr(13)+chr(10), "~")
*!* Now Replace enter chr(13) with some spaces to solve excel issue
luValue = lcValue
lcValue = strtran(luValue, chr(13), space(5))
CASE lcType $ "C"
lcValue = luValue
OTHERWISE
lcValue = ""
ENDCASE
RETURN alltrim(lcValue)
*!* Çetin Basöz



Kevin Emmrich
www.jkt9000.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform