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 “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()

Program output is as follows:

Though program is quite simple and straight forward, let’s analyze it.

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

Spreadsheet document = new Spreadsheet())

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

document.LoadFromFile("SimpleReport.xlsx");

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

// Save the document as CSV file

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

4. And finally, we’re closing document, which will essentially cleanup memory.

document.Close();

 

That’s all guys,

Happy Coding!

Tutorials:

prev
next