Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set explicit column widths for tables #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martinsp
Copy link
Contributor

Thank you for the great library!

I had to generate table where first row had a single cell with colspan set to total number of table columns. Because of this - cell code that generates <w:gridCol> elements made all the columns the same width.

This patch allows to set explicit column widths for tables by setting table_column_widths property on TableModel

Maybe there is a better approach to achieve the same result?

Example: column widths applied correctly if first row does not have cell with colspan
docx.table [['01', '02', '03'], ['11'], ['21', '22', '23']] do
  width 8000
  border_color   '666666'
  border_line    :single
  border_size    1

  cell_style cells, width: 2000
  cell_style cols[0], width: 4000
  cell_style rows[1][0], colspan: 3
end

Result

Screenshot 2019-03-22 at 17 59 35
Example: column widths not applied correctly if first row has cell with colspan
docx.table [['11'], ['21', '22', '23']] do
  width 8000
  border_color   '666666'
  border_line    :single
  border_size    1

  cell_style cells, width: 2000
  cell_style cols[0], width: 4000
  cell_style rows[0][0], colspan: 3
end

Result

Screenshot 2019-03-22 at 17 59 28
Example: column widths set explicity when first row has cells with colspan
docx.table [['11'], ['21', '22', '23']] do
  width 8000
  border_color   '666666'
  border_line    :single
  border_size    1
  column_widths [4000, 2000, 2000]

  cell_style rows[0][0], colspan: 3
end

Result

Screenshot 2019-03-22 at 17 59 46

@jdugan
Copy link
Contributor

jdugan commented Mar 24, 2019

Hei, Martins.

Thanks for the contribution. I'm booked solid this coming week, so don't be discouraged if it takes me a while to review the PR and provide feedback. You're in my mental queue--I'll circle back. :)

Thanks,
John

@martinsp
Copy link
Contributor Author

Hi John,

thanks for the notice and no worries :)

goulvench added a commit to goulvench/caracal that referenced this pull request Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants