Lead all data sheets in Excel with VFP

zhaozj2021-02-12  143

In the program application of the database, it is often used to transform the data from a file format from one file format. At this time, OLE is the uppermost choice. OLE technology has become the programmer with its ease of use and platform. The choice is selected. However, when we develop programs, a module can generally only be used to export a data table because the content of the data content is limited, and the table structure must be done in the programming. The author encountered such problems in the process of developing a school management system. After some exploration of the author, it is unrelated to the VFP function to successfully deport the table file. Finally, the source table is derived into Excel. Here, it is proposed for everyone to discuss, and at the same time, it will take this brick to jade, but also hope that the master will enlighten me.

In fact, the principles used by the author are simple. It mainly uses the FCount () and the Fields function in Visual FoxPro. After opening the table, use the fcount () function to get the number of fields in the table. Then use the Fields () function to try the field name of each field. This problem is basically solved. However, in practice, the author discovered that only the field name also could not obtain the value of the fields in the record, the author used the macro to temporarily solve this problem. If a master has a better way. Also hope to advise.

Source code list:

Local myoleapp

Local myfilename

Local myfield

YFILENAME = GetFile ("*. dbf") && gets the source table

Myoleapp = creteObject ("excel.application" && creates OLE objects

Myoleapp.visible = .t.

myoleapp.workbooks.add

Use & myfilenamefor i = 1 to fcount () myoleapp .cells (i, 1) .value = fields (i) endforscan for i = 1 to fcount () Myfield = Fields (i) myoleapp .cells (Recno () 1, i ) .value = & myfield endforendscan

Myoleapp.activeworkBoods.saveas ("Myxls.xls") myoleapp.quit

转载请注明原文地址:https://www.9cbs.com/read-6163.html

New Post(0)