This is a simple class that takes an
HTMLTable
in the constructor and returns an array of
string
s in CSV format.
namespace WebLib
{
using System.Collections.Generic;
using System.Text;
using System.Web.UI.HtmlControls;
public class HTMLTableHelper
{
#region Fields
private readonly HtmlTable htmlTable;
#endregion
#region Constructors
public HTMLTableHelper(HtmlTable htmlTable)
{
this.htmlTable = htmlTable;
}
#endregion
#region Methods
public string[] ConvertToCSV()
{
List<string> rows = new List<string>();
foreach (HtmlTableRow row in htmlTable.Rows)
{
StringBuilder rowCVS = new StringBuilder();
foreach (HtmlTableCell cell in row.Cells)
{
rowCVS.Append(cell.TagName.Trim());
rowCVS.Append(",");
}
rowCVS.Remove(rowCVS.Length - 1, 1);
rows.Add(rowCVS.ToString());
}
return rows.ToArray();
}
#endregion
}
}
In the hope that it might prove useful,
Jethro Badenhorst
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.