Thursday, 21 November 2013 09:10

How to Convert Excel to Text in C#, VB.NET

Written by  Administrator
Rate this item
(0 votes)

This article aims at introducing an easy solution to convert Excel (xls/xlsx) to Text in C# and VB.NET by a powerful and independent Excel .NET component, called Spire.Xls. Meanwhile, this Excel API supports for converting Excel (xls/xlsx) to PDF, HTML, Image, CSV, XML, etc, without Microsoft Excel installed on the machine. Download it from here to have a try.

Step 1: Create an instance of Spire.Xls.Document.

Workbook workbook = new Workbook();

Step 2: Load the file base on a specified file name.


Step 3: Get the first worksheet of the Worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 4: Save the document object to a Txt file.

sheet.SaveToFile("ExceltoTxt.txt", " ", Encoding.UTF8);

Effect Screenshot:



Sample code:

using Spire.Xls;
namespace Excel_to_Txt
    class Program
        static void Main(string[] args)
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToFile("ExceltoTxt.txt", ",", Encoding.UTF8);
Imports Spire.Xls
Namespace Excel_to_Txt
       Friend Class Program
              Shared Sub Main(ByVal args() As String)
                     Dim workbook As New Workbook()
                     workbook.LoadFromFile("..\ExceltoTxt.xls ")
                     Dim sheet As Worksheet = workbook.Worksheets(0)
                     sheet.SaveToFile("ExceltoTxt.txt", ",", Encoding.UTF8)
              End Sub
       End Class
End Namespace

Additional Info

  • tutorial_title: Convert Excel to Text
Last modified on Tuesday, 29 July 2014 01:58