# Exporting FlexSheet

## Content



FlexSheet can be exported to .xls, .xlsx, .htm, .html, .csv, and .txt file formats using [FileFormat](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexGrid.4.6.2/C1.WPF.FlexGrid.FileFormat.html) and [SaveOptions](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexGrid.4.6.2/C1.WPF.FlexGrid.SaveOptions.html) enums. It also exports .pdf file format using [PdfExportOptions](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.PdfExportOptions.html) class, which provides options for pdf export and **SavePDF** method, which saves the grid to a PDF stream. The following steps illustrate exporting [C1FlexSheet](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.C1FlexSheet.html) to these formats:

**vbnet**

```vbnet
Dim dlg = New Microsoft.Win32.SaveFileDialog()
dlg.DefaultExt = "xlsx"
dlg.Filter = "Excel Workbook (*.xlsx)|*.xlsx|" +
             "Excel 97-2003 Workbook (*.xls)|*.xls|" +
             "HTML File (*.htm;*.html)|*.htm;*.html|" +
             "Comma Separated Values (*.csv)|*.csv|" +
             "Text File (*.txt)|*.txt|" + "PDF (*.pdf)|*.pdf"
If dlg.ShowDialog().Value Then
    Using s = dlg.OpenFile()
        Dim ext = System.IO.Path.GetExtension(dlg.SafeFileName).ToLower()
        Select Case ext
            Case ".htm", ".html"
                flex.Save(s, FileFormat.Html, SaveOptions.Formatted)
                Exit Select
            Case ".csv"
                flex.Save(s, FileFormat.Csv, SaveOptions.Formatted)
                Exit Select
            Case ".txt"
                flex.Save(s, FileFormat.Text, SaveOptions.Formatted)
                Exit Select
            Case ".pdf"
                SavePdf(s, "ComponentOne ExcelBook")
                Exit Select
            Case ".xlsx"
                flex.SaveXlsx(s)
                Exit Select
            Case Else
                flex.SaveXls(s)
                Exit Select
        End Select
    End Using
End If
```

**csharp**

```csharp
var dlg = new Microsoft.Win32.SaveFileDialog();
dlg.DefaultExt = "xlsx";
dlg.Filter =
    "Excel Workbook (*.xlsx)|*.xlsx|" +
    "Excel 97-2003 Workbook (*.xls)|*.xls|" +
    "HTML File (*.htm;*.html)|*.htm;*.html|" +
    "Comma Separated Values (*.csv)|*.csv|" +
    "Text File (*.txt)|*.txt|" +
    "PDF (*.pdf)|*.pdf";
if (dlg.ShowDialog().Value)
{
    using (var s = dlg.OpenFile())
    {
        var ext = System.IO.Path.GetExtension(dlg.SafeFileName).ToLower();
        switch (ext)
        {
            case ".htm":
            case ".html":
                flex.Save(s, FileFormat.Html, SaveOptions.Formatted);
                break;
            case ".csv":
                flex.Save(s, FileFormat.Csv, SaveOptions.Formatted);
                break;
            case ".txt":
                flex.Save(s, FileFormat.Text, SaveOptions.Formatted);
                break;
            case ".pdf":
                SavePdf(s, "ComponentOne ExcelBook");
                break;
            case ".xlsx":
                flex.SaveXlsx(s);
                break;
            default:
                flex.SaveXls(s);
                break;
        }
    }
}
```

The implementation of the **SavePDF** method used in the above code is given in the following code:

**vbnet**

```vbnet
Private Sub SavePdf(s As Stream, documentName As String)
    Dim options As New PdfExportOptions()
    options.Margin = New Thickness(96, 96, 96 / 2, 96 / 2)
    options.ScaleMode = ScaleMode.ActualSize
    flex.SavePdf(s, options)
    s.Close()
```

**csharp**

```csharp
void SavePdf(Stream s, string documentName)
{
    PdfExportOptions options = new PdfExportOptions();
    options.Margin = new Thickness(96, 96, 96 / 2, 96 / 2);
    options.ScaleMode = ScaleMode.ActualSize;
    flex.SavePdf(s, options);
    s.Close();
}
```