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

Autowidth cell calculation is now configurable #127

Merged
merged 1 commit into from
Feb 5, 2022
Merged

Autowidth cell calculation is now configurable #127

merged 1 commit into from
Feb 5, 2022

Conversation

eglitobias
Copy link
Contributor

@eglitobias eglitobias commented Feb 2, 2022

On the workbook you can now configure the font_scale_divisor and the bold_font_multiplier to get better results for the automatic cell width calculation
New PR based on feedback: #115

@eglitobias
Copy link
Contributor Author

Example:

require 'axlsx'

p = Axlsx::Package.new
wb = p.workbook
wb.font_scale_divisor = 11.5
wb.bold_font_multiplier = 1.05
s = wb.styles
sm_bold = s.add_style b: true, sz: 5
m_bold = s.add_style b: true, sz: 11
b_bold = s.add_style b: true, sz: 16
ub_bold = s.add_style b: true, sz: 21
sm_text = s.add_style sz: 5
m_text = s.add_style sz: 11
b_text = s.add_style sz: 16
ub_text = s.add_style sz: 21

wb.add_worksheet(name: 'Line Chart') do |sheet|
  sheet.add_row(['Lorem', 'Lorem', 'Lorem', 'Lorem', 'Lorem', 'Lorem', 'Lorem', 'Lorem', 'WWW', 'www', 'iii', 'iii',
                 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed',
                 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed'],
                style: [sm_bold, m_bold, b_bold, ub_bold, sm_text, m_text, b_text, ub_text,
                        b_bold, b_text, b_bold, b_text, b_bold, b_text])
end

p.serialize 'example1.xlsx'

Result:
Screenshot 2022-02-02 at 16 40 09

Copy link
Member

@kiskoza kiskoza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a lot better, thanks for your extra time on making it configurable

@alexanderadam
Copy link

alexanderadam commented Feb 3, 2022

Would it make sense to document to add your example to examples/ or to the style reference?

@eglitobias
Copy link
Contributor Author

Would it make sense to document to add your example to examples/ or to the style reference?

I think on the style reference page it doesn't make much sense because it's more about the styling of the font. But I can add the example from above to the examples.

On the workbook you can now configure the font_scale_divisor and the bold_font_multiplier to get better results for the automatic cell width calculationb
@straydogstudio
Copy link
Contributor

I agree. Nice work. @simi @noniq Any concerns on merging this?

@simi simi merged commit d3cf7bc into caxlsx:master Feb 5, 2022
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.

5 participants