# TX Text Control .NET for Windows Forms: Converting a Table to Text

> TX Text Control .NET for Windows Forms exposes Table and TableCell classes that simplify converting tables to plain text. A C# method iterates every cell, accumulates row strings with a configurable separator such as tab, removes the table, then inserts the resulting lines as text.

- **Author:** Bjoern Meyer
- **Published:** 2009-07-10
- **Modified:** 2026-07-17
- **Description:** TX Text Control .NET for Windows Forms exposes Table and TableCell classes that simplify converting tables to plain text. A C# method iterates every cell, accumulates row strings with a configurable separator such as tab, removes the table, then inserts the resulting lines as text.
- **2 min read** (331 words)
- **Tags:**
  - Sample
  - Tables
- **Web URL:** https://www.textcontrol.com/blog/2009/07/10/tx-text-control-net-for-windows-forms-converting-a-table-to-text/
- **LLMs URL:** https://www.textcontrol.com/blog/2009/07/10/tx-text-control-net-for-windows-forms-converting-a-table-to-text/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2009/07/10/tx-text-control-net-for-windows-forms-converting-a-table-to-text/llms-full.txt

---

I just found an interesting solution from our support staff while reviewing our support cases of the last week. A user was trying to convert a table into normal text.

Thanks to TX Text Control's easy-to-use [Table](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.table.class.htm) and [TableCell](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.tablecell.class.htm) classes, this task is quite easy to solve. The following method converts every 1-dimensional (not nested) table to normal text. The table and the separator must be passed in the parameters of the method.

```
private void ConvertTableToText(Table Table, string Separator)
{
    if (Table == null)
        return;

    string sRowText = String.Empty;
    string[] sTableText = new string[Table.Rows.Count];
    int iCurRow = 1;

    // loop through all cells to get the text for each line
    foreach (TableCell tcCell in textControl1.Tables.GetItem(13).Cells)
    {
        if (tcCell.Row != iCurRow)
        {
            sTableText.SetValue(sRowText, iCurRow - 1);
            sRowText = "";
        }

        // add the cell\'s text including a separator to the line\'s text
        sRowText += tcCell.Text + Separator;
        iCurRow = tcCell.Row;
    }

    // last row
    sTableText.SetValue(sRowText, iCurRow - 1);

    // remove the table
    textControl1.Tables.Remove();

    // insert each line of text
    foreach (string sLine in sTableText)
    {
        textControl1.Selection.Text = sLine + "
";
    }
}
```

This method can be called as shown below to convert the table at the current input position. The separator between the cell's text is a tab character in this case to simulate a table layout:

```
ConvertTableToText(textControl1.Tables.GetItem(), "	");{/literal}
```

Technically, a loop through all table cells is used to create the strings for each line of the table. At the end, the table is removed and replaced with the text of each table cell.

This particular user wanted to save the content as plain text, so that the formatting of the text could be ignored. To save the formatting, an array of formatted text snippets should be created by selecting the table cell's text and using the Save method to save in an appropriate format.

