I am generating pdf and word documents. In that displaying the tables using html tags. columns will be different for each records. I want to set width of the column based list count. If list have 3 records i want to display 3 coulumns fit in the table width.(means table width is 100%, then column width should be 100/3). If list has 5 records i want to display 4 columns(here column width should be 100/4). max 7 records. How to set the width dynamically..?

1 Answer 1


You can simple check the number of rows in your controller and calculate width .

for ex:

Integer width = 100 / number_of_records;

And then use this variable in you VF/HTML. for ex.

        <TD width="{!width}">
        <TD width="{!width}">
        <TD width="{!width}">
        <td>First Name</td>
        <td>Last Name</td>
  • Hi it's working perfectly for pdf. but word document i am not getting width what i mentioned. Mar 4, 2016 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.