There are several options, it depends on what additional operations you want to do ...
int row = 2;
using (StreamReader sr = new StreamReader("data.txt"))
{
while (sr.Peek() >= 0)
{
string c1 = sr.ReadLine();
string c2 = sr.ReadLine();
oSheet.Cells[row, 1] = c1;
oSheet.Cells[row, 2] = c2;
row++;
}
}
You can also read the data in a two-dimensional array and insert the range right away:
string[,] cells = new string[numberOfRows, 2];
cells[0, 0] = "Row0 Column0";
cells[0, 1] = "Row0 Column1";
cells[1, 0] = "Row1 Column0";
cells[1, 1] = "Row1 Column1";
oSheet.get_Range("A1", "B8").Value2 = cells;
source
share