Hello,
I have a HTML string. I want to convert HTML string to MSWORD.
The header column should be repeat when page breaks.
Give me a solution.
Thanks
This message was posted using Page2Forum from Aspose.Words for .NET and Java - Documentation
Hello,
I have a HTML string. I want to convert HTML string to MSWORD.
The header column should be repeat when page breaks.
Give me a solution.
Thanks
This message was posted using Page2Forum from Aspose.Words for .NET and Java - Documentation
Hi
Thanks for your request. You can use RowFormat.HeadingFormat property to achieve this.
https://reference.aspose.com/words/net/aspose.words.tables/rowformat/headingformat/
You should just need to find row, which should be repeated and specify this option.
Please let me know if you need more information, I will be glad to help you.
Best regards.
Hello,
string sHtml = "<table>";
//Header Row
sHtml += "<tr>";
sHtml += "<td>Name</td>";
sHtml += "<td>Age</td>";
sHtml += "<td>Score</td>";
sHtml += "</tr>";
//
for(int i = 0; i < 30 ; i++)
{
sHtml += "<tr>";
sHtml += "<td>Name " + i.ToString() + "</td>";
sHtml += "<td>Age" + i.ToString() + "</td>";
sHtml += "<td>Score " + i.ToString() + "</td>";
sHtml += "</tr>";
}
sHtml += "</table>";
This is my HTML String.
What code should I add in this Header Row.
Thanks
Hi
Thanks for your request. You can try using code like the following:
string sHtml = "<table>";
//Header Row
sHtml += "<tr>";
sHtml += "<td>Name</td>";
sHtml += "<td>Age</td>";
sHtml += "<td>Score</td>";
sHtml += "</tr>";
for (int i = 0; i < 60; i++)
{
sHtml += "<tr>";
sHtml += "<td>Name " + i.ToString() + "</td>";
sHtml += "<td>Age" + i.ToString() + "</td>";
sHtml += "<td>Score " + i.ToString() + "</td>";
sHtml += "</tr>";
}
sHtml += "</table>";
// Create document and DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert HTML string.
builder.InsertHtml(sHtml);
// Search for previously insertted table.
Node currentNode = builder.CurrentParagraph;
while (currentNode != null && currentNode.NodeType != NodeType.Table)
currentNode = currentNode.PreviousPreOrder(doc);
if (currentNode != null)
{
Table table = (Table) currentNode;
table.FirstRow.RowFormat.HeadingFormat = true;
}
// Save output document.
doc.Save(@"Test001\out.doc");
But I think, it is better to build such table programmatically. Please see the following code for example:
// Create document and DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create heading row that will be repeated on each page
builder.RowFormat.HeadingFormat = true;
builder.Bold = true;
for (int i = 0; i <5; i++)
{
builder.InsertCell();
builder.Write(string.Format("heading_{0}", i));
}
builder.EndRow();
builder.RowFormat.HeadingFormat = false;
builder.Bold = false;
// Generate body of table
for (int rowIdx = 0; rowIdx <100; rowIdx++)
{
for (int colIdx = 0; colIdx <5; colIdx++)
{
builder.InsertCell();
builder.Write(string.Format("value_of_{0}_{1}", rowIdx, colIdx));
}
builder.EndRow();
}
builder.EndTable();
// Save output document
doc.Save("out.doc");
I hope this could help you.
Best regards.