Free Support Forum - aspose.com

Reg: Header Row Repeat

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

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can use RowFormat.HeadingFormat property to achieve this.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.tables.rowformat.headingformat.html

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 = "

";
//Header Row
sHtml += "";
sHtml += "";
sHtml += "";
sHtml += "";
sHtml += "";

//
for(int i = 0; i < 30 ; i++)
{
sHtml += "

";
sHtml += "";
sHtml += "";
sHtml += "";
sHtml += "";

}

sHtml += "

NameAgeScore
Name " + i.ToString() + "Age" + i.ToString() + "Score " + i.ToString() + "
";

This is my HTML String.

What code should I add in this Header Row.

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can try using code like the following:

string sHtml = "

";

//Header Row

sHtml += "

";

sHtml += "

";

sHtml += "

";

sHtml += "

";

sHtml += "

";

for (int i = 0; i < 60; i++)

{

sHtml += "

";

sHtml += "

";

sHtml += "

";

sHtml += "

";

sHtml += "

";

}

sHtml += "

Name Age Score
Name " + i.ToString() + " Age" + i.ToString() + " Score " + i.ToString() + "
";

// 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.