XLSX to CSV Conversion Tutorial - C# and VB.NET - ByteScout

XLSX to CSV Conversion Tutorial – C# and VB.NET

  • Home
  • /
  • Articles
  • /
  • XLSX to CSV Conversion Tutorial – C# and VB.NET

XLSX to CSV conversion tutorial shows how to convert XLSX Excel files to CSV in C# or Visual Basic .NET using Bytescout Spreadsheed SDK. Use CSharp or VB.NET source code below to convert XLSX to CSV files.

Program samples demonstrated in this article uses features from the “Bytescout.Spreadsheet” assembly. If you want to code along, then you can get your free SDK trial from this link.

C#

Spreadsheet document = new Spreadsheet())

document.LoadFromFile("SimpleReport.xlsx");
string csvFile = Path.GetTempPath() + "SimpleReport.csv";

// Save the document as CSV file
document.Workbook.Worksheets[0].SaveAsCSV(csvFile);
document.Close();

Following is the VB.NET program for the same.

VB.NET

   ' Load XLS document
 	Dim document As New Spreadsheet()
   document.LoadFromFile("SimpleReport.xlsx")
   Dim csvFile As String = Path.GetTempPath() & "SimpleReport.csv"

   ' Save the document as CSV file
   document.Workbook.Worksheets(0).SaveAsCSV(csvFile)
   document.Close()

The program output is as follows:

Though the program is quite simple and straightforward, let’s analyze it.

1. Creating an instance of Spreadsheet class which is under the “Bytescout.Spreadsheet” assembly.

Spreadsheet document = new Spreadsheet())

2. Next we are loading the input file to be processed by utilizing the “LoadFromFile” method. Spreadsheet class also provides various versions of the same method as loading password-protected input file. Also, if we have an input file in-stream format, we can utilize the “LoadFromStream” method.

document.LoadFromFile("SimpleReport.xlsx");

3. Next step is generating output and saving it at the desired location. Here we are considering the first worksheet to parse as a CSV file.

// Save the document as CSV file

document.Workbook.Worksheets[0].SaveAsCSV(csvFile);

4. And finally, we’re closing the document, which will essentially clean up memory.

document.Close();

 

That’s all guys,

Happy Coding!

Tutorials:

prev
next