We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Repeat Header and sub header - LINQ

Hello,
I’m using the LINQ engine. Is it possible to understand when a table goes to a new page, in order to replicate some sub-rows in addition to the title? Are there any other solutions?

I am attaching an example file

Thanks

Example.docx (16.4 KB)

@Blegork,
Could you please ZIP and attach your input template document? We will then provide you code example and/or updated template document needed to get desired result according to your requirement.

@sergey.lobanov

Hi,
thank you for replying. I am attaching the Java code, and the output document that I would like to have. When I go to a new page, in addition to repeating the header of the table, I would like to repeat the row with the subheader, in the output file it is row number 13, the one in red.

ASPOSE.zip (4.7 MB)

Marco

@Blegork,
To get the desired result, you need to update output document after bulding a report, using Aspose.Words API. Please check the following code:

Document doc = new Document("C:\\Temp\\Report_out.docx");

Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
Row boldRow = new Row(doc);
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
double maxPos = 0;
double thisRowPos;
for (Row r : table.getRows())
{
	//getting vertical position of row
	enumerator.setCurrent(collector.getEntity((Node)r));
	thisRowPos = enumerator.getRectangle().getY();

	if (thisRowPos > maxPos || Math.abs(maxPos - thisRowPos) < 1)
		maxPos = thisRowPos;

	Cell cellOfRow = (Cell)r.getChild(NodeType.CELL, 0, true);
	Run runOfCell = (Run)cellOfRow.getChild(NodeType.RUN, 0, true);

	//remember needed subtitle row
	if ((runOfCell != null) && runOfCell.getFont().getBold() && runOfCell.getText().startsWith("Deposito"))
		boldRow = (Row)r.deepClone(true);

	//if this row's position is less then max pos of page, that means that row is on a new page
	if (thisRowPos < maxPos)
	{
		table.insertBefore(boldRow, r);
		boldRow = (Row)boldRow.deepClone(true);
		maxPos = 0;
		doc.updatePageLayout();
	}
}

doc.save("C:\\Temp\\Report_out_final.docx");