title: Parse HTML table to a CSV file (colspan and rowspan)
body: <p>I want to parse a HTML table into a CSV file, but keeping the right number of colspan and rowpspan.</p>
  
  <p>I'm using <strong>";" as delimiter cell</strong>. Thus, when there colspan of 2 columns, for example, instead of having only one, ";", it will have 2.</p>
  
  <p>I can extract the content of the table and make line breaks where <em>tr</em> indicators ends, but don't know how to treat <strong>colspan</strong> and <strong>rowspan</strong>.</p>
  
  <pre><code>HtmlNodeCollection rows = tables[0].SelectNodes("tr");
  
  // Aux vars
  int i;
  // ncolspan
  
  // For each row...
  for (i = 0; i &lt; rows.Count; ++i)
  {
      // For each cell in the col...
      foreach (HtmlNode cell in rows[i].SelectNodes("th|td"))
      {
          /* Unsuccessful attempt to treat colspan
          foreach (HtmlNode n_cell in rows[i].SelectNodes("//td[@colspan]"))
          {
              ncolspan = n_cell.Attributes["colspan"].Value;
          }
          */
  
          text.Write(System.Text.RegularExpressions.Regex.Replace(cell.InnerText, @"\s\s+", ""));
          text.Write(";");
          /*
          for (int x = 0; x &lt;= int.Parse(ncolspan); x++)
          {
              text.Write(";");
          }
          */
      }
      text.WriteLine();
      ncolspan = "0";
  }
  </code></pre>
  
  <p>Any help, please? Thank you!</p>
  
  <p><strong>UPDATE:</strong> Here a simple example table to use:</p>
  
  <pre><code>&lt;table id="T123" border="1"&gt;
      &lt;tr&gt;
          &lt;td colspan="3"&gt;&lt;center&gt;&lt;font color="red"&gt;Title&lt;/font&gt;&lt;/center&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th&gt;R1 C1&lt;/th&gt;
          &lt;th&gt;R1 C2&lt;/th&gt;
          &lt;th&gt;R1 C3&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;R2 C1&lt;/td&gt;
          &lt;td&gt;R2 C2&lt;/td&gt;
          &lt;td&gt;R2 C3&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td colspan="2"&gt;R3 C1 e C2 with "&lt;/td&gt;
          &lt;td&gt;R3 C3&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;R4 C1&lt;/td&gt;
          &lt;td colspan=2&gt;R4 C2 e C3 without "&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;R5 C1&lt;/td&gt;
          &lt;td&gt;R5 C2&lt;/td&gt;
          &lt;td&gt;R5 C3&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td rowspan ="2"&gt;R6/R7 C1: Two lines rowspan. Must leave the second line blank.&lt;/td&gt;
          &lt;td&gt;R6 C2&lt;/td&gt;
          &lt;td&gt;R6 C3&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;R7 C2&lt;/td&gt;
          &lt;td&gt;R7 C3&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;End&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>