title: Get more DataTables from an Excel file
body: <p>I have this situation with an Excel:</p>
  
  <p><a href="https://i.stack.imgur.com/JLhAD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JLhAD.png" alt="enter image description here"></a></p>
  
  <p>... I need to read this file but, how you can see, there are two kind of data:</p>
  
  <ul>
  <li>data (name, surname)... that I can read because I know exactly where they are</li>
  <li>and a table with N rows.</li>
  </ul>
  
  <p>I have some difficulties to read the table.</p>
  
  <p>This is my current implementation:</p>
  
  <pre><code>public void Reader()
  {
      IExcelDataReader excel = ExcelReaderFactory.CreateOpenXmlReader(FileUpload1.PostedFile.InputStream);
  
      // Fill datatable:
      DataSet dt = excel.AsDataSet();
      DataTable dataTable = dt.Tables["sheetName"];
  
      // With the position of the cell:
      string name1 = GetCellValue("C2", dataTable);
      string surname1 = GetCellValue("C3", dataTable);
      myLabel1 = name1 + " " + surname1;
  
      string name2 = GetCellValue("C5", dataTable);
      string surname2 = GetCellValue("C6", dataTable);
      myLabel2 = name2 + " " + surname2;
  
      string name3 = GetCellValue("F2", dataTable);
      string surname3 = GetCellValue("F3", dataTable);
      myLabel3 = name3 + " " + surname3;
  
      string name4 = GetCellValue("F5", dataTable);
      string surname4 = GetCellValue("F6", dataTable);
      myLabel4 = name4 + " " + surname4;
  
      // The table:
      DataTable table = new DataTable();
      table.Columns.Add("ColumnA");
      table.Columns.Add("ColumnB");
      table.Columns.Add("ColumnC");
      table.Columns.Add("Total");
      table.Columns.Add("Result");
  
      DataRow newRow;
      foreach (DataRow row in dataTable.AsEnumerable().Skip(9).Take(100))
      {
          newRow = dtSinistri.NewRow();
          newRow["ColumnA"] = row[1]; // I have discover this index with the debug... :(
          newRow["ColumnB"] = row[3];
          newRow["ColumnC"] = row[5];
          newRow["Total"] = row[7];
          newRow["Result"] = row[8];
          dtSinistri.Rows.Add(newRow);
      }
  
      myGridView.DataSource = table;
      myGridView.DataBind();
  }
  
  /// &lt;summary&gt;Get the value from the cell.
  /// For example: 'C5' return "Guybrush"
  /// &lt;/summary&gt;
  private string GetCellValue(string codeCell, DataTable dt)
  {
      Regex regex = new Regex("([0-9]+)(.*)");
      string HDR = "Yes";
      string[] substrings = regex.Split(codeCell);
      string columnLetter = substrings[0];
      int columnNumber = ColumnLetterToNumber(columnLetter);
      int num = (HDR == "Yes") ? 2 : 1; // if first row is an header then num=2, else num=1
      int rowNumber = Int32.Parse(substrings[1]) - num;
      string s = dt.Rows[rowNumber][columnNumber].ToString();
      return s;
  }
  
  
  /// &lt;summary&gt;transform the letter in a column index&lt;/summary&gt;
  private static int ColumnLetterToNumber(string columnName)
  {
      columnName = columnName.ToUpperInvariant();
  
      int sum = 0;
      for (int i = 0; i &lt; columnName.Length; i++)
      {
          sum *= 26;
          char letter = columnName[i];
          sum += (letter - ('A' - 1));
      }
      sum--;
      return sum;
  }
  </code></pre>
  
  <p>...<strong>This works</strong>.
  But I want a way to take the table from the excel file in automatic way, like with a query or something else. Any advice?</p>