How to Convert Excel to TXT with C#

Text is one frequently used file format, which is formed with texts in lots of columns. It is attached in Windows operation system. Therefore, it is easy to create and open a TXT file.

Because its simple structure, TXT file is widely used to save text information. It is easy to recover if there are some errors in file. Also, txt file has small size and easy to save. However, there are not so much format tools provided, just including font type, color and size setting.

Sometimes, we need to use txt file to save data to avoid some problems which exists because of format. We can export data to txt file directly or convert other format files which save data to txt. In this post, I will show way to convert Excel to txt with C#.

In my example, I want to convert one Excel file about sales report to txt file. And I use Spire.XLS in this method. So, I add its DLL file as reference.

Sales Report


  1. Load the file which I want to convert to txt from my computer and initialize the current worksheet.
  2. Save this file to txt and launch this file.


using System;
using Spire.Xls;

namespace ExceltoTXT
    class toTXT
        static void Main(string[] args)


            //Load File and Initialize Worksheet
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@”D:\work\My Documents\Sales Report.xlxs”,ExcelVersion.Version2010);
            Worksheet sheet = workbook.Worksheets[0];

            //Save to TXT
            sheet.SaveToFile(“toTXT.txt”, “,”);

            //Launch TXT File



Click Here to LEARN MORE about Spire.XLS

Click Here to DOWNLOAD Spire.XLS


One thought on “How to Convert Excel to TXT with C#

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s