[ieee 2011 international conference on consumer electronics, communications and networks (cecnet) -...
TRANSCRIPT
Methods of Appling Excel in VFP
Lijun Wang, Jiuming Liu Institute of Information Spreading Engineering
Changchun University of Technology Changchun, 130012, China
Abstract—In the development of management software, it is often necessary to put the query data in Excel for output or secondary exploitation. Both VFP and Excel can be used for the processing of database tables, and it would greatly facilitate our work with a skillful combination of the advantages of both. This paper, based on the development experience of Telecommunications Engineering Business Management System, mainly introduces how to operate Excel files to complete the above functions by directly calling Windows API functions and COM components.
Keywords- Visual Foxpro; Windows API; COM Components
I. INTRODUCTION Visual Foxpro is a relational database management system,
and its powerful data- processing ability and good compatibility make it become a main tool used in routine data management; while Excel is excellent spreadsheet processing software with unique advantages in its operation interfaces, formula calculations, charts forms and compatibility, which makes it become popular software among a majority of Office XP personnel. The above two software have been widespread in their respective areas of application, and they also have a good interactive programming capacity with each other, which lays a good foundation for them drawing the strong points of each other to offset their own weakness.
Both VFP and Excel can be used for the processing of database tables, but the reports of Visual Foxpro have been inconvenient, and it would greatly facilitate our work with a skillful combination of the advantages of both. For example, we can apply VFP for data processing, and Excel's print preview function for report printing, and this doing requires us to use Excel indirectly in VFP.
II. ADOPT EXCEL BY CALLING WINDOWS API FUNCTIONS During the development of Telecommunications
Engineering Business Management System, part of the query results need to be converted to Excel according to the users’ needs. Excel can be called directly in VFP by using OLE controls[1], and both the display modes and display properties of the tables can be controlled by macro in the realized Excel, but it won’t do to transfer data between the Excel and database tables. In addition to OLE in calling Excel program, we can also accomplish the above functions by directly calling the Windows API functions, and we actually have adopted the latter method[2-3].
A. Simplified Code of Project Acceptance Form Example The following simplified code of using Project Acceptance
Form tables to establish Excel tables illustrates the method of applying Excel with Windows API functions.
The simplified code of Project Acceptance Form example is as follows:
j0=fcount ()
i0= reccount ()
j=1
Excel Book= CREATEOBJECT ( Excel. application ) && Create Excel Book
ExcelBook.Workbooks. Add && Add Workbooks
do while j<=j0
ExcelBook.Cells(1,j).Value=field(j)
&& Assign Value to Cells
i=1
do while i<=i0
go i
fname= field(j)
ExcelBook.Cells(i+1,j).Value=&fname
&& Assign Value to Cells
i=i+1
enddo
j=j+1
enddo
endif
ExcelBook.Visible=.T.
&& Make Excel Book Visible in Excel
B. Common Modifying and Control Commands on the Style of Excel in VFP According to the users’ request, the code in the 2.1 does not
contain complete functions for the designing of the style of
Identify applicable sponsor/s here. (sponsors)
4178978-1-61284-459-6/11/$26.00 ©2011 IEEE
tables, and it just opens the established tables and displays them with Excel, and then the users have to modify the styles according to their own needs. However, the modification of styles can be achieved by the VFP controls, and several control commands which may be used in the development are listed below:
1 . Operate the cells
assign value to t cells
ExcelBook.Cells(r,c).value= VFP variables or constants
Commonly, the data transferred to excel may be any data supported by VFP
set the width of designated columns
ExcelBook.ActiveSheet. Columns (serial number).ColumnWidth = number of characters
(Unit: number of characters)
autoFit column width
ExcelBook.Columns (serial number).EntireColumn.AutoFit
set the height of designated rows
ExcelBook.ActiveSheet. Rows (1).RowHeight=1/0.035
(Unit: pound), the Row Height is set to be 1 cm in this example
merge cells
ExcelBook.Worksheets("name of Worksheets" ).Range. Merge
The above range must be designated with the start-stop cells, such as "b2d4"
horizontal centering alignment
ExcelBook.WorkSheets("Sheet1").Range("A1:A5").HorizontalAlignment = xlHAlignCenter
vertical centering alignment
ExcelBook.WorkSheets ("Sheet1"). Rows(2).VerticalAlignment = xlVAlignCenter
2 . Set font style and font size
set font style
ExcelBook.ActiveSheet.Cells(r, c).Font.Name = "bald"
set font size (default unit: dot)
ExcelBook.ActiveSheet.Cells(r, c).Font.Size = 16
set font style as italicized
ExcelBook.ActiveSheet.Cells(r, c).Font.Italic = .t.
set font style in the whole column as bold
ExcelBook.ActiveSheet.Columns(c). Font. Bold = .t.
3 . Control the table lines
design the borderline width
ExcelBook.ActiveSheet.Range. Borders (2).Weight=3
The borders parameters: 1 right, 2 right, 3 top, 4bottom, 5 italic\, 6 italic/
set the style of the four border lines
ExcelBook.ActiveSheet.Range.Borders(2). LineStyle=1
The LineStyle value: 1and 7 fine solid, 2 fine dash, 4dotted dash, 9 double fine solid.
III. OPERATION ON EXCEL FILES WITH COM COMPONENTS COM components are with complete Excel controlling
ability which includes not only methods of complex operation, but also underlying operation on Excel files, so that the work efficiency has been improved greatly.
A. Class Library Reference Visual Studio 2005 has provided packaged .Net Excel
programming model of Microsoft Office 2003. In Figure 1, you can see a COM component named Microsoft Excel 12.0 Object Library, after successfully referenced, there will be two class libraries of Microsoft.Office.Core and Microsoft.Office.Interop.Excel[4-5].
Figure 1. Add and reference dialog
B. Basic Application Process 1. Set up a Excel process
Microsoft.Office.Interop. Excel. Application app1 =
new Microsoft.Office.Interop.Excel.Application();
2. Set visibility of the process interface
app1.Visible = true;
3. Set up a Workbook object
Generate new Workbook
Workbook book1 = app1.Workbooks.Add (Type. Missing);
4. Generate a Sheet object
Worksheet sheet1 = (Worksheet) book1.Sheets [1];
5. Set the access range
4179
Range rng1 = sheet1.get_Range (A1:C3, E2:G6, Type.Missing);
6. Operate on the access range
rng1.NumberFormatLocal = “@”; // format as text
rng1.Value2 = “2006147214E00045”;
7. Save operating process
app1.DisplayAlerts = false; // not displaying the saving dialog
book1.Save ();
8. Close the Excel process
app1.Quit ();
IV. CONCLUSION Acting as an active and powerful data base management
system in market, VFP is with a long and glorious developing history and it is a reliable, convenient and efficient data base for programmers.
In the development of management software, it is often necessary to put the queried data in Excel for output or secondary exploitation. Various statements can be made by the VFP statement designer, but its ability of making complex statements especially for making statement of Chinese style is still too weak to meet the work demand; Excel is spreadsheet
software issued by the Microsoft Corporation. It can provide various flexible statement handling methods, but its ability of collecting data from data base and processing data is comparatively weak. We can combine VFP and Excel together by applying Windows API parameters and COM components technology to make them reflect their strengths, so that the users can be serviced by strong data processing and statement printing systems.
REFERENCES
[1] LIAO Jin-hui ,GONG De-liang,LI Jing-fu,The Application of COM Component in Access Database.JISUANJI YU XIANDAIHUA,2005(2),pp.106-111. (In Chinese).
[2] Yu Pengfei, LiHaiyan,Development of Excel Score Statistic Add- ins Based on Com Add- Ins Technology. JISUANJI YU SHUZIGONGCHENG,Vol 34(10),pp.16-19,Oct.2006 (In Chinese).
[3] YUAN Hang, WANG Cheng-yao,Design and implementation of general database access component based on COM. COMPUTER ENGINEERING AND DESIGN,Vol 25(1),pp.105-106,Jan. 2004 (In Chinese).
[4] LI Mei-man, XIA Han-zhu, Yi De-cheng.Design and implementation of general examination system based on COM technique.Computer Engineering and Applications, 2007, 43( 1) : 245-248. (In Chinese).
[5] QU Yun-qian, ZHAO Lei, YANG Ji-wen, The Design and Implementation of a Heterogeneous Data Exchanging Interface Based on Component Technology. JOURNAL OF SOOCHOW UNIVERSITY(ENGINEERING SCIENCE EDITION),Vol 26(2),pp.46-48,Apr.2006(In Chinese)
4180