|
|
|||
Home Products Downloads Registered users Support Prices Order Primary Subscription |
|
||
Other optionsIn addition to range options and column options, XL Report processes several sheet options and report options. The first ones have an influence upon a worksheet, and the second, accordingly, on a report workbook. Both are used to automate getting the optimal height and width for cells, scaling to the installed printer, hiding some worksheets and protecting them from changes. Sheet optionsWhere? QDemo.dpr form: frmOpts1; unit: fOpts1; template: tOpts1.xls You need to specify the sheet options in the A2 cell of a given worksheet. When processing every worksheet of the template, XL Report checks that cell's value. When XL Report recognizes any options, it takes some additional actions. Here they are:
Note The A2 cell will be cleared only if it contains any XL Report options. So you can use this cell for your own needs. This rule also refers to the A1 cell that contains report options. Some XL Report users, knowing that report options can be specified on any sheet, create a hidden worksheet with report options. Report optionsWhere? QDemo.dpr form: frmOpts2; unit: fOpts2; template: tOpts2.xls Report options should be placed in the A1 cell of any sheet (or sheets - in this case all the options supplied will count) of a template workbook. While processing every sheet of a template, XL Report checks this cell. When XL Report recognizes any options it takes some additional actions. Here is the options list:
Visualize report generationWhere? QDemo.dpr form: frmEvents1; unit: fEvents1; template: tEvents1.xls Analytical reports can contain lots of data. So, report generation can take a lot of time. To reassure the user that the program is progressing appropriately, we recommend you use the OnProgress property of the TxlReport class declared as follows:
property OnProgress: TxlOnProgress; type
TxlOnProgress = procedure (Report: TxlReport; Position, Max: integer) of object;
Report generation consists of several steps. You get the number of steps in the Max parameter. The current step is kept in the Position parameter. By using the TProgressBar component named pbReport, you can process the event this way:
procedure TfrmEvents1.xlReportProgress(Report: TxlReport; Position, Max: Integer); begin
pbReport.Min := 0;
end;
pbReport.Max := Max; pbReport.Position := Position; Note the assignment statement pbReport.Max:=Max. The report generation algorithm consecutively parses a template. This means that at some stage the total amount of steps needed is unknown. For example, no one can know before list range option processing if there is a need to create a pivot table. That's why the Max value can change in run-time. OnBeforeBuild and OnAfterBuild eventsWhere? QDemo.dpr form: frmEvents2; unit: fEvents2; template: tQuickStart.xls XL Report can open and close the datasets engaged in report building automatically. The TxlReport instance has the Options property which roAutoOpen and roAutoClose inhabit. If they are True, then all unopened datasets will be opened before report building and, accordingly, they will be closed immediately after report building. Since parameterized queries are often used, however, you will need to initialize these parameters. We recommend you use the OnBeforeBuild event of TxlReport class or the OnBeforeDataTransfer event of DataSources collection item (TxlDataSource class):
property OnBeforeBuild: TxlReportHandleEvent; type
TxlReportHandleEvent = procedure (xlReport: TObject) of object;
property OnBeforeDataTransfer: TxlDataTransferHandleEvent; type
TxlDataTransferHandleEvent = procedure (DataSource: TxlDataSource) of object;
The TxlReport and TxlDataSource classes both have the Tag property, which is usual in Delphi and often used to distinguish between components in a common event handler. If using this property the OnBeforeBuild handler looks like the following:
procedure TfrmEvents2.xlReportBeforeBuild(Report: TObject); begin
case TxlReport.Tag of
end;
10: tblOrders.ParamByName('CustNo').AsInteger :=
tblCustomers.FieldByName('CustNo').AsInteger;
end;
The form used as example in this chapter shows a list of clients from the Customer.Db table. The report goal is to show all orders for a given client. So we created the query whose CustNo parameter is initialized in this event handler. The DataSources collection item containing tblOrders dataset has rgoAutoOpen and rgoAutoClose flags that were set to True. So report building passes through the following stages. First, in the OnBeforeBuild handler, the CustNo parameter of the query is set equal to the value of the same field in the client table. Then the rgoAutoOpen flag is handled - the query is opened and the report is built. After report generation rgoAutoClose is handled - the query is closed. We recommend you use this approach to minimize the need for system resources. TxlReport.Options - options of a reportWhile working on previous examples, you might run into a property that follows VCL fashion. Some of the Options' flags are complete analogs of sheet and report options of a template; others are accessible in the Delphi Object Inspector only.
property Options: TxlReportOptionsSet read FOptions write SetOptions
default [xroOptimizeLaunch, xroDisplayAlerts, xroAutoOpen];
type
TxlReportOptions = (xroOptimizeLaunch, xroNewInstance, xroDisplayAlerts,
xroAddToMRU, xroAutoSave, xroUseTemp, xroAutoOpen, xroAutoClose, xroHideExcel);
TxlReportOptionsSet = set of TxlReportOptions;
TxlDataSource.OptionsDataSources collection items have their own Options property. In contrast to TxlReport.Options, this property relates to a given dataset that is bound to the collection item or to the given range into which the data is put. Here they are.
property Options: TxlRangeOptionsSet; default [xrgoAutoOpen]; type
TxlRangeOptions = (xrgoAutoOpen, xrgoAutoClose);
TxlRangeOptionsSet = set of TxlRangeOptions;
Add a report to an existing workbookWhere? QDemo.dpr form: frmAddF1; unit: fAddF1; template: tAddF1.xls+tExistingBook.xls This example adds the Sheet1 worksheet to the tExistBook.xls. If the Sheet1 worksheet already exists in the target workbook the added worksheet will be renamed according to Excel naming convention. Thus Sheet1 will become
procedure ReportTo(const WorkbookName: string; const NewWorkbookName: string = '');
The WorkbookName parameter allows you to specify the workbook that receives the report's worksheet. The NewWorkbookName parameter allows specifying the name of the workbook, which will receive the final report. The following examples demonstrate the logics of the method:
xlReport.ReportTo('', ExtractFilePath(ParamsStr(0)) + 'NewBook.xls'); xlReport.ReportTo('..\WB1.xls', ExtractFilePath(ParamsStr(0)) + 'NewBook.xls'); The first example causes creation of a report and saving it in NewBook.xls, while the second one creates a report, adds it to WB1.xls, and saves the resulting report in NewBook.xls. XL Report creates a report going through usual chain of methods and events, and adds all non-hidden worksheets of the report workbook to the workbook specified. The OnlyValues option will be applied to every worksheet added. And more, all names referencing the worksheet added will be destroyed. The report worksheets are added after the last existing worksheet. XL Report fires an exception if the WorkbookName file doesn't exist and keeps silence if the NewWorkbookName file exists. Several reports in one workbookWhere? QDemo.dpr form: frmAddF2; unit: fAddF2; template: tAddF2.xls.xls XL Report contains the MergeReports class method that allows you to merge several reports in one workbook.
class procedure MergeReports(Reports: array of TxlReport;
SheetPrefixes: array of string);
You should pass an array of TxlReport instances - the reports that you want to be merged - to the Reports parameter. Every process of report generation in this case is isolated from other report generation processes so you will not be bothered with existing event handlers for every report or with macros in their templates. After processing the current report, the OnlyValues option will be applied to its visible worksheets and every name (the Name object) will be deleted from them (in order to prevent probable name conflicts). All the reports will be added to the first instance of TxlReport in the Reports array. Every worksheet will be added with its own name prefixed with the prefix taken from the SheetPrefixes parameter. You should ensure that both of the arrays have equal number of elements. Custom options - the XLOptionPack technologyXL Report supports the XLOptionPack technology that allows the developer to create option packages. This technology bases on the architecture of XL Report, which permits expanding the space of options due to specially designed additional components. These components must be descendants of the TxlOptionPackage component class that encapsulates the mechanisms required in option package creation. Every option in such a package must descend from the TxlOption class. You can find detailed information on creating custom options and option packages in "XLOptionPack Developer's Guide". Time to look back - other optionsPlease remember that:
|
Components
Developed forDelphi 4, 5, 6, 7 Excel version supportedMS Excel 97 (SR2)
[ Download it ] |