Edit this page
Available for: UI for ASP.NET AJAX | UI for ASP.NET MVC | UI for WPF | UI for WinForms | UI for Silverlight

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.


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:

[C#] 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:

[C#] 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);
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article