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.

Fri Apr 29, 2022 6:51 pm

I have a table in two pages. I have some data in some of the rows. Can we program so that the page auto reduces height if the data is only in one page so if data in rows is less reduce the document height to one page.

Thank you

AmisHealth
 
Posts: 8
Joined: Fri Apr 21, 2017 5:59 am

Mon May 02, 2022 3:04 am

Hello,

Thanks for your inquiry.

Please refer to the code below and give it a try. If there is still any issue, please feel free to contact us.

C#
Code: Select all
            foreach(TableRow row in table.Rows)
            {
                row.HeightType = TableRowHeightType.AtLeast;
                row.Height = 0;
            }


Java
Code: Select all
        for(Object obj:table.getRows()){
            TableRow row= (TableRow) obj;
            row.setHeightType(TableRowHeightType.At_Least);
            row.setHeight(0);
        }
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue May 03, 2022 5:17 am

Hi,

Unfortunately the code didnt work. (By the way we are using C#.NET)

I will explain in some detail.

I have a document with two pages with one table.

This table sometimes will have data with 2 pages but mostly it wont. So I want to reduce the page to one page if data is less so the report looks good.

I have attached the sample document.

What I do is replace the values inside the tags programmatically and if tags empty I replace them with empty values.

Is there a way to reduce the page height if the table only has data in few rows.

Thank you

AmisHealth
 
Posts: 8
Joined: Fri Apr 21, 2017 5:59 am

Tue May 03, 2022 6:45 am

Hello,

Thanks for your feedback.
Please use the following code to directly specify the row height of the table.
Code: Select all
foreach (TableRow row in table.Rows)
{
    row.HeightType = TableRowHeightType.Exactly;
    row.Height =14;
}

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc