title: Programmatically building Excel worksheet.range in C#
body: <p>Hope you can help.</p>
  
  <p>I'm looking for a way to build an excel sheet range by just passing in some parameters. My method is as follows:</p>
  
  <pre><code>private void TableCellformatting(int rowStart, int rowEnd, char colStart, char colEnd)
      {
          char temp;
          StringBuilder s = new StringBuilder();
          excelSheetRange = null;
          for (int i = rowStart; i &lt;= rowEnd; i++)
          {
              temp = colStart;
              while (temp &lt;= colEnd)
              {
                  if (s.Length &gt; 0)
                      s.Append(", ");
                  s.Append(string.Format("{0}{1}", temp.ToString(), i));
                  temp++;
              }
          }
          excelSheetRange = excelSheet.get_Range(s.ToString());
          excelSheetRange.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
      }
  </code></pre>
  
  <p>This runs ok until the excelSheet.get_Range part is called. When I pass in the cell numbers manually, I have to do it like this:</p>
  
  <pre><code>get_Range("A1", "A2" etc...)
  </code></pre>
  
  <p>Any ideas if this is even possible, or if there is another way?</p>
  
  <p>Thanks!</p>