I'm writing the program that is rewrite CSV files to the excel spreadsheet. I need two dimensional array to write text into excel, so I use File.ReadAllLines and in foreach line.Split method for it and it works perfect. The problem is, when we want to have line feed inside the excel cell - ReadAllLines is treated line feed and carriage return the same way, so we will have new line in excel also with different cell.
The question is, there is any way to override this method that we can treat LF and CR distinguish? For example, when is the LF don't create new line so the new element in list, just append it to previous string with some kind of identifier for excel.
Here is how I read the file:
public virtual List<List<string>> Read(string inFile)
{
var sheetData = new List<List<string>>();
if (!File.Exists(inFile))
{
FileDoesNotExist(inFile);
return sheetData;
}
var lines = File.ReadAllLines(inFile);
foreach (var line in lines)
{
var cells = line.Split(_delimiter).ToList();
sheetData.Add(cells);
}
return sheetData;
}