Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Jan 10, 2017 2:40 pm

Hi.

We have a template that renders a series of records in word tables.
There can be many records and each individual record is represented as a word table.

Our customer ideally wanted to keep each record on its own page, so did not want a records table starting at the top of a page and finishing halfway down the next page. In this scenario the record should start at the top of the next page.
We were able to implement this using code similar to that shown below.
Code: Select all
foreach (TableRow row in table.Rows)
 {
     foreach (TableCell cell in row.Cells)
     {
       foreach (Paragraph p in cell.Paragraphs)
        {
            p.Format.KeepFollow = true;
        }
     }
}


However, we have recently encountered an instance where the table is actually too large to fit on one page.
When we do NOT execute the code above the doc saves fine but it just "hangs" unresponsively for ages if we have set KeepFollow to true.
The data in the table is obviously dynamic (so for one doc a text field will contain only a small amount of data but another could contain larger amounts of text).
is there some way to stop this error from occurring (i.e. keep it on one page if it will fit but stop it throwing an error if it does not fit)?

brycare
 
Posts: 9
Joined: Fri Apr 15, 2016 1:31 pm

Wed Jan 11, 2017 5:53 am

Dear brycare,

Thanks for your detailed information.
The code you provided is to traverse all cells in the table, if the table is too big, that work is so complex, the project may crash. We suggest you only set that format to the cells in the first column, the work is much simpler for the project. Here is sample code for your reference.
Code: Select all
            foreach (TableRow tr in table.Rows)
            {
                //get the first cell in the row
                TableCell FirstCell = tr.Cells.FirstItem as TableCell;
                foreach (Paragraph para in FirstCell.Paragraphs)
                {
                    para.Format.KeepFollow = true;
                }
            }

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jan 13, 2017 8:59 am

Dear brycare,

How is the issue now ?
Could you please give us some feedback at your convenience ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc