Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exporting a table to xls with formating
Message
From
09/11/1998 05:08:54
Jeroen Naus
Harte-Hanks Europe
Hasselt, Belgium
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Exporting a table to xls with formating
Miscellaneous
Thread ID:
00155650
Message ID:
00155650
Views:
35
Hi,
Here's an example of how easy it is to convert a foxpro table into a nice format. P.S. this example does not contain any error handling.

FUNCTION EXP2XLS
LPARAMETER lcTablename

LOCAL XLApp, XLSheet, lnCounter, lnNumFields

tmpsheet = sys(2015)

PUBLIC &tmpsheet.
&tmpsheet. = GetObject('','excel.sheet')
XLApp = &tmpsheet..application
XLApp.Visible = .t.
SELECT(lcTablename)

* Copying to excel is a lot faster then doing it cell by cell
lcXlsFilename = ALLTRIM(SYS(2023)) + "\" + ALLTRIM(SYS(3)) + ".XLS"
EXPORT TO (lcXlsFilename) TYPE XLS
* Open it up
XLApp.WorkBooks.Open(lcXlsFilename)
XLSheet = XLApp.ActiveSheet

lnNumFields = FCOUNT(lcTablename)
* Making a nice first header line
FOR lnCounter = 1 TO lnNumFields
XLSheet.Cells(1,lnCounter).Value = Proper(FIELD(lnCounter))
XLSheet.Cells(1,lnCounter).Font.Bold = .T
XLSheet.Cells(1,lnCounter).interior.colorindex=15
XLSheet.Cells(1,lnCounter).interior.pattern=1
NEXT
* Make columns as wide as largest field value
XLSheet.Cells.Select
XLSheet.Cells.EntireColumn.AutoFit()
* Freezing the first line (column names)
XLSheet.Range("A2").Select
XLApp.ActiveWindow.FreezePanes = .T.

RETURN

Hope this will help some people doing some weird stuff our end-users love.
Next
Reply
Map
View

Click here to load this message in the networking platform