title: How to find first and last cell in ExcelInterop and graph range in C#
body: <p>Trying to graph a simple csv file in Excel :</p>
  
  <pre><code>1,2,3
  4,5,6
  7,8,9
  </code></pre>
  
  <p>How do I programmatically determine the graphing range to be A1:C3?</p>
  
  <p>I have tried</p>
  
  <pre><code>            var lastCell = worksheet.Cells.get_End(XlDirection.xlUp);
  </code></pre>
  
  <p>to determine the final column but it doesn't seem to work.</p>
  
  <p>The following is the code that I am using to graph the file, and I just need to determine the range.</p>
  
  <pre><code>using Microsoft.Office.InteropServices.Excel;
  
  
  
          Application application = new Application();
          Workbook workbook = application.Workbooks.Open(fileName);
          var worksheet = workbook.Worksheets[1] as
              Microsoft.Office.Interop.Excel.Worksheet;
  
  
                     // Add chart.
          var charts = worksheet.ChartObjects() as
              Microsoft.Office.Interop.Excel.ChartObjects;
          var chartObject = charts.Add(60, 10, 300, 300) as
              Microsoft.Office.Interop.Excel.ChartObject;
          var chart = chartObject.Chart;
  
          // Set chart range.
          var range = worksheet.get_Range( ); //  ????????
          chart.SetSourceData(range);
  
          // Set chart properties.
          chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine;
          chart.ChartWizard(Source: range,
              Title: graphTitle,
              CategoryTitle: xAxis,
              ValueTitle: yAxis);
  
  
          // Save.
          workbook.Save();
          workbook.Close();
  </code></pre>