Easiest Solution to Convert Excel to CSV in C#, VB.NET

This section just aims at introducing an easiest solution to convert Excel (XLS/XLSX) to CSV with C#, VB.NET via an Excel component. Two reasons can be attributed to call this solution the easiest: One is that the key code of Excel to CSV is only three lines; the other reason is that you can directly convert Excel to CSV without opening the original Excel file.

Spire.XLS for .NET, as a .NET Excel component, enables users to fast create, read, write and modify Excel document without Microsoft Office Excel Automation. Besides, it has powerful conversion functions, such as it can easily convert excel to PDF, Excel to HTML, Excel to XML, XML to Excel, Excel to Image and Excel to CSV.

By calling a class Spire.XLS.Worksheet in Spire.XLS.dll component, you can convert Excel to CSV by calling a method: public void SaveToFile(string fileName, string separator, Encoding encoding) with three parameters passed. Please preview the effective screenshot of this task first:

Excel to CSV

Now before view the whole code of Excel to CSV conversion, please Download Spire.XLS for .NET.

Sample Code:

[C#]
using Spire.Xls;
namespace xls2csv
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\ExceltoCSV.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToFile("sample.csv", ",", Encoding.UTF8);
        }
    }
}
[VB.NET]
Imports Spire.Xls
Namespace xls2csv
       Friend Class Program
              Shared Sub Main(ByVal args() As String)
                     Dim workbook As New Workbook()
                     workbook.LoadFromFile("..\ExceltoCSV.xls ")
                     Dim sheet As Worksheet = workbook.Worksheets(0)
                     sheet.SaveToFile("sample.csv", ",", Encoding.UTF8)
              End Sub
       End Class
End Namespace