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

Text orientation/rotation #110

Closed
javierfdr opened this issue Jul 8, 2012 · 4 comments
Closed

Text orientation/rotation #110

javierfdr opened this issue Jul 8, 2012 · 4 comments

Comments

@javierfdr
Copy link

Is there a way to change vertical/horizontal of text within the cells?. Otherwise, it would be nice to be able to assign a given rotation for text. My problem is that I have 'column header names' that are really long, but each of the column values are 2 digit numbers, so the column width expands too much. I would like to display the header with vertical orientation, and the rest of the column values as usual.

Thanks for your help

@JonathanTron
Copy link
Collaborator

You should be able to do that by assigning a style to the cell:

p = Axlsx::Package.new
wb = p.workbook
ws = wb.add_worksheet
cell_rotated_text_style = wb.styles.add_style(:alignment => {:textRotation => 90})
ws.add_row(
  ["Short cell", "My long title which should be rotated"], 
  :style => [nil, cell_rotated_text_style]
)

@javierfdr
Copy link
Author

Thank you very much. That worked perfectly for the whole row.
Is it possible to apply the style just to a given cell in the row, instead of the whole row?

@javierfdr
Copy link
Author

Ok, I've just found out how can you do it. For instance, if you want to apply the new style for cells [0,..,2] of rows[0,..,.2] you could do:

ws.rows[0..2].each {|row| row.cells[(0..2)].each {|cell| cell.style = cell_rotated_text_style} }

Taken from issue: #16

Thanks

@randym
Copy link
Owner

randym commented Jul 9, 2012

thanks @JonathanTron!
@javierfdr you can also pass a sparse style array on add row or use sheet['D1:F3'] style notation if it feels cleaner to you.

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