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

Free Support Forum - aspose.com

Page Break For Each Row

hi there..

i have a document where i want to view it for one data row for one page..

so i need to make a page break after one data row end

is there have any solution for my problem..

best regard..

zaruell..

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

Thanks for your inquiry. I think the following code example could be useful for you.

//Open document and create DocumentBuilder

Document doc = new Document(@"Test100\in.doc");

DocumentBuilder buildr = new DocumentBuilder(doc);

//Get table from document

Table tab = doc.FirstSection.Body.Tables[0];

//We should split our table and insert breaks between parts of table.

//Start loop

while (tab.Rows.Count > 1)

{

//Cone table and append last row to this table

Table clone = (Table)tab.Clone(false);

clone.AppendChild(tab.LastRow);

//Insert empty paragraph after original table

Paragraph par = new Paragraph(doc);

tab.ParentNode.InsertAfter(par, tab);

//Insert newly created table after paragraph

par.ParentNode.InsertAfter(clone, par);

//Move document builder cursor to the paragraph

buildr.MoveTo(par);

//And insert PageBreak also you can use SectionBreakNewPage

buildr.InsertBreak(BreakType.PageBreak);

}

//Save output document

doc.Save(@"Test100\out.doc");

Best regards.

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

Also there is another approach to achieve this. See the following code:

//Open document and create DocumentBuilder

Document doc = new Document(@"Test100\in.doc");

//Get table from document

Table tab = doc.FirstSection.Body.Tables[0];

//Loop through all rows in the table

foreach (Row row in tab.Rows)

{

//Set PageBreakBefore property

row.FirstCell.FirstParagraph.ParagraphFormat.PageBreakBefore = true;

}

//Save output document

doc.Save(@"Test100\out.doc");

Hope this helps.

Best regards.

hello there...

thanks for ur reply...i think ur solution has answered my question..but still i dont know why is some of the coding didnt doing well..i already convert this coding

Table tab = doc.FirstSection.Body.Tables[0];into vb and became

Dim tab As Aspose.Words.Tables.Table = doc.FirstSection.Body.Tables(0)

but it always get tab.rows = 1..

can u show me how to solve it..

thanks..

best regards...

zaruell

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

Hi

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

Thanks for your inquiry. Could you please attach your document for testing? I will investigate your problem and provide you more information.

Best regards.

here is my source..

i hope u can solve it..

thanks!!...

best regards..

zaruell

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

Thanks for your inquiry. If you open your document you will see that the first table really contains only one row. So you should get second or third table from the document (dependent on your requirements).

Best regards,

hello there..

thanks for your reply..

the document that i gave to you before is only for one row..

but when there is more than one row it will became like the document that i attached...

and this is the coding i put it in my form..

Dim buildr As DocumentBuilder = New DocumentBuilder(doc)

Dim tables As Aspose.Words.Tables.Table = doc.FirstSection.Body.Tables(0)

Dim row As Aspose.Words.Tables.Row

For Each row In tables.Rows

row.FirstCell.FirstParagraph.ParagraphFormat.PageBreakBefore = True

Next

it was spoil when the "Dim tables As Aspose.Words.Tables.Table" will get only one row..

but actually the "doc.FirstSection.Body.Tables(0)" get more than one..

can you help me with this..

best regards...

zaruell...

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

Thank you for more information. But again the first table in your Document contains only one empty row. Please open your document and check this. Your document contains multiple tables.

First is empty at the beginning of document.

Also there is multiple tables that starts with “Information” text and the last table starts with “Leave Balance Information”.

This code gets the first empty table from your document.

Dim tables As Aspose.Words.Tables.Table = doc.FirstSection.Body.Tables(0)

So I guess you need get second table or third etc.

Dim tables As Aspose.Words.Tables.Table = doc.FirstSection.Body.Tables(1)

Also I think that you need to start each “Information” table from new page. If so you should use the following code.

'Open docuent

Dim doc As Document = New Document("c:\Temp\LeaveForm.doc")

'Get collection of Tables

Dim tables As NodeCollection = doc.GetChildNodes(NodeType.Table, True)

'Loop trough all tables in the document

For Each tab As Table In tables

tab.FirstRow.FirstCell.FirstParagraph.ParagraphFormat.PageBreakBefore = True

Next

'Save Document

doc.Save("C:\Temp\out.doc")

I hope this could help you.

Best regards.