Aisha Srivastava

Aisha Srivastava

  • NA
  • 230
  • 27.5k

C#,win form ,Mshtml Table element

Apr 12 2015 4:22 AM
I have written code for split table  .it split the table from row index where it is . It works fine and it split the table but the space between the table is very minute (less) .i have tried it using  <p> </p> tag but it give error and and  inserting Nbsp too...it worked fine but i don't want to use nbsp because it will get removed when i will run my clean up button in my tool  to remove unnecessary tags....
 
 
plz.. help ...got ..stucked  ...Code for split table is attached.....
 
private void splittable()
{
mshtmlTable table1 = null;
mshtmlTableRow row1 = null;
mshtmlTableCell cell1 = null;
GetTableElement(out table1, out row1, out cell1);
HtmlElement table = getTableHTMLElement();
int rowIndex = row1.rowIndex;
// HtmlElement space = this.editorWebBrowser.Document.CreateElement("p");
HtmlElement splittedTable = this.editorWebBrowser.Document.CreateElement("table");
splittedTable.Style = table.Style;
splittedTable.SetAttribute("border", table.GetAttribute("border"));
splittedTable.SetAttribute("cols", table.GetAttribute("cols"));
splittedTable.SetAttribute("cellPadding", table.GetAttribute("cellPadding"));
splittedTable.SetAttribute("cellSpacing", table.GetAttribute("cellSpacing"));
splittedTable.SetAttribute("width", table.GetAttribute("width"));
splittedTable.SetAttribute("cell.colspan", table.GetAttribute("cell.colspan"));
splittedTable.SetAttribute("cell.rowspan", table.GetAttribute("rowspan"));
//cellSpacing=0 cols=3 cellPadding=0 width="50%" border=1
HtmlElement splittedTableBody = this.editorWebBrowser.Document.CreateElement("tbody");
HtmlElement row = null;
if (table != null)
{
for (int i = 0; i <= rowIndex; i++)
{
row = this.editorWebBrowser.Document.CreateElement("tr");
row.OuterHtml = table.GetElementsByTagName("tr")[i].OuterHtml;
row.Style = table.GetElementsByTagName("tr")[i].Style;
foreach (HtmlElement element in table.GetElementsByTagName("tr")[i].GetElementsByTagName("td"))
{
HtmlElement newElement = this.editorWebBrowser.Document.CreateElement(element.TagName);
newElement.InnerHtml = element.InnerHtml;
newElement.Style = element.Style;
newElement.SetAttribute("colSpan", element.GetAttribute("colSpan"));
row.AppendChild(newElement);
}
splittedTableBody.AppendChild(row);
}
for (int i = 0; i <= rowIndex; i++)
{
table1.deleteRow(0);
}
splittedTable.AppendChild(splittedTableBody);
}
table.OuterHtml = splittedTable.OuterHtml + table.OuterHtml;
}

Answers (2)