Trying to convert xlsx
file to csv
via C# code. I am able to convert file successfully but it could not handle newline and line break properly.
Please advice which separator to use so that my csv
is generated correctly
csv
conversion code could not convert correctly. It should complete the conversion of a column completely but didn't.
using the below code to convert xlsx
file to csv
string file= @"fakepath\abc.xlsx";
DataSet result = new DataSet();
//------To read the xlsx file
if (file.EndsWith(".xlsx"))
{
// Reading from a binary Excel file (format; *.xlsx)
FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
result = excelReader.AsDataSet();
excelReader.Close();
}
//-------To convert the file into csv format
while (row_no < result.Tables[0].Rows.Count)
{
for (int i = 0; i < result.Tables[0].Columns.Count; i++)
{
a += result.Tables[0].Rows[row_no][i].ToString() + ",";
}
row_no++;
a += "\r\n";
}
string output = @"fakepath\abc.csv";
StreamWriter csv = new StreamWriter(@output, false);
csv.Write(a);
csv.Close();
column in excel holds data as
First Line
Second Line
Third Line
excel point i.e. 1,2 and 3 are in same column but different lines
Expected output csv formmat 1. First Line 2. Second Line 3. Third Line
Please help