Skip to content

How to read a text file and write a excel file using a gembox.preadsheet library

brenda meza

Asked May 5, 2008, 9:34 AM EDT1 answer
Share
LinkedInX
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

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi,

    Did you mean something like this:
    C#
    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");
    Also check these demonstration samples for reading and writing excel files in C#.
    0