Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write text file from excel using C#

Tags:

c#

excel

c#-4.0

New at C# using visual studio 2010 and trying to get output in a text file from an excel sheet. The excel sheet contains only one column with numeric values like this:

ColumnA
-------
222
333
444
555
666
777
888
999
877
566
767
678
767

I am trying to get the output in the text file like this:

222, 333, 444, 
555, 666, 777, 
888, 999, 877, 
566, 767, 678,
767

Thanks in advance.

like image 784
ncoder Avatar asked Nov 24 '25 02:11

ncoder


1 Answers

This should do it using the 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");

// delete output file if exists already
if (File.Exists("SimpleReport.txt")){
File.Delete("SimpleReport.txt");
}

// save into TXT
document.Workbook.Worksheets[0].SaveAsTXT("SimpleReport.txt");

}
}
}

References:

  • BytesCout SpreadSheet Tutorial
like image 185
David Kroukamp Avatar answered Nov 26 '25 16:11

David Kroukamp