How to convert Excel (XLS) document into CSV file using Bytescout Spreadsheet SDK - ByteScout

How to convert Excel (XLS) document into CSV file using Bytescout Spreadsheet SDK

  • Home
  • /
  • Articles
  • /
  • How to convert Excel (XLS) document into CSV file using Bytescout Spreadsheet SDK

How to convert Excel document into CSV (comma separated data) file using Bytescout Spreadsheet SDK

This source code sample shows how to convert excel XLS document into comma-separated data file (.CSV) using Bytescout Spreadsheet SDK with C# in .NET

Download example source code: bytescoutxls_converting_excel_to_csv.zip (8 KB)

Source Excel document

CSV generated from Excel document using Bytescout Spreadsheet SDK

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Bytescout.Spreadsheet;

namespace Converting_XLS_to_TXT
{
class Program
{
static void Main(string[] args)
{
// Create new Spreadsheet from SimpleReport.xls file
Spreadsheet document = new Spreadsheet(“SimpleReport.xls”);
// Create new StringBuilder
StringBuilder builder = new StringBuilder();
// For each row
for (int row = 1; row <= document.Workbook.Worksheets[0].UsedRangeRowMax; row++)
{
// And column in first Worksheet
for (int col = 1; col <= document.Workbook.Worksheets[0].UsedRangeColumnMax; col++)
{
// Append cell value to StringBuilder
builder.AppendFormat(“{0}t”, document.Workbook.Worksheets[0].Cell(row, col).Value);
}
// Append new line
builder.AppendLine();
}
// Save StringBuilder to file
File.WriteAllText(“SimpleReport.txt”, builder.ToString());
}
}
}

Download example source code: bytescoutxls_converting_excel_to_csv.zip (8 KB)

Tutorials:

prev
next