Feel free to leave your comments or questions on this.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Revised Sample: Converting Text to a Table](https://www.textcontrol.com/blog/2009/01/07/revised-sample-converting-text-to-a-table/llms.txt)
- [Apply a Boxed Frame Style to Selected Cells](https://www.textcontrol.com/blog/2007/06/12/apply-a-boxed-frame-style-to-selected-cells/llms.txt)
- [Change Table Width to Fit Document Width - Automatically](https://www.textcontrol.com/blog/2005/02/03/change-table-width-to-fit-document-width-automatically/llms.txt)
- [Export Document Tables to CSV in .NET C#](https://www.textcontrol.com/blog/2026/06/19/export-document-tables-to-csv-in-dotnet-csharp/llms.txt)
- [Convert CSV to PDF in .NET C#](https://www.textcontrol.com/blog/2026/01/19/convert-csv-to-pdf-in-dotnet-csharp/llms.txt)
- [Why Table Control in Templates is Important for Professional PDF Creation in C#](https://www.textcontrol.com/blog/2025/04/04/why-table-control-in-templates-is-important-for-professional-pdf-creation/llms.txt)
- [Splitting Tables at Bookmark Positions and Cloning Table Headers](https://www.textcontrol.com/blog/2025/02/13/splitting-tables-at-bookmark-positions-and-cloning-table-headers/llms.txt)
- [Loading and Processing Excel XLSX Spreadsheet Tables into TX Text Control using .NET C#](https://www.textcontrol.com/blog/2024/10/16/loading-and-processing-excel-spreadsheet-tables-into-tx-text-control-using-net-csharp/llms.txt)
- [Creating Advanced Tables in PDF and DOCX Documents with C#](https://www.textcontrol.com/blog/2024/09/30/creating-advanced-tables-in-pdf-and-docx-documents-with-csharp/llms.txt)
- [Text to Table and Table to Text in TX Text Control and C#](https://www.textcontrol.com/blog/2024/06/26/text-to-table-and-table-to-text-in-tx-text-control-and-csharp/llms.txt)
- [A Step-by-Step Guide to Formatting Table Cells in TX Text Control Programmatically Using C#](https://www.textcontrol.com/blog/2024/06/19/a-step-by-step-guide-to-formatting-table-cells-in-tx-text-control-programmatically-using-c-sharp/llms.txt)
- [Document Editor: Useful JavaScript Functions for Tables](https://www.textcontrol.com/blog/2024/06/19/document-editor-useful-javascript-functions-for-tables/llms.txt)
- [Document Editor: Formatting Table Cells Using JavaScript](https://www.textcontrol.com/blog/2024/06/18/document-editor-formatting-table-cells-using-javascript/llms.txt)
- [Inserting MergeBlocks with the DataSourceManager and Applying Table Styles in C#](https://www.textcontrol.com/blog/2024/04/09/inserting-mergeblocks-with-the-datasourcemanager-and-applying-table-styles-in-csharp/llms.txt)
- [How to Detect and Extract Table Data as JSON from PDF Documents in C#](https://www.textcontrol.com/blog/2023/08/15/how-to-detect-and-extract-table-data-as-json-from-pdf-documents-in-csharp/llms.txt)
- [Useful Tricks for Working with Tables](https://www.textcontrol.com/blog/2023/08/04/useful-tricks-for-working-with-tables/llms.txt)
- [Generating Hierarchical Tables from JSON Data in .NET C#](https://www.textcontrol.com/blog/2023/08/03/generating-hierarchical-tables-from-json-data-in-csharp/llms.txt)
- [Table Extension: Remove Empty Columns After Mail Merge](https://www.textcontrol.com/blog/2023/06/08/table-extension-remove-empty-columns-after-mail-merge/llms.txt)
- [Extension Method: Converting Tables to Tabs in C#](https://www.textcontrol.com/blog/2023/03/16/extension-method-converting-tables-to-tabs-in-csharp/llms.txt)
- [Using Accounting Double Underlining in MailMerge Templates](https://www.textcontrol.com/blog/2023/03/02/use-accounting-double-underlining-in-mailmerge-templates/llms.txt)
- [Importing Excel XLSX Spreadsheets into TX Text Control in ASP.NET Core and Windows Forms in C#](https://www.textcontrol.com/blog/2023/02/07/importing-excel-xlsx-spreadsheets-into-tx-text-control/llms.txt)
- [Create a Table of Contents in Windows Forms using C#](https://www.textcontrol.com/blog/2023/01/23/create-toc-in-windows-forms/llms.txt)
- [Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub](https://www.textcontrol.com/blog/2023/01/08/official-tx-text-control-net-sample-applications-are-now-hosted-on-github/llms.txt)
- [Formatting Numbers in Table Cells](https://www.textcontrol.com/blog/2022/06/21/formatting-numbers-in-table-cells/llms.txt)
- [Detect Toggle Button Changes Using a MutationObserver](https://www.textcontrol.com/blog/2021/11/11/detect-toggle-button-changes-using-a-mutationobserver/llms.txt)
