I am using Epplus to write out a collection into an excel file. Currently I am incrementing rows by manually manipulating the cell number.(ws is an instance of ExcelWorkSheet)

  int i = 1;
  foreach (var item in items)
   {
      ws.Cells["A"+i.ToString()].Value =item.Text; 
      i++;
    }

Instead of adding number to cell name is there a better way to handle this? Something like

 int i = 1;
      foreach (var item in items)
       {
          ws.Row[i].Cells[0]=item.Text; 
          i++;
        }
有帮助吗?

解决方案

There's an [int Row, int Col] indexer on Cells (type ExcelRange), so you can use ws.Cells[i, 0].

  int i = 1;
  foreach (var item in items)
   {
      ws.Cells[i, 0].Value =item.Text; 
      i++;
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top