# Importing FlexSheet

## Content



[C1FlexSheet](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.C1FlexSheet.html) allows import of Excel files (.xls, .xlsx) and text file (.txt). This functionality is attained by using [ImportFileFormat](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.ImportFileFormat.html) enum. The following code sample illustrates importing Excel files in [C1FlexSheet](/componentone/api/wpf/online-flexsheet/dotnet-framework-api/C1.WPF.FlexSheet.4.6.2/C1.WPF.FlexGrid.C1FlexSheet.html):

**vbnet**

```vbnet
Dim dlg = New Microsoft.Win32.OpenFileDialog()
dlg.Filter = "Excel 97-2003 Workbook (*.xls)|*.xls|" +
             "Excel Workbook (*.xlsx)|*.xlsx" +
             "Text File (*.txt)|*.txt|"
If dlg.ShowDialog().Value Then
    Try
        Using s = dlg.OpenFile()
            Dim ext = System.IO.Path.GetExtension(dlg.SafeFileName).ToLower()
            Select Case ext
                Case ".txt"
                    flex.Load(s, ImportFileFormat.TXT)
                    Exit Select
                Case ".xlsx"
                    flex.Load(s, ImportFileFormat.XLSX)
                    ' ImportFileFormat uses namespace FlexGrid
                    Exit Select
                Case ".xls"
                    flex.Load(s, ImportFileFormat.XLS)
                    Exit Select
            End Select
        End Using
    Catch x As Exception
        Dim msg = "Error opening file: " & vbCr & vbLf & vbCr & vbLf + x.Message
        MessageBox.Show(msg, "Error", MessageBoxButton.OK)
    End Try
End If
```

**csharp**

```csharp
var dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Filter = "Excel 97-2003 Workbook (*.xls)|*.xls|"
    + "Excel Workbook (*.xlsx)|*.xlsx" +
    "Text File (*.txt)|*.txt|";
if (dlg.ShowDialog().Value)
{
    try
    {
        using (var s = dlg.OpenFile())
        {
            var ext = System.IO.Path.GetExtension(dlg.SafeFileName).ToLower();
            switch (ext)
            {
                case ".txt":
                    flex.Load(s, ImportFileFormat.TXT);
                    break;
                case ".xlsx":
                    // ImportFileFormat uses namespace FlexGrid
                    flex.Load(s, ImportFileFormat.XLSX);
                    break;
                case ".xls":
                    flex.Load(s, ImportFileFormat.XLS);
                    break;
            }
        }
    }
    catch (Exception x)
    {
        var msg = "Error opening file: \r\n\r\n" + x.Message;
        MessageBox.Show(msg, "Error", MessageBoxButton.OK);
    }
}
```