Saves grid contents and format to a file.
Syntax
[form!]VSFlexGrid.SaveGrid FileName As String, SaveWhat As SaveLoadSettings, [ FixedCells As Boolean ]
Remarks
This method saves a grid to a binary or to a text file. The grid may be retrieved later with the LoadGrid method. Grids saved to text files may also be read by other programs, such as Microsoft Excel or Microsoft Word.
The parameters for the SaveGrid method are described below:
FileName As String
The name of the file to create, including the path. If a file with the same name already exists, it is overwritten.
SaveWhat As SaveLoadSettings
This parameter specifies what should be saved. Valid options are:
Constant |
Value |
Description |
flexFileAll |
0 |
Save all data and formatting information. |
flexFileData |
1 |
Save only the data, ignoring formatting information. |
flexFileFormat |
2 |
Save only the global formatting, ignoring the data. |
flexFileCommaText |
3 |
Save data to a comma-delimited text file. |
flexFileTabText |
4 |
Save data to a tab-delimited text file. |
flexFileCustomText |
5 |
Save data to a text file using the delimiters specified by the ClipSeparators property. |
flexFileExcel |
6 |
Save all data and formatting information to an Excel97 file. This filter does not support frozen color rows or columns. |
Options As Variant (optional)
When saving and loading text files, this parameter allows you to specify whether fixed cells are saved and restored. The default is False, which means fixed cells are not saved or restored.
When saving and loading Excel files, this parameter allows you to specify the name or index of the sheet to be loaded, or the name of the sheet to be saved. If omitted, the first sheet is loaded.
The options for saving fixed rows, columns, and translated combo values include:
Constant |
Value |
Description |
flexXLSaveFixedCells |
3 |
Saves fixed cells. |
flexXLSaveFixedRows |
2 |
Saves fixed rows. |
flexXLSaveFixedCols |
1 |
Saves fixed columns. |
flexXLSaveRaw |
4 |
Saves raw (untranslated) data. |
For example, the options can be written as:
fg.SaveGrid "book1.xls", flexFileExcel
fg.SaveGrid "book1.xls", flexFileExcel, "sheetName"
fg.SaveGrid "book1.xls", flexFileExcel, flexXLSaveFixedCells
fg.SaveGrid "book1.xls", flexFileExcel, flexXLSaveFixedRows
fg.SaveGrid "book1.xls", flexFileExcel, flexXLSaveFixedCols
fg.SaveGrid "book1.xls", flexFileExcel, flexXLSaveRaw
fg.SaveGrid "book1.xls", flexFileExcel,
_
flexXLSaveFixedCells Or
flexXLSaveRaw
Notes
The flexFileFormat option saves global formatting only. It does not save any cell-specific information, not even the number of rows and columns. This allows you to use this setting to create formats that can be applied to existing grids even if they have different dimensions.
Because column widths and row heights are related to the number of rows and columns on the grid, they are not saved or restored if you use the flexFileFormat option. The following is a list of the properties that do get saved and restored if you use the flexFileFormat option:
BackColor, ForeColor, BackColorBkg, BackColorAlternate, BackColorFixed, ForeColorFixed, BackColorSel, ForeColorSel, TreeColor, SheetBorder, GridLines, GridLinesFixed, GridLineWidth, GridColor, GridColorFixed, TextStyle, TextStyleFixed, ScrollBars, SelectionMode, RowHeightMin, MergeCells, SubtotalPosition, OutlineBar, Font, and WordWrap.
If your application requires you to save several grids, you should consider using the Archive method to compress and combine them all into a single archive file. You can later use the ArchiveInfo method to retrieve information from the archive file.
The flexFileExcel option is new in Version 8. It does not require Excel to be present on the machine. You can load and save Excel97 sheets (BIFF9 format), one sheet per workbook only (when loading, you can specify which sheet using the Options parameter).
The Excel filter supports cell values (including formula values), fonts, formats, colors, row and column dimensions. Several improvements have been made so that it now also supports more than 30k rows, word-wrapping and all ColorAlternate and ColorFrozen properties. It does not support features that don't translate into the grid, such as macros, charts, rotated text, cell borders, and other advanced formatting.
Starting in build 200, the control also recognizes a string parameter when saving/loading text files. If the string contains an 'f', fixed cells will be included when saving/loading. If the string contains a 'v', only visible cells will be saved to the text files. For example:
fg.SaveGrid "book1.csv", flexFileCommaText, "fv"