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

Table cell widths ignored? #123

Open
leei opened this issue May 22, 2019 · 5 comments
Open

Table cell widths ignored? #123

leei opened this issue May 22, 2019 · 5 comments

Comments

@leei
Copy link

leei commented May 22, 2019

Table cell widths seem to be accepted but ignored in modern versions of Word (16.25 for Mac and current Word on Windows 10. When I open a docx with Pages or Open Office, it seems to be respecting the twips-based cell widths, but in Word it seems to default to just auto-width even when twips are given.

I'm trying to get percentage width columns so I'm effectively going with:

container_width = docx.page_width - docx.page_margin_left - docx.page_margin_right
col_width = container_width / 3

and then

cell = Caracal::Core::Models::TableCellModel.new do |cell|
cell.width col_width
cell.h4 "Direct Reports"
end

Any hints? Do I need to do the calculation differently?

@jdugan
Copy link
Contributor

jdugan commented May 22, 2019

I gather that this is somewhere between code and pseudocode, but before we dive in too deep, your example above uses the variable thirds to set the width, but you call that variable col_width in the code above it.

Is that a function of how you translated/presented the code in the issue description, or is it possible you are passing a nil or similar into the width method? Which some versions might interpret to mean divide the widths evenly and others to mean autofit?

@leei
Copy link
Author

leei commented May 22, 2019

Yes, just corrected the example. Ideally, I'd like to be able to specify a pct width without needing to calculate...

@martinsp
Copy link
Contributor

This pull request might be related: #115 . It allows to set column widths, but does not support percentages.

Without this patch caracal "auto-calculates" column widths from the first row. If you specify cell width in a row other than first row, it will be ignored.

@leei
Copy link
Author

leei commented May 29, 2019

@martinsp Your pull request is probably related. The issue with my table is a header row with colspan: 2 or 3. That seems to be the precipitating problem. I'm going to try a few things in caracal-example to test your theory.

@leei
Copy link
Author

leei commented May 29, 2019

Here's a replicable example (inserted into caracal-example doc):

docx.table [['Only Header'], row2.dup, row3.dup, row4.dup], border_size: 4 do
  cell_style rows[0],    bold: true,   background: '3366cc', color: 'ffffff', colspan: 2
  cell_style rows[-1],   bold: true,   background: 'dddddd'
  cell_style cells[5],   italic: true, color: 'cc0000'
  cell_style cols[0],    width: 6000
  cell_style cols[1],    width: 3000
  cell_style cells,      size: 18, margins: { top: 100, bottom: 0, left: 100, right: 100 }
end

This generates a table with a header row and then two "equal width" columns... Yikes!

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

No branches or pull requests

3 participants