Ljzsoft WDREPORTCOM User Manual

WDReportCom
User Manual
Version 1.5
Copyright© 2007-2009 LJZsoft Corporation
All rights reserved
Contents
CHAPTER 1 INTRODUCTION...........................................................................................................1
1.1 OVERVIEW......................................................................................................................................1
1.2 FEATURES.......................................................................................................................................1
CHAPTER 2 INSTALLATION AND STARTUP...............................................................................3
2.1 SOFTWARE REQUIREMENTS............................................................................................................3
2.2 INSTALLING WDREPORTCOM ........................................................................................................3
2.3 UNINSTALLING WDREPORTCOM ...................................................................................................4
2.4 WDREPORTCOM.DLL .....................................................................................................................4
2.5 WORDREPORT.EXE.........................................................................................................................5
2.6 RUN-TIME FILES.............................................................................................................................6
CHAPTER 3 QUICK START...............................................................................................................7
3.1 LEARNING HOW TO USE WDREPORTCOM.......................................................................................7
3.2 SAMPLE DATABASE ........................................................................................................................7
3.3 SAMPLES.........................................................................................................................................8
3.4 CREATING A REPORT PROGRAMMATICALLY...................................................................................9
3.5 CREATING A REPORT WITH WORDREPORT.EXE............................................................................10
CHAPTER 4 REPORT TEMPLATES ..............................................................................................12
4.1 ABOUT REPORTS ..........................................................................................................................12
4.2 ABOUT REPORT TEMPLATES.........................................................................................................12
4.3 WORD BASIC CONCEPTS...............................................................................................................12
4.3.1 Documents............................................................................................................................13
4.3.2 Headers and Footers............................................................................................................13
4.3.3 Tables...................................................................................................................................13
4.3.4 Bookmarks............................................................................................................................13
- I -
4.3.5 Page Breaks.........................................................................................................................13
4.3.6 Graphics and Diagrams.......................................................................................................14
4.3.7 Inline Pictures and Floating Pictures..................................................................................14
4.3.8 Charts...................................................................................................................................14
4.3.9 Formatting...........................................................................................................................15
4.3.10 Fields .................................................................................................................................16
4.4 TABLE REPORTS ...........................................................................................................................17
4.4.1 About Table Reports.............................................................................................................17
4.4.2 Creating a Table for a Fixed Table Report..........................................................................17
4.4.3 Creating a Table for a Variable Table Report.....................................................................18
4.4.4 Formatting Cells..................................................................................................................19
4.4.5 Irregular Tables...................................................................................................................20
4.4.6 Referencing Cells.................................................................................................................21
4.4.7 Referencing Tables...............................................................................................................22
4.4.8 Formatting Cells for Pictures..............................................................................................23
4.5 FORM REPORTS.............................................................................................................................24
4.5.1 About Form Reports.............................................................................................................24
4.5.2 Creating Merge Fields or Quote Fields...............................................................................25
4.5.3 Defining Ranges...................................................................................................................26
4.5.4 Formatting Fields for Pictures.............................................................................................27
4.6 CHARTS ........................................................................................................................................28
4.6.1 About Charts........................................................................................................................28
4.6.2 Creating a Blank Chart using Microsoft Graph ..................................................................29
4.6.3 Creating a Blank Chart using Microsoft Excel....................................................................29
4.6.4 Referencing Charts ..............................................................................................................31
CHAPTER 5 API REFERENCE........................................................................................................33
5.1 OBJECTS .......................................................................................................................................33
5.1.1 WDReport Object.................................................................................................................33
- II -
5.2 METHODS.....................................................................................................................................33
5.2.1 FixTableReport Method.......................................................................................................33
5.2.2 VarTableReport Method ......................................................................................................36
5.2.3 GroupTableReport Method..................................................................................................39
5.2.4 FormReport Method.............................................................................................................43
5.2.5 MSGraphChart Method.......................................................................................................47
5.2.6 ExcelChart Method..............................................................................................................49
5.2.7 SetDocVariable Method.......................................................................................................52
5.2.8 WordReport Method.............................................................................................................54
5.2.9 GetTableByIndex Method.....................................................................................................55
5.2.10 GetTableByBookmark Method...........................................................................................56
5.2.11 GetChartByIndex Method..................................................................................................56
5.2.12 GetChartByBookmark Method...........................................................................................57
5.3 EVENTS ........................................................................................................................................58
5.3.1 BeforeConnect Event............................................................................................................58
5.3.2 TemplateOpen Event............................................................................................................59
5.3.3 ReportComplete Event.........................................................................................................60
5.3.4 FunctionBeforeExectue Event..............................................................................................60
5.3.5 FunctionAfterExectue Event.................................................................................................61
5.3.6 FunctionProgress Event.......................................................................................................62
5.4 ERROR MESSAGES........................................................................................................................63
CHAPTER 6 WRF FILES...................................................................................................................65
6.1 USING WRF FILES........................................................................................................................65
6.1.1 About WRF files...................................................................................................................65
6.1.2 Using a WRF file with WDReport Object ............................................................................65
6.1.3 Using a WRF file in command line......................................................................................66
6.1.4 Creating a WRF file.............................................................................................................66
6.1.5 Using parameters.................................................................................................................67
- III -
6.1.6 Converting files....................................................................................................................70
6.2 WRF FILE REFERENCE.................................................................................................................72
6.2.1 WRF File Format.................................................................................................................72
6.2.2 [Data Source] Section..........................................................................................................74
6.2.3 [FILE] Section.....................................................................................................................76
6.2.4 [PARAMETER] Section.......................................................................................................77
6.3 FUNCTION REFERENCE .................................................................................................................78
6.3.1 Fixed Table Report...............................................................................................................78
6.3.2 Variable Table Report..........................................................................................................81
6.3.3 Group Table Report.............................................................................................................84
6.3.4 Form Report.........................................................................................................................88
6.3.5 MSGraph Chart ...................................................................................................................91
6.3.6 Excel Chart ..........................................................................................................................93
6.3.7 DocVariable.........................................................................................................................95
6.3.8 ExecSQL...............................................................................................................................97
CHAPTER 7 ADVANCED REPORTS..............................................................................................99
7.1 EXECUTING MULTIPLE SQL STATEMENTS ....................................................................................99
7.2 USING FORMULA FIELDS ............................................................................................................102
7.3 SORTING, GROUPING AND TOTALING.........................................................................................104
7.3.1 Sorting data........................................................................................................................104
7.3.2 Totaling..............................................................................................................................105
7.3.3 Grouping data and Subreports...........................................................................................105
7.3.4 Subtotaling.........................................................................................................................106
7.4 PICTURES....................................................................................................................................107
7.4.1 Inserting pictures into a report template............................................................................107
7.4.2 Inserting pictures into a report..........................................................................................107
CHAPTER 8 HINTS AND TIPS.......................................................................................................109
- IV -
CHAPTER 9 FORMAT EXPRESSIONS IN DATA CELLS.........................................................115
A.1 FORMATS FOR NUMERIC VALUES..............................................................................................115
A.2 FORMATS FOR STRING VALUES .................................................................................................119
A.3 FORMATS FOR DATE/TIME VALUES...........................................................................................120
CHAPTER 10 LICENSE AND SUPPORT ......................................................................................123
10.1 LICENSE....................................................................................................................................123
10.2 TECHNICAL SUPPORT................................................................................................................124
- V -
Chapter 1 Introduction
1.1 Overview
WDReportCom is a solution that generates reports using Microsoft Word. Using Microsoft Word and WDReportCom, you can create all kinds of reports quickly and easily. WDReportCom includes an ActiveX DLL and an executable file that can be used to develop your applications. It will significantly accelerate your application development. WDReportCom is a template-based solution. To create a report, you need to create a report template file first. The report template file is a Microsoft Word document that defines the layouts and formats of a report. WDReportCom retrieves data from data source and fills data into Word documents.
1.2 Features
WDReportCom includes the following features: Using Microsoft Word as your reporting tool Just use Microsoft Word as your reporting tool. You design reports like layouts, formats and styles directly using Microsoft Word. And you will get reports in Microsoft Word spreadsheet format as a result. Microsoft Word is powerful, flexible and familiar. You do not need to buy and learn extra reporting tools. Making report template directly using Microsoft Word The main advantage of using WDReportCom is based on the fact that all formatting is done directly in Microsoft Word. You can take full advantage of Microsoft Word including text formatting, tables, fields, pictures and graphics, drawing, page setup, headers and footers, preview and printing, VBA, macros,
- 1 -
and more. Accessing to databases using SQL WDReportCom executes SQL statements to extract data from database. Supports all type SQL: DML, DDL and DCL. Multiple SQL statements can be executed in one report building process. You can perform queries on databases, insert data into databases, and create database objects like tables. The power of SQL can be harnessed for maximum efficiency in reporting. Using ADO to access and manipulate data sources Using ADO, WDReportCom can access and manipulate a wide variety of data sources such as Oracle, DB2, Sybase, Informix, Microsoft SQL Server, Teradata, MySQL, Microsoft Access, dBase. Integrating Microsoft Word into your application WDReportCom includes an ActiveX DLL for building application. Developers can save time and meet their users’ needs by integrating the report processing power of WDReportCom into their applications. Command line program WDReportCom includes a command line program WordReport.exe. You can use the program to create reports too. It does not require programming. It is enough if you know how to use Microsoft Word and how to write SQL. Various reporting capabilities WDReportCom provides various reporting capabilities including sorting data, grouping data, subreports, totaling and summarizing data, formatting, charting and pictures. It is easy to create simple reports, and, you can create complex reports.
- 2 -
Chapter 2 Installation and Startup
2.1 Software Requirements
Microsoft Windows 95, Windows 98, Windows NT, Windows 2000, Windows XP, Windows 2003, Windows Vista or later. Microsoft Office 97/98, Office 2000, Office XP, Office 2003 or later.
2.2 Installing WDReportCom
Run the installation program, and follow the instructions to complete WDReportCom installation. For Windows Vista, the data folder should be different from the application folder.
If you don’t have Microsoft Office installed, please install it first. If your environment is Windows 95/98 and Office 97, and you don’t have VB6.0 run-time files installed, please install it. For Windows 2000, Windows XP, Windows 2003 and Office 2000 or later, you do not need to install VB6.0 run-time files because they are included in OS and Office. To install VB6.0 run-time files, just run vbrun60sp5.exe, and follow the instructions. If you don’t have ODBC Driver installed for the database you want to access, please install it. If your OS is Windows 95/98 and you don’t have Microsoft Data Access Components 2.0 (MDAC_TYP) or later installed, please install it. For Windows 2000, Windows XP and Windows 2003, you do not need to install MDAC_TYP because it is preinstalled in OS. To install MDAC_TYP, just run mdac_typ.exe, and follow the instructions.
- 3 -
2.3 Uninstalling WDReportCom
1. Double-click the Add/Remove Programs icon in the Windows Control Panel.
2. Do one of the following: For Windows 2000, Windows XP and Windows 2003 Edition: Click WDReportCom in the Currently installed programs box, and then click the Change/Remove button. For Windows 98 and Windows NT 4.0: Click WDReportCom on the Install/Uninstall tab, and then click the Add/Remove button.
3. Follow the instructions on the screen to complete uninstalling the program.
2.4 WDReportCom.dll
WDReportCom.dll is an ActiveX DLL that provides WDReport object. You can write a program to work with the object. Before you can use the WDReport object, you must create a reference to the object. And you should create references to Microsoft Word and Microsoft Graph Object Library too. To create a reference to the WDReport object
1. Do one of the following: For Visual Basic 6.0 From the Project menu, choose References. For Microsoft Word Visual Basic For Application From the Tools menu, choose References.
2. In the References dialog box, select WDReportCom.
3. You can use the Browse button to search for WDReportCom.dll.
4. In the References dialog box, Select Microsoft Word and Microsoft Graph Object Library to create their references.
- 4 -
5. Declare an object variable of the object's class. Dim wdrpt As WDReport
6. Assign an object reference to the variable by using the New keyword in a Set statement. Set wdrpt = New WDReport
2.5 WordReport.exe
WordReport.exe is an executable program that developed using WDReportCom.dll. It likes WDReportGen command line and can read a WRF file to create a Word report. The syntax of command is:
wordreport <wrf file name> [-D] [-U1 user1] [-P1 pwd1] … [-U10 user10] [-P10 pwd10] [pa1 pa2 … pa10]
wrf file name Specifying a WRF (.wrf) file that tells WDReportCom how to
get data from data sources and how to put data into a report.
-D Display the generated report with Microsoft Word.
-U1 user1 …
-U10 user10
-P1 pwd1 ...
-P10 pwd10 pa1 … pa10 The values of the parameters defined in the WRF file. You can
Specify the user names. user1 is the user name of the first data source. user2 is the user name of the second data source…… Specify the passwords. pwd1 is the password of the first data source. pwd2 is the password of the second data source……
use parameters in SQL statements. WDReportCom will replace the names of the parameters in a SQL statement with the actual values before it executes the SQL statement. You can use no more than 10 parameters in one report.
For example, you have defined two parameters in your WRF file. The first parameter is the sales date, and the second is the category of the product. You can run WordReport.exe as follows: wordreport c:\wordreport\myreport.wrf 1996-05-01 “Dairy Products”
- 5 -
2.6 Run-Time Files
You can distribute royalty-free the run-time files of WDReportCom with your applications. The run-time files are files your application must have in order to work correctly after installation. The following are the run-time files you need to distribute:
File Description wdreportcom.dll The WDReportCom ActiveX DLL. It must be registered. wconv.cfg The file contains the information of the file format. If you
are using WordReport method to convert files, you should include it and copy it to the same directory as wdreportcom.dll.
scrrun.dll Microsoft script runtime. WDReportCom used some
functions in this file. It should be copied to Windows System directory, and must be registered.
To register a DLL file, use regsvr32.exe. For example, regsvr32.exe /s “C:\Program Files\LJZsoft\WDReportCom\WDReportCom.dll”
- 6 -
Chapter 3 Quick Start
3.1 Learning how to use WDReportCom
You can teach yourself how to use WDReportCom by choosing from the methods available in this section:
You can study the samples included with WDReportCom. You can use the detailed descriptions and instructions in this document.
3.2 Sample Database
WDReportCom comes with Sample.mdb, a sample database you can use when learning the program. Sample.mdb is a Microsoft Access database. Virtually all of the examples in this manual are based on Sample.mdb data. The sample reports access the sample database through the ODBC data source name “Report Sample”. When you install WDReportCom, you can choose to add the ODBC data source name. And you also can add the ODBC data source name manually. To create the System DSN “Report Sample”, do as follows:
1. Click the Windows Start button, choose Settings, and then click Control Panel.
2. On computers running Microsoft Windows 2000 or later, double-click
Administrative Tools, and then double-click Data Sources (ODBC). The ODBC Data Source Administrator dialog box appears. On computers running previous versions of Microsoft Windows, double-click 32-bit ODBC or ODBC.
3. Select the System DSN tab, and then press Add button.
4. Choose Microsoft Access Driver (*.mdb), then press Finish button.
- 7 -
5. In the ODBC Microsoft Access Setup dialog box, type Report Sample in the Data Source Name box.
6. Press the Select button, and browse to select Sample.mdb.
7. Press OK button to close the ODBC Microsoft Access Setup dialog box.
8. Press OK button to close the ODBC Data Source Administrator dialog box.
3.3 Samples
After WDReportCom is installed, some samples are installed too. Use these samples to learn WDReportCom. The samples include a sample database, VB sample programs, VBA sample programs and sample reports. They are located in the Application Data\LJZsoft under All Users or your profile folder. WDReportCom was tested with Microsoft Office 2007. Please download the sample reports for Microsoft Office 2007 from our website.
Directory Description {data}\Common\SampleDatabase Contains the sample database
“Sample.mdb”.
{data}\WDReportCom\Samples\WordReport Contains the report template
files (.doc) and the WRF files (.wrf).
{data}\WDReportCom\Samples\VB Contains the sample programs
for VB6.0.
{data}\WDReportCom\Samples\VBA Contains the sample programs
for Microsoft Word VBA.
{data} is the path of the data folder. You can select the data folder when you install WDReportCom. By default, the data folder is the Application Data\LJZsoft folder under All Users. If you install WDReportCom without administrative privileges, the data folder is the Application Data\LJZsoft folder under the current user. The data folder is usually at:
- 8 -
Windows 95/98: C:\windows\All Users\Application Data\LJZsoft Windows NT: C:\WinNT\Profiles\All Users\Application Data\LJZsoft Windows 2000/XP: C:\Documents and Settings\All Users\Application Data\LJZsoft Windows Vista: C:\ProgramData\LJZsoft
3.4 Creating a Report Programmatically
1. Create a template In Microsoft Word, create a report template file named “custlist.doc”. Static values and any Word features included in the template will be included in the generated report. The template file you have created as follows:
2. Write the code in your application. Set con = New ADODB.Connection Set rec = New ADODB.Recordset con.ConnectionString = "Data Source=Report Sample" con.Open strSQL = "SELECT CompanyName, CityName, CountryName, ContactName FROM Customers, Cities, Countries WHERE Customers.CityCode = Cities.CityCode AND Customers.CountryCode = Cities.CountryCode AND Customers.CountryCode = Countries.CountryCode ORDER BY CompanyName, CityName, CountryName" rec.Open strSQL, con wdrpt.VarTableReport Recordset:=rec, Table:=wdTable, CellList:="A2", Reserve:=2
- 9 -
rec.Close
3.5 Creating a Report with WordReport.exe
1. Create a template In Microsoft Word, create a report template file named “custlist.doc”. Static values and any Word features included in the template will be included in the generated report. The template file you have created as follows:
2. Create a WRF file Create a WRF file named “custlist.wrf” using WDReportGen or a text editor. The following is the content of the WRF file.
WordReport Version 2.0 [Data Source] Name1=Report Sample
[File] ReportTemplateFileName=custlist.doc ReportFileName=Report\custlist.doc LogFileName=Log\custlist.log
[SQL] @F1=Report(table=1 cell=A2 reserve=2) SELECT CompanyName ,CityName
- 10 -
,CountryName ,ContactName FROM Customers, Cities, Countries WHERE Customers.CityCode = Cities.CityCode AND Customers.CountryCode = Cities.CountryCode AND Customers.CountryCode = Countries.CountryCode ORDER BY CompanyName,CityName,CountryName
3. Run WordReport.exe wordreport c:\report\custlist.wrf
- 11 -
Chapter 4 Report Templates
4.1 About Reports
The report generated by WDReportCom is a Microsoft Word document. The layouts, formats and styles of the report are defined by a report template, and the data of the report are got from databases such as Oracle, DB2.
4.2 About Report Templates
To make a report using WDReportCom, you should create a report template first. The report template is a Microsoft Word document that defines the layouts, formats and styles of the report. In the Microsoft Word report template, you can input static content such as titles, descriptions, comments, a cover, a company logo, format the static content, and define the format of the data you will get from databases. WDReportCom will generate the report based on the report template file. All static contents and the layouts, formats and styles defined in the report template file will be brought to the final report file.
4.3 Word Basic Concepts
If you have known these concepts of Microsoft Word, please skip this section. For more detail information about Microsoft Word, refer to Microsoft Word Help.
- 12 -
4.3.1 Documents
A document is a Microsoft Word file with extension .doc. You can open and save it using Microsoft Word. Microsoft Word documents may contain a combination of text, formatting and graphics.
4.3.2 Headers and Footers
Headers and footers are areas in the top and bottom margins of each page in a document. You can insert text or graphics in headers and footers - for example, page numbers, the date, a company logo, the document's title or file name, or the author's name - that are printed at the top or bottom of each page in a document.
4.3.3 Tables
A table is made up of rows and columns of cells that you can fill with text and graphics. Tables are often used to organize and present information. You can set borders, shading, alignment and fonts in tables.
4.3.4 Bookmarks
A bookmark identifies a location or selection of text that you name and identify for future reference. For example, you might use a bookmark to identify text that you want to revise at a later time.
4.3.5 Page Breaks
When you fill a page with text or graphics, Microsoft Word inserts an automatic page break and starts a new page. To force a page break at a specific location, you can insert a manual page break.
- 13 -
4.3.6 Graphics and Diagrams
There are two basic types of graphics that you can use to enhance your Microsoft Word documents: drawing objects and pictures. Drawing objects include AutoShapes, diagrams, curves, lines, and WordArt drawing objects. These objects are part of your Word document. Use the Drawing toolbar to change and enhance these objects with colors, patterns, borders, and other effects. Pictures are graphics that were created from another file. They include bitmaps, scanned pictures and photographs, and clip art. You can change and enhance pictures by using the options on the Picture toolbar and a limited number of options on the Drawing toolbar. In some cases, you must ungroup and convert a picture to a drawing object before you can use the Drawing toolbar options.
4.3.7 Inline Pictures and Floating Pictures
Inline picture: A graphic or other object that is positioned directly in the text of a Microsoft Word document at the insertion point. Floating picture: A graphic or other object that is inserted in the drawing layer so that you can position it precisely on the page or in front of or behind text or other objects.
4.3.8 Charts
Charts are visually appealing and make it easy for users to see comparisons, patterns, and trends in data. You can create a chart in a Microsoft Word document using Microsoft Graph or Microsoft Excel. When you create a new chart in Word, Microsoft Graph or Microsoft Excel opens and a chart is displayed with its associated data in a data sheet or worksheet.
- 14 -
4.3.9 Formatting
You can use these formatting features of Microsoft Word to effectively display your data. Characters formatting To make text stand out, you can format the text in selected characters. You can set font, color, size of text, bold and italic formats, animate or highlight the text. Paragraphs formatting You can set text alignment, tab stops, line spacing, spacing before or after paragraphs, and borders. Bulleted and numbered lists Bulleted and numbered lists in Microsoft Word are easy to create. You can quickly add bullets or numbers to existing lines of text, or Microsoft Word can automatically create lists as you type. Borders, Shading, and Graphic Fills Borders, shading, and graphic fills can add interest and emphasis to various parts of your document. You can add borders to pages, text, tables and table cells, graphic objects, pictures, and Web frames. You can shade paragraphs and text. You can apply colored or textured fills to your graphic objects. Automatic formatting By using AutoFormat, you can quickly apply formatting such as headings, bulleted and numbered lists, borders, numbers, symbols, and fractions to your text. You can automatically format a document either as you type or after you've written it. In both cases, you can control which automatic changes Microsoft Word makes. You can also turn off automatic formatting. Style A style is a set of formatting characteristics that you can apply to text, tables,
- 15 -
and lists in your document to quickly change their appearance. When you apply a style, you apply a whole group of formats in one simple task. For example, instead of taking three separate steps to format your title as 16 pt, Arial, and center-aligned, you can achieve the same result in one step by applying the Title style.
4.3.10 Fields
Fields Fields are used as placeholders for data that might change in a document and for creating form letters and labels in mail-merge documents. Microsoft Word inserts fields when you use particular commands, such as the Date and Time command on the Insert menu. You can also manually insert your own fields by using the Field command on the Insert menu. Field codes appear between curly brackets, or braces ( { } ). Fields are somewhat like formulas in Microsoft Excel — the field code is like the formula, and the field result is like the value that the formula produces. You can switch between displaying field codes and results in your document. (Formula) fields (Formula) field calculates a number by using a mathematical formula. You can insert an (Formula) field in a table or in regular text. Computation in tables can be completed using (Formula) fields, such as add, subtract, multiply, divide, sum. Syntax:
{ = Formula [Bookmark ] [\# Numeric Picture ] }
DocVariable field DocVariable field defines a document variable. Each document has a collection of variables, which can be added and referenced by the Microsoft Visual Basic for Applications programming language. This field provides a way to display the contents of the document variables in the document. Syntax:
- 16 -
{ DOCVARIABLE "Name" }
Inserts the string assigned to a document variable. “Name” is the name of the document variable.
4.4 Table Reports
4.4.1 About Table Reports
A table is made up of rows and columns of cells that you can fill with text and graphics. Tables are often used to make reports, and organize and present information. WDReportCom supports two types of table reports: fixed table report, variable table report. Fixed table report: The number of rows and columns in the table is fixed. When WDReportCom executes a SQL statement, directly puts the result data into cells in the table. Variable table report: The number of rows or columns in the table is unfixed, and it is variable as the number of result records. When WDReportCom executes a SQL statement, it repeats the table rows or columns for each record or group, and then puts data into cells of the table.
4.4.2 Creating a Table for a Fixed Table Report
For a fixed table report, you need to create a table in the report template file according to the report. The format of the table is the same as the format in the report, but cells that should be filled data into are blank. When WDReportCom executes a SQL statement, the data values from data source will be filled into these cells.
- 17 -
BA
BA
1
1 2
2 3
3
BA
BA
3.4141
3.4141
5.2202
5.2202
2.783
2.783
The fixed table defined in the report template file
The fixed table filled data by rows in the re port file
4.4.3 Creating a Table for a Variable Table Report
For a variable table report, you also need to create a table in the report template file according to the report. But you just need to reserve some rows/columns in the table for one or two records. WDReportCom will add some rows/columns according to the number of the records returned from data source.
SalesItem IdDate
SalesItem IdDate SalesItem IdDate
SalesItem IdDate
1503 1998-01-01
1503 1998-01-01 2003 1998-01-02
2003 1998-01-02 2503 1998-01-03
2503 1998-01-03 3503 1998-01-05
3503 1998-01-05 5503 1998-01-10
5503 1998-01-10 1503 1998-01-21
1503 1998-01-21 2003 1998-01-25
2003 1998-01-25 1003 1998-01-31
1003 1998-01-31
The variable-rows tab le defined
in the report template file
One record from data source can be put into two or more rows/columns. To do this, you need to create a repeat range that includes two or more rows/columns. The format of the last row/column border can be different from the others. For
- 18 -
The variable-rows table filled data
by rows in the report file
example, the outside borders used double lines, and the inside borders used single lines. To do this, you should reserve the blank rows/columns for 2 records. When WDReportCom inserts some blank rows/columns, the new rows/columns will inherit the format of the first row/column in the reserved rows/columns. WDReportCom will repeat the range for each record. Ranges can be nested. The inside range is the detail range for detail record, and the external range is the group range for group. WDReportCom will repeat the inside range for each record, and repeat the group range for each group.
4.4.4 Formatting Cells
To format cells that contain static contents, use “Format” menu in Microsoft Word. To format cells that contain (Formula) fields, use the switches of fields in Microsoft Word. For more detail information, refer to Microsoft Word Help. For cells in which data are got from database, you can set font, color, alignment using Microsoft Word. But to display values in formatting string, you should use other way. You should write formatting expressions into data cells in the report template file. WDReportCom will get the text of the cell as a format expression before it puts a value into a cell, and output the value using the format expression. In fact, WDReportCom calls the format function in Visual Basic. The text got from a cell is used as the format expression in format function. For a variable table report, WDReportCom will use the format expressions in the reserved rows/columns. For more information about format expression, refer to “Format Expression in Data Cells”.
- 19 -
AmountQuantityDate
AmountQuantityDate
#,##0.00#,##0yyyy-mm-dd
#,##0.00#,##0yyyy-mm-dd #,##0.00#,##0yyyy-mm-dd
#,##0.00#,##0yyyy-mm-dd #,##0.00#,##0yyyy-mm-dd
#,##0.00#,##0yyyy-mm-dd
AmountQuantityDate
AmountQuantityDate
827.795601999-02-18
827.795601999-02-18
1,113.058901999-06-14
1,113.058901999-06-14 1,552.251,2402000-01-21
1,552.251,2402000-01-21
The table defined in the report template file The table generated in the report file
A format expression for numbers can have from one to four sections separated by semicolons. You can define the different formats and colors for positive values, negative values and zeros. For example, the format "$#,##0;($#,##0)" has two sections: the first defines the format and color (black) for positive values and zeros; the second section defines the format and color (red) for negative values. It displays “2345.12” as “$2,345”, displays “-5432” as “($5,432)”. The format “#,##0.00;;” has three sections: the first defines the format and color (black) for positive values, the second defines the format and color (red) for negative values, the third section defines the format and color (blue) for zeros. Note, the first semicolon “;” is red, the second semicolon “;” is blue. The negative values and zeros are printed using the format of the positive value. But the color for negative values is red, the color for zeros is blue. It displays “8.9” as “8.90”, displays “-123” as “-123.00”, and displays “0” as “0.00”.
4.4.5 Irregular Tables
Tables don't have to consist of simple grids. Not every row has to have the same number of columns. You can merge and split cells to create irregular tables. An irregular table is the table that contains split cells or merge cells, and it does not have the same number of cells for each row or column. While an irregular table provides for an attractive way to display data, but it does make it harder to process the document. You have some difficulty to reference
- 20 -
a cell in an irregular table. For example in the following table, for most Office version, cell1 is in column 3 and row 2, cell2 is in column 3 and row 3. But for some lower Office version, cell2 is in column 2 and row 3. Moreover, an error may occur when you try to work with some rows or columns in an irregular table.
CBA
CBA
Cell1
Cell1 Cell2
Cell2
Irregular table
To simplify your work and ensure that report function can be executed correctly, you should regularize the irregular tables. Split the merge cells, and remove the border in these cells. For example, the following table is a regularized table, cell1 is in column 3 and row 2, and cell2 is in column 3 and row 3.
CBA
CBA
Cell1
Cell1 Cell2
Cell2
Regularized table
4.4.6 Referencing Cells
You can reference table cells as A1, A2, B1, B2, and so on, with the letter representing a column and the number representing a row. Cell references in Microsoft Word are always absolute references and are not shown with dollar signs. You can reference an entire row or column in a calculation in the following ways: Use a range that includes only the letter or number that represents it - for
example, 1:1 to reference the first row in the table. This designation allows the calculation to automatically include all the cells in the row if you decide
- 21 -
to add other cells later.
Use a range that includes the specific cells - for example, a1:a3 to
reference a column with three rows. This designation allows the calculation to include only those particular cells. If you add other cells later and you want the calculation to include them, you need to edit the
calculation. Unfortunately, there is no inherent capability of Microsoft Word to inform you of the reference of a cell you have selected. You can get around this problem by using a macro. In the sample file “monthly_sales.doc”, there is a macro called “CellRef”. The macro can tell you the table number and the cell reference. When you position the insertion pointer in a table cell and then run the macro, it displays a message box that shows the table number and the cell reference of the current cell. You can copy the macro “CellRef” into your documents. It is easy for you to reference a cell.
4.4.7 Referencing Tables
You can reference a table by an index number or a bookmark. The index number represents the position of the table in a document. The index number starts at 1. So table 1 is the first table in a document, table 2 is the second table, and so on. You can reference a nested table inside a table by an index number like 2-1-2. Table 2-1 is the first table inside table 2, and table 2-1-2 is the second table inside table 2-1. The max nested level WDReportCom supports is 3. In the sample file “monthly_sales.doc”, there is a macro called “CellRef”. The macro can tell you the index number of a table. When you position the insertion pointer in a table cell and then run the macro, it displays a message box that shows the table number and the cell reference of the current cell. You can reference a table by the bookmark too. If you add a bookmark in a
- 22 -
table, you can reference the table using the bookmark. If you want to reference a nested table inside a table, you must add the bookmark in the nested table. It is very useful if you do not know the number of tables. To add a bookmark in a table, do as follows:
1. Click in the upper-left cell in the first row of the table, and place the insertion point before the text.
2. On the Insert menu, click Bookmark.
3. Under Bookmark name, type or select a name. Bookmark names must begin with a letter and can contain numbers. You can't include spaces in a bookmark name.
4. Click Add. Note: Microsoft Word 97 or lower does not support the nested tables.
4.4.8 Formatting Cells for Pictures
To enhance the visual impact of your report, you can insert pictures into your report. WDReportCom supports many popular graphics file formats: bitmap, JPG, GIF, PNG, TIFF and so on. For the graphics file formats WDReportCom supports, refer to Microsoft Word Help. You should store the path and name of the graphics files in the database, and identify the image fields in the report function. WDReportCom will read the graphics files, and insert them into the cells in the report file. You can adjust the position of the pictures by changing the cell margins. To specify the inserted way, text wrapping style and size, you should write a formatting expression into the cell in the report template file. WDReportCom will get the text of the cell, and insert a picture into the cell according to the instruction in the format expression. The format expression for pictures as follows:
[wrapstyle] [size]
- 23 -
The wrapstyle specifies the inserted way and text wrapping style, and can be one of the following values. The default value is NONE. “NONE” means floating pictures.
Values Description INLINE Inline picture NONE Floating picture, none text-wrapping style SQUARE Square text-wrapping style THROUGH Through text-wrapping style TIGHT Tight text-wrapping style TOPBOTTOM TopBottom text-wrapping style
The size specifies the size of a picture. Possible values are STRETCH, Wnnn or / and Hnnn. "STRETCH" means that the picture is resized to fit within the cell. “W100” means that the width of the picture is set to 100 points. “H50” means that the height of the picture is set to 50 points. The default means the original size. If you just specify the width or height of the picture, not both, WDReportCom will retain the original proportions of the picture when WDReportCom resize it.
Example
inline w120 h90
Remarks
WDReportCom will insert an inline picture, and set the width of the picture to 120 points, the height to 90 points. Note: On Microsoft Word 97 or lower version, it may not work correctly if you insert a floating picture into a table. And it will split the table under some text wrapping style. You should insert inline pictures into a table.
4.5 Form Reports
4.5.1 About Form Reports
Beside table reports, WDReportCom supports form reports too. For a form
- 24 -
Loading...
+ 100 hidden pages