How to convert Excel document into
text (.txt) file using Bytescout.XLS library
This source code sample shows how to convert
excel XLS document into text file (.txt) using Bytescout.XLS
library with C# in .NET
Download example source code: bytescoutxls_converting_xls_to_txt.zip
(8 KB)
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Bytescout.XLS;
namespace Converting_XLS_to_TXT
{
class Program
{
static void Main(string[] args)
{
// Create new XLSDocument from SimpleReport.xls file
XLSDocument document = new XLSDocument("SimpleReport.xls");
// Create new StringBuilder
StringBuilder builder = new StringBuilder();
// For each row
for (int row = 1; row <= document.WorkBook.Worksheets[0].LastRow;
row++)
{
// And column in first Worksheet
for (int col = 1; col <= document.WorkBook.Worksheets[0].LastColumn;
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_xls_to_txt.zip
(8 KB)