Exporting reports from the previewer
Similarly to printing, when users click the “Export” button in the previewer toolbar (), the Export method of the XFCont class is called. This method displays a dialog box with output type and a file name selection and converts the XFF file that is being previewed to the output document:
If you would like to create your own custom exporting solution, you can either setup an extension handler (please see Registering an extension handler paragraph above in this chapter for more information) or you can create a child of the XFCont class and override the Export method. There are five events that extension handler can implement:
Name | Description |
---|---|
BeforeSetParams | The method is executed right before calls SetParams() method and can be used to parametrize the xfrx session object before exporting. |
BeforeExport | The method is executed right before the report is exported to the output format and can be used to parametrize the xfrx session object before exporting. |
AfterExport | The method is executed right after the report is exported to the output format and can be used to copy output file to another folder. |
This method is called when the Export button is clicked in the toolbar. | |
BeforeExportOptions | This method is called before the Export Options dialog is opened. |
This method is called after the Export Options dialog is closed, before the actual Export is executed |
The export parameter object has the following properties:
Name | Type | Description |
---|---|---|
cTarget | string | XFRX output type. |
cPageScope | string | Enter page numbers and/or page ranges separated by commas (e.g. 3,4,5-9). |
cOutputFile | string | Output file. |
lNotOpenFile | boolean | Specifies whether a XFRX open file after creating. |
lShowDialog | boolean | Specifies whether a XFRX call "Print options" dialog. |
lExport | boolean | Specifies whether a XFRX export to output. |
number | Include all pages, odd or even only. | |
Copies | number | The number of copies. |
Zoom | number | The number of pages per sheet. |
ImageDPI | number | Image DPI. |
aFindString | array | A array contains strings for highlight. The array can has one column - than background color will be yelow for all strings. Or cab has two columns - than second column contains background color for string. |
nAppendMode | number | Append mode for PDF, RTF, FRTF and PLAIN. |
nAMFromPage | number | For nAppendMode 4 - The generated report will be inserted to the existing document at the given page number. For nAppendMode 5 - first page for replacing in original document. |
nAMToPage | number | For nAppendMode 5 - last page for replacing in original document. |
cArchive | string | Archive (zip) file name. |
lArchiveAdditive | boolean | Append to archive. |
lArchiveDeleteFileAfter | boolean | Delete file(s) after creating archive. |
oWM | object | Watermark object. |
oEffect | object | Effect object |
Extension handler examples
USE invoices ORDER customer LOCAL m.loSession, m.lnRetval, m.loXFF, m.loPreview, m.loScripts m.loSession=EVALUATE([xfrx("XFRX#LISTENER")]) m.lnRetVal = m.loSession.SetParams("",,,,,,"XFF") && no name = just in memory IF m.lnRetVal = 0 REPORT FORM invoices OBJECT m.loSession m.loXFF = m.loSession.oxfDocument * * initialize the previewer * SET CLASSLIB TO xfrxlib ADDITIVE m.loPreview = CREATEOBJECT("frmMPPreviewer") m.loPreview.setExtensionHandler(CREATEOBJECT("MyExtensionHandler")) m.loPreview.windowType = 0 m.loPreview.iBook = 0 m.loPreview.PreviewXFF(loXFF) m.loPreview.show(1) ENDIF DEFINE CLASS MyExtensionHandler AS Custom PROCEDURE Export LPARAMETERS m.toXFF IF USED("_xfExportTypes") USE IN _xfExportTypes ENDIF * * define my export options list * CREATE CURSOR _xfExportTypes (name C(50), extension C(4), targetCode C(10)) INSERT INTO _xfExportTypes VALUES ("HTML", "html", "HTML") INSERT INTO _xfExportTypes VALUES ("PDF", "pdf", "PDF") INSERT INTO _xfExportTypes VALUES ("Excel", "xls", "XLS") ENDPROC PROCEDURE ExportOptions LPARAMETERS m.toXFF, m.toOptions IF m.toOptions.cTarget = "XLS" * * my own code to handle output to Excel * =MESSAGEBOX("exporting to "+m.toOptions.cOutputFile) RETURN .F. && suppress the default behavior ELSE RETURN .T. && continue with the default behavior ENDIF ENDPROC ENDDEFINE
SET PATH TO xfrxlib SET CLASSLIB TO xfrxlib LOCAL m.loPreview, m.loSession, m.loExtensionHandler m.loExtensionHandler = CREATEOBJECT("myExtensionHandler") m.loPreview = CREATEOBJECT("frmMPPreviewer") m.loSession=EVALUATE([xfrx("XFRX#LISTENER")]) * * create a memory XFF file * m.lnRetVal = m.loSession.SetParams(,,,,,,"XFF") IF m.lnRetVal = 0 SELECT * ; FROM customers INNER JOIN orders ON customers.customerid = orders.customerid ; INNER JOIN orderdetails ON orders.orderid = orderdetails.orderid ; ORDER BY customers.companyname, customers.customerID, orders.orderID ; INTO CURSOR custlist REPORT FORM custlist OBJECT loSession ENDIF * * assign the extension handler * m.loPreview.setExtensionHandler(loExtensionHandler) * * preview the report * m.loPreview.previewXFF(m.loSession.oxfdocument) m.loPreview.show(1) DEFINE CLASS myExtensionHandler AS CUSTOM PROCEDURE Print LPARAMETERS m.toXFF RETURN .T. && continue with the default behavior ENDPROC PROCEDURE Export LPARAMETERS m.toXFF * * now you can process the XFF file * RETURN .F. && override the default behavior ENDPROC ENDDEFINE
USE demoreps\invoices ORDER customer LOCAL m.loSession, m.lnRetval, m.loXFF, m.loPreview, m.loScripts m.loSession=EVALUATE([xfrx("XFRX#LISTENER")]) m.lnRetVal = m.loSession.SetParams(,,,,,,"XFF") && no name = just in memory IF m.lnRetVal = 0 REPORT FORM demoreps\invoices object m.loSession * * the XFRX#DRAW object reference is stored in oxfDocument property * m.loXFF = m.loSession.oxfDocument * * initialize the previewer * SET PATH TO xfrxlib SET CLASSLIB TO xfrxlib ADDITIVE m.loPreview = CREATEOBJECT("frmMPPreviewer") * * setup the extension handler * m.loPreview.oExtensionHandler = CREATEOBJECT("SampleExtensionHandler") m.loPreview.windowtype = 1 m.loPreview.iTool = 2 && embedded toolbar m.loPreview.PreviewXFF(m.loXFF) m.loPreview.show(1) ENDIF DEFINE CLASS SampleExtensionHandler as Custom PROCEDURE BeforeExport LPARAMETERS m.toSession, m.toExportParameters m.toSession.setAuthor("Martin") && set the document author property IF m.toExportParameters.cTarget = "XLS" && (XLS or XLSPLAIN) m.toSession.SetOtherParams("DISPLAY_GRID_LINES",.F.) && do not display gridlines in excel ENDIF ENDPROC PROCEDURE AfterExport LPARAMETERS m.toSession, m.toOptions IF m.toOptions.cTarget = "XLS" *COPY FILE (m.toOptions.coutputfile) TO ([anybackupfolder]\[anyfile.xls]) ENDIF ENDPROC ENDDEFINE