I need to read a text file with the following structure:
"2^7^N^2160.000000
2^8^C^US "
where the first value is the line, the second the column, the third data type and the quarter
the value to generate a excel file usign the gembox.preadsheet library
How to read a text file and write a excel file using a gembox.preadsheet library
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Garry Gibson20 pointsPosted Apr 30, 2014, 1:12 AM EDT
Did you mean something like this:
var excel = new ExcelFile(); var sheet = excel.Worksheets.Add("Sheet 1"); foreach (var line in File.ReadLines("Data.txt")) { string[] lineValues = line.Split('^'); int rowIndex = Convert.ToInt32(lineValues[0]); int columnIndex = Convert.ToInt32(lineValues[1]); if (lineValues[2] == "N") sheet.Cells[rowIndex, columnIndex].Value = Convert.ToDouble(lineValues[3]); else sheet.Cells[rowIndex, columnIndex].Value = lineValues[3]; } excel.Save("Sample.xlsx");