문제

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