A question of developers in the database management system is that the report of our Chinese is too complicated! There is no rules, nested, slash, cross lines, etc. have always been a biggest problem that developers. Designing a database has certain skills, designing data operations also requires certain logical analysis capabilities, but these issues should not be a problem for general developers. Users can do how flexible algorithms you have use, how is their most interested in how they come out beautiful, and how to make the operation of the report, it is better to solve all problems. The author also has some experience in developing the database management system. From FoxPro, Delphi, Powerbuilder has been in the current VB, all of which have been designed and printing reports. These software can be said in the process of design reports, I am not here. One thin. I am here only to introduce a method I have to design a designed print report so far: using VB operation Excel to generate complex reports.
1. Create an external Excel object with VB
Most large ActiveX-Enabled applications and other ActiveX components provide an external external to which to create an object in their object level. This object provides access to other objects in this level, and also provides methods and properties for the entire application.
For example, each Microsoft Office application provides a top-level Application object. The following statement shows a reference to the Application object of Microsoft Excel:
DIM XLAPP as Excel.Application
Set xlapp = new excel.Application
---- Then you can use these variables to access the slave objects in the Excel application, as well as the properties and methods of these objects. E.g:
Set XLAPP = CreateObject ("Excel.Application")
'Activate Excel Application
XLapp.visible = false 'Hide Excel Application Window
Set xlbook = xlapp.workbooks.open (strDestination)
'Turn on the workbook, strDestination is an Excel report file
Set xlsheet = xlbook.worksheets (1)
'Setting a worksheet
---- II. Template documents for design reports with Excel 97
---- Excel 97 is a very good tool for creating a report. It provides the cell apparent merger, split, and drawing functionality can basically meet the needs of all complex reports. It provides powerful support for any of the formats of any cell, providing a strong support for the designed reports that you want.
---- According to the report provided by the user, we can quickly generate a template file in Excel. The so-called generating template file is only designed to meet the needs of users. It is also a little preparatory work to be made for changes in the report. For example, the user needs to print hundreds of employee resumes, but its format is consistent, and with time and actual changes, the form of format may need to change. We design a template file obviously "can change "
---- We should record the cell number to populate the content and the data field to be filled in the cell. This forms a table, which is clear when writing the program. Such as:
Cell (4, 2) employee name Cell (6,6) graduation school
Cell (4, 4) Social Gender Cell (6,7)
Cell (4, 6) Workers National Cell (6,9) Working Time
(Table I)
---- We do not operate in the program, we only need to operate a copy of the template file (this is also a purpose and benefit of our design template file). Such as follows:
DIM strsource, strDestination as stringstrsource = app.path & "xexcels/registerfee.xls"
'Registerfee.xls is a template file
STRDESTINATION = App.Path & "Perxcels/temp.xls"
Filecopy Strsource, StRDESTINATION
'Copy the template file to a temporary file
---- III. Generate Worksheet Content
---- With the above-mentioned two-step work, we will then assign each cell according to the format of (Table 1). Such as:
Datprimaryrs.Recordset.Movefirst
'Datprimaryrs for DATA controls
IF isnull (Datprimaryrs.Recordset! Name) = false kil
Xlsheet.cells (4, 2) = DATPRIMARYRS.Recordset! Name
END IF
IF isnull (Datprimaryrs.Recordset! Gender) = false the
Xlsheet.cells (4, 4) = DATPRIMARYRS.Recordset! Gender
END IF
IF isnull (Datprimaryrs.Recordset! National) = false kil
Xlsheet.cells (4, 6) = dateprimaryrs.recordset! nation
END IF
..................
Four. Print report
After generating a worksheet, you can issue a print instruction to Excel.
Note that the Excel temporary file should be performed once before performing the print operation, so as not to ask the user if the Excel prompts the user to save the modified file so that users feel inexplicably. The following statement:
XLbook.save 'Save File
Xlsheet.printOut 'Execute Print
XLapp.quit 'Exits Excel
At this reader, it should be seen that the report prints we designed are implemented by the Excel program. The user does not see the specific process, and they only see a beautiful report is easily printed.