[]
FlexGrid can export data to CSV, Text, XLSX/XLSM, and HTML using the C1.Maui.Grid.Excel assembly. That assembly exposes an Extensions class with an asynchronous SaveAsync method that serializes the FlexGrid into the chosen format and exports the result.
These are the save file formats that this extension supports.
Member | Description |
|---|---|
| Exports to an Excel Workbook |
| Exports to a Comma Separated Values file |
| Exports to a Text file |
| Exports to an HTML file |
This specifies options available for customizing the excel output when grid is exported. These are the row(s) and column(s) export options that this extension supports.
Option | Description |
|---|---|
VisibleOnly | Renders only visible row(s) and/or column(s) |
RenderFrozen | Renders the frozen row(s) and/or column(s) |
SelectedOnly | Renders only the selected row(s) and/or column(s) |
ExludeRange | Excludes explicitly specified ranges |
ExcludeEmpty (Row only) | Excludes empty rows |
RenderGroups (Row only) | Includes grouped rows |
This specifies constants that defines which header cells are displayed in the exported file. These are the row(s) and column(s) grid header visibility options that this extension supports
Option | Description |
|---|---|
None | No header cells are displayed in the output file. |
All | Both column and row header cells are displayed in the output file. |
Column | Only column header cells are displayed in the output file. |
Row | Only row header cells are displayed in the output file. |
This specifies additional options available for rendering merged ranges, formatted values, and images.
Option | Description |
|---|---|
RenderMergedRanges | Render merged ranges in the output |
RenderFormattedValues | Render cell values as formatted in the output |
RenderImages | Includes images; otherwise exports image URIs |
The following example shows how to use the SaveAsync method to export FlexGrid to Excel files. In this example, we used the Name property to name the FlexGrid control as "grid".
XML
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml">
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="btnSave" Clicked="OnSave" />
</ContentPage.ToolbarItems>
<c1:FlexGrid x:Name="grid" FontFamily="Algerian" />
</ContentPage>CSharp
using C1.Maui.Grid;
using GrapeCity.Documents.Excel;
private string FILENAME = "ExportedGrid";
async void OnSave(object sender, EventArgs e)
{
var type = await DisplayActionSheet("Save As", "Cancel", null, "Excel");
string filePath = "";
//Windows
filePath = Path.Combine(
Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments),
FILENAME) + ".xlsx";
//Android, iOS, Mac
filePath = Path.Combine(
Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData),
FILENAME) + ".xlsx";
try
{
await grid.SaveAsync(
filePath, "FlexGrid Sheet", //Sheet Name
SaveFileFormat.Xlsx, //GrapeCity.Documents.Excel.SaveFileFormat: Represents the format in which the workbook is saved
headers: GridHeadersVisibility.Column); //C1.Maui.Grid.GridHeaderVisibility: Specifies constants that defines which header cells are displayed
//Windows
System.Diagnostics.Process.Start(
new System.Diagnostics.ProcessStartInfo
{
FileName = filePath,
UseShellExecute = true
});
//Android, iOS, Mac
await DisplayAlert("Saved", "File has been saved to: " + filePath, "OK");
}
catch
{
await DisplayAlert("Error", "File could not be saved", "OK");
}
break;
}The following example shows how to use the Save method to export FlexGrid to CSV, Text, and HTML files. In this example, we used the Name property to name the FlexGrid control as "grid".
XML
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml">
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="btnSave" Clicked="OnSave" />
</ContentPage.ToolbarItems>
<c1:FlexGrid x:Name="grid" FontFamily="Algerian" />
</ContentPage>CSharp
using C1.Maui.Grid;
private string FILENAME = "ExportedGrid";
async void OnSave(object sender, EventArgs e)
{
var type = await DisplayActionSheet("Save As", "Cancel", null, "CSV", "Text", "HTML");
string PathAndName = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
FILENAME) + "." + type;
switch (type)
{
case "CSV":
grid.Save(
PathAndName,
GridFileFormat.Csv, //C1.Maui.Grid.GridFileFormat: Specifies file formats available for saving the grid
System.Text.Encoding.UTF8,
GridSaveOptions.SaveColumnHeaders);//C1.Maui.Grid.GrisSaveOptions: Specifies options available for customizing the files created by FlexGrid.Save Method
break;
case "Text":
grid.Save(
PathAndName,
GridFileFormat.Text,
System.Text.Encoding.UTF8,
GridSaveOptions.SaveColumnHeaders);
break;
case "HTML":
grid.Save(
PathAndName,
GridFileFormat.Html,
System.Text.Encoding.UTF8,
GridSaveOptions.SaveColumnHeaders);
break;
}
if(type != "Cancel")
{
await DisplayAlert("Saved", "File has been saved to: " + PathAndName, "OK");
}
}
Use
SaveAsyncfor Excel and PDF export.Use
Savefor CSV, Text, and HTML export.File paths must be handled using platform-specific storage APIs (e.g.,
LocalApplicationData).File access behavior varies across platforms (Windows, Android, iOS, macOS).