C1Flexgrid is one of the most popular grid controls as of now, in the market. This is so because the control is not only user friendly but has hordes of features that can be quite useful. These features, though in abundance individually, can also be merged together to provide some very cool options. One of these features is that of Export and Export to Excel in particular. When we export the grid to an Excel sheet, there are a number of flags that we can set, and then the better implementation is using these flags in combination with each other. These flags are stored in the FileFlags enum, and are to be set in the SaveExcel method's overload. Now when we use these flags in combinations, there are different precedences that are applied at the time of final exported columns and rows. With the help of this blog, what I want to show is what is the end result, we obtain, when we use different combinations of the export flags. For the sake of simplicity, I have used a simple flex control on the form, bound to the Categories table from the Nwind db. The CategoryName column has been hidden so that we can check all the options available in the FileFlags enum
- IncludeFixedCells And VisibleOnly Setting these two flags would ensure that the column and row headers are exported, and the hidden columns are not at all exported to the saved excel sheet
- IncludeFixedCells And SelectedRows Setting these flags again ensures that the column and row headers are exported, along with data from only those rows which were selected on the grid control. Another important aspect is that the columns that were hidden in the original grid are also exported, although their width is set as '0', so they are not apparently visible. If we hover the mouse in between columns then the resize icon shows up. So incase you want hidden data not to be exported, do set this flag in combination with others.
- VisibleOnly And AsDisplayed This is a combination when you would require the grid to be exported as it is to the Excel sheet, i.e. with the styles and formatting preserved. With AsDisplayed there are a few limitations though. The export of colors from excel and open xml file formats differs and that is more because of the color palettes being utilized by the file format coding, rather than the controls behavior.
- IncludeFixedCells And NoFreezing Selecting this combination, helps us include the column and row headers, but also makes sure the excel sheet is not frozen for the headers while scrolling takes place.
For more such interesting combinations please refer to the attached sample, select the flag options from first and second dropdowns, if you only want to check a single flag select "None" in the second dropdown, and hit the "Save to Excel" button, the desired excel file should open up for you. Download Sample