Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Silverlight | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

Using TxtFormatProvider

TxtFormatProvider makes it easy to import and export TXT files. Note that TXT is a plain text format and holds only the contents of the worksheet without its formatting. Exporting a file to this format strips all styling and saves only cell's result value with their format applied using tab as a delimiter. Moreover, it exports only the contents of the active worksheet – no support for exporting multiple worksheets into a txt at once is available. Importing from TXT respectively creates a new workbook with a single worksheet named Sheet1.

In order to import and export txt files, you need an instance of TxtFormatProvider, which is contained in the Telerik.Windows.Documents.Spreadsheet.FormatProviders.TextBased.Txt namespace. The TxtFormatProvider implements the interface IWorkbookFormatProvider that appears in the Telerik.Windows.Documents.Spreadsheet.FormatProviders namespace.

For more examples and application scenarios of Importing and Exporting a Workbook to various formats using a FormatProvider check out the Import/Load and Export/Save RadSpreadProcessing Workbook knowledge base article.


Example 1 shows how to import a txt file using a FileStream. The sample instantiates a TxtFormatProvider and passes a FileStream to its Import() method:

Example 1: Import TXT file

Workbook workbook; 
IWorkbookFormatProvider formatProvider = new TxtFormatProvider(); 
using (Stream input = new FileStream(fileName, FileMode.Open)) 
    workbook = formatProvider.Import(input); 


Example 2 demonstrates how to export an existing Workbook to a TXT file. The snippet creates a new workbook with a single worksheet. Further, it creates a TxtFormatProvider and invokes its Export() method:

Example 2: Export TXT file

Workbook workbook = new Workbook(); 
string fileName = "SampleFile.txt"; 
IWorkbookFormatProvider formatProvider = new TxtFormatProvider(); 
using (Stream output = new FileStream(fileName, FileMode.Create)) 
    formatProvider.Export(workbook, output); 

See Also

In this article