Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate Excel with Visual foxpro 9 (help)

Status
Not open for further replies.

Luiz Eduh

Technical User
Jan 10, 2012
51
US
Hi all,

I'm in the process of learning how to export information to excel but came across an issue that I can seem to resolve.

I have a table ("Testtable") with 4 records (4 rows and 5 columns) see image below
jhrVd5

Testtable_vy3c5g.jpg


In VFP9 im running this code;

Code:
local oExcel, oSheet
oExcel = CreateObject("Excel.Application")
oExcel.Visible = -1   && for debugging
oExcel.Workbooks.Add()
oSheet = oExcel.ActiveSheet
oSheet.cells(1,1).Value = "Name of Company"
oSheet.cells(2,1).Value = orderdate
oSheet.Cells(2,2).Value = line
oSheet.Cells(2,3).Value = item
oSheet.Cells(2,4).Value = customer_number

The code above opens up Excel with the following data on it;
ExcelExport_vpf4eq.png


The code i'm using only grabs what's stored in row 1 on the table. I can't figure out how to get the rest of the data to excel. Im using this approach because I need add format the excel with more data like Name of the company, address, phone number etc..

Any help/suggestions will be greatly appreciated.
Thank you
 
Of course this only pulls over one row. Execel Cell Value is just one Value each, not a controlsource, even less a "columnsource", if there would be such a thing.

Either you do a SCAN..ENDSCAN and fill every cell of every row and column, or you EXPORT TYPE XLS or COPY TO TYPE XLS and postprocess the resulting excel file in terms of the caption row 1.

Bye, Olaf.

 
Of Olaf's choices, doing COPY TO and then post-processing is almost certainly much faster. If you're only dealing with a few records, it doesn't matter, but if you have hundreds or thousands, you'll see the difference.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top