Bottom Row for Tables That Spans Across Two Pages


#1

Hi there,

We are using Aspose Word for .Net version 17. We stumble upon issue with bottom border in table that spans across two pages. We generate table on the fly and on the case where the table spans across two pages, the last row of the table for each page is not generated. Please see the attached image to better know our problem.
AsposeTable.png (86.5 KB)

Would you be able to assist us how we may rectify this please? Thank you.


#2

@BenchmarkEst,

Thanks for your inquiry. Please set the height rule of row as “Auto” as shown below to get the correct output. Please refer to the following article.
Specifying Row Heights

If you still face problem, please ZIP and attach your input and expected output Word documents here for our reference. We will then provide you more information about your query along with code.

Document doc = new Document(MyDir + "in.docx");

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
    foreach (Row row in table.Rows)
    {
        row.RowFormat.HeightRule = HeightRule.Auto;
    }
doc.Save(MyDir + "18.6.docx");

#3

Hi Tahiz,

I apologize for being unclear with my question. But the problem is that the bottom border of the last row of each page is not being printed. Like the image i attached. Do you think you could help us with that? Thank you.


#4

@BenchmarkEst,

Thanks for your inquiry. Please note that Aspose.Words mimics the behavior of MS Word. If the bottom border of table’s row is not set, you can set it using Aspose.Words.

Please ZIP and attach your input and expected output Word documents here for our reference. We will then provide you more information about your query along with code.


#5

Hi Tahir,

I am attaching two documents. If you open document 0109.04_with issues.docx, you will see that it contains the issue. I marked the row in light blue, it does not have bottom border. As the document 0109.04_expected_result.docx, we expect the row to have bottom border. FYI again, the table is created on the fly dynamically. Please let me know if you unsure about my question/issue. Thank you.Documents.zip (39.4 KB)


#6

@BenchmarkEst,

Thanks for sharing the detail. In your document, the last row on the page has no bottom border. You need to set the bottom border of row’s cell. Please use the following code example to get the desired output.

Document doc = new Document(MyDir + "0109.04_with issues.docx");
LayoutCollector collector = new LayoutCollector(doc);
                 
foreach (Table table in doc.GetChildNodes(NodeType.Table, true).ToArray())
{
    if (collector.GetStartPageIndex(table.FirstRow) != collector.GetStartPageIndex(table.LastRow))
    {
        int pagenumber = collector.GetStartPageIndex(table.FirstRow);
        int rowindex = 0;
        foreach (Row row in table.Rows)
        {
            if (collector.GetStartPageIndex(row) != pagenumber)
            {
                rowindex = table.Rows.IndexOf(row) - 1;
                foreach (Cell cell in table.Rows[rowindex].Cells)
                {
                    cell.CellFormat.Borders[BorderType.Bottom].LineWidth = 1.0;
                }

                break;
            }
        }
        }
}

doc.Save(MyDir + "18.7.docx");

#7

Thanks for your help Tahir! It fixes the issue!


#8

@BenchmarkEst,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.


#9

Hi Tahir,

I came across with the same issue again in different document. It seems that the LayoutCollector get the page number incorrect therefore the bottom border is set in the wrong row. I am attaching the document. Would you be able to let me know what might cause the issue please? Thank you.Quote_17 07 20182.zip (27.8 KB)


#10

@BenchmarkEst,

Thanks for your inquiry. Please use following modified code to get the desired output.

Document doc = new Document(MyDir + "Quote_17 07 20182.docx");
LayoutCollector collector = new LayoutCollector(doc);
                 
foreach (Table table in doc.GetChildNodes(NodeType.Table, true).ToArray())
{
    if (collector.GetStartPageIndex(table.FirstRow) != collector.GetStartPageIndex(table.LastRow))
    {
        int pagenumber = collector.GetStartPageIndex(table.FirstRow);
        int rowindex = 0;
        foreach (Row row in table.Rows)
        {
            if (collector.GetStartPageIndex(row) != pagenumber)
            {
                rowindex = table.Rows.IndexOf(row) - 1;
                foreach (Cell cell in table.Rows[rowindex].Cells)
                {
                    cell.CellFormat.Borders[BorderType.Bottom].LineWidth = 1.0;
                }
            }

            pagenumber = collector.GetStartPageIndex(row);
        }
    }
}

doc.Save(MyDir + "18.7.docx");

#11

Hi Tahir,

I have tried your code, but still I got the output wrong. Please see the attached image.TableBorder.PNG (19.8 KB)

FYI, I use Aspose dll version 17.6.


#12

@BenchmarkEst,

Thanks for your inquiry. Please use latest version of Aspose.Words for .NET 18.7 to get the correct output.


#13

Hi Tahir, I have brought the latest version and is now on version 18.7 and the issue still happens. Would you be able to investigate if there is anything different with the document that I attached please?


#14

@BenchmarkEst,

Thanks for your inquiry. We have not found the shared issue while using latest version of Aspose.Words for .NET 18.8. We have attached the output DOCX with this post for your kind reference. 18.8.zip (24.9 KB)