• No results found

Export Method

In document Manual Sheridan DataWidgets (Page 191-194)

Applies To SSDBGrid Description

Exports the contents of the grid to a file.

Syntax

object . Export(Type As Integer, Flags As Integer, ExportToFile As String, [HTMLTemplate As Variant], [OutputFileField As Variant])

Part Description

object An object expression that evaluates to an object or a control in the Applies To list.

Type An enumerated integer indicating the type of file to export, as described in Settings.

Flags An integer expression specifying the options used for export, as described in Settings. Options are specified as a series of bit flags that may be combined using the OR operator. See

Remarks for further details.

ExportToFile A string expression specifying the filename of the export file.

HTMLTemplate Optional. A variant expression specifying the filename of a template file that will be used to format the exported HTML file or files.

OutputFileField Optional. A variant expression that specifies the name (or ordinal number) of the grid column

that contains a unique key that will be used to construct the output file name for each row file.

Used only when Type is set to export row files.

Settings

The settings for Type are:

Setting Description

0 ssExportTypeText. The data will be exported to an ASCII text file.

1 ssExportTypeHTMLTable. Data will be exported in table format to a single HTML file.

2 ssExportTypeHTMLRowFiles. Data will be exported as a series of HTML files, each with a table that contains a single row of data.

There are constants available for the settings of this parameter.

The settings for Flags are:

Setting Description

1 ssExportCurrentRow. The row containing the active cell will be exported.

2 ssExportSelectedRows. All selected rows will be exported.

4 ssExportNonSelectedRows. All non-selected rows will be exported.

7 ssExportAllRows. (Combines bits 1, 2 and 4) - supplied as a convenience

16 (&H10) ssExportFieldNames. Include the field names as a line in the output file.Used only when Type is set to '0 - ssExportTypeText.' Has no effect on HTML exports.

32 (&H20) ssExportColumnHeaders. Include the column headers as a line in the output file.Used only when Type is set to '0 - ssExportTypeText.' Has no effect on HTML exports.

64 (&H40) ssExportInLayoutOrder. Fields will be exported in the order that they are displayed by the grid. If this flag is not supplied, fields will be exported based on their ordinal positions in the Columns collection.

128 (&H80) ssExportHiddenColumns. If specified, hidden columns will be exported. Otherwise, data from hidden columns will not appear in the output file.

256 (&H100) ssExportOverwriteExisting. Replaces any existing output file with the same name as specified in ExportToFile.

512 (&H200) ssExportAppendToExisting. If a file is found with the same name as specified in

ExportToFile, exported data will be appended to the existing file. This option is primarily used when exporting text files.

Note If neither ssExportOverwriteExisting or ssExportAppendToExisting are specified, an error will be generated if a file is found to exist with the same name as was specified in ExportToFile. If both are specified, any existing file will be overwritten.

There are constants available for the settings of this parameter.

Remarks

The Export method gives you the ability to take the data displayed in the grid and move it into an external file for further processing or display. Data can be exported to a plain ASCII text file, or it can be exported to an HTML file for use with a web browser. You specify the name of the file that will be created by passing it as the ExportToFile parameter of the method.

The export method can create three types of export files. For each type of file, you can determine whether to include some or all of the grid data in the output, and whether the generated file should replace an existing file of the same name, or be appended to it. You can also specify how field order will be determined during export. You specify these settings using the Flags parameter of the method. For any type of file, you can choose whether to

export all rows, selected rows, non-selected rows or the current row.

The values specified for the Flags parameter are a series of bit flags that selectively enable or disable

combinations of options. You can specify multiple settings by combining the parameter values using logical OR.

For example, specifying "ssExportFieldNames OR ssExportColumnHeaders" for the Flags parameter will include both field names and column headers in the exported text file.

The first type of file you can generate is a simple ASCII text file. Set the Type parameter of the method to ssExportTypeText (0) to generate a plain text file. You can specify export flags for the Flags parameter that specify whether to include group headers and/or field names as part of the output. The plain text export feature is useful for moving data into a third-party application, such as a spreadsheet. The FieldDelimiter and

FieldSeparator properties are used when specifying this type of export.

The second type of export file is an HTML table file. When you specify ssExportTypeHTMLTable (1) for the Type parameter, the Data Grid will generate a complete HTML page based on the specified contents of the grid.

Although you specify which rows will be exported using the Flags parameter, the remainder of the grid's formatting is determined by an HTML template file. You supply the filename of the template file as the

HTMLTemplate parameter. The control reads the template file, extracts the HTML export codes embedded within the HTML and uses them to determine the formatting of the generated HTML.

You must specify a template file when you are exporting HTML. If you fail to specify a template file, no output will be generated. If you specify a template file when exporting plain text, the template will be ignored.

You must create HTML templates using an HTML or text editor. An extensive knowledge of HTML is not required, as the template format is fairly straightforward. Data Widgets includes several sample templates to get you started, and there is a tutorial that covers the creation and use of export templates in detail. For more information on creating HTML export templates, see HTML Template Codes.

The third type of export file is an HTML row file, created by specifying ssExportTypeHTMLRowFiles (2) for the Type parameter. This is similar to the HTML table file export, except that it generates multiple HTML files - one for each exported row of grid data. This is primarily useful in creating a master/detail web site, where clicking on a cell in the main table brings up a secondary page with related information about the data in that cell.

The names of the generated files are based on field in the data source; for example, if the records in the grid have an "ID" field with values of 12, 13, 14, etc., the Export method can automatically generate multiple files with names such as ID_012.HTM, ID_013.HTM, ID_014.HTM, etc. You implement this feature by specifying the field that will supply the numbers in the OuptputFileField parameter.

Note The method used to construct the output filenames varies depending on whether you are operating on a 16-bit or 32-bit platform. In a 16-bit environment, the name of the output file is taken from the first 4 letters of the file name specified as the ExportToFile parameter. This allows for up to 4 digits to be appended to the name of the generated file while still observing the 16-bit (8.3) filename length limit. In a 32-bit environment, support for long filenames eliminates the need to truncate the supplied output filename; the digits from the field specified by OutputFileField are simply appended to the filename specified in ExportToFile.

Once you invoke the Export method, the export begins. You can further monitor and control the export process using the RowExport event, which is fired once for each row of grid data exported into a file.

See Also

FieldDelimiter, FieldSeparator, HTML Template Codes, RowExport Example

The following are two common uses of the Export method. The first exports grid data to a formatted HTML file, the second to a plain text file with column headers.

Private Sub cmdExport_Click()

'Export all rows of the grid (exactly as it appears on screen) 'to HTML using template.htm as the template file.

SSDBGrid1.Export ssExportTypeHTMLTable, ssExportAllRows, _ App.Path & "\Generated File.htm", App.Path & "\template.htm"

'Export selected rows of the grid to a text file,

'with the first line containing the field names.

SSDBGrid1.Export ssExportTypeText, ssExportFieldNames & _ ssExportSelectedRows, App.Path + "\Generated File.txt"

End Sub

In document Manual Sheridan DataWidgets (Page 191-194)