Fix Format borders #6

Merged
merged 3 commits into from Jun 26, 2012

Conversation

Projects
None yet
2 participants
Contributor

uraki66 commented Jun 26, 2012

These commits correct the Format borders implementation and correct the issue with Excel choking on a .xls written by Spreadsheet when borders are specified.

You can now write an .xls with borders and/or border_colors and the resulting file works in both Excel and Open/LibreOffice.

Borders were previously implemented as booleans which is incorrect...the are line-sytles (bit values).

The full list of border styles are now available:

  • :none, :thin, :medium, :dashed, :dotted, :thick,
  • :double, :hair, :medium_dashed, :thin_dash_dotted,
  • :medium_dash_dotted, :thin_dash_dot_dotted,
  • :medium_dash_dot_dotted, :slanted_medium_dash_dotted

So something like:

x = Spreadsheet::Format.new
x.border = :thick
x.border_color = :green

Sets the cell border to a thick, green border

The issue with Excel crashing if you set a border wasn't related to the border style, but rather the border color....I'm not sure of the exact issue, but if the border_color was one of the :builtin_, then Excel had issues with the resulting .xls. Changing the default color to :black fixed this....I suspect it's a result of builtin formats/indexes vs "user" formats when the binary .xls is written (the 'xf' records), but it's beyond my feeble skills to figure out what is happening. I did save and dump a few Excel workbooks in .xml format (to get an idea of what was being saved in the real .xls) and I really think the default/builtin formats aren't being written correctly and/or indexed for formats that have :builtin_ colors in them.

The reader was also fixed to properly pull in the border styles & border colors...however, if the reader pulls in a border color of :builtin_, it will end up saving it with that color and most likely create an .xls that will crash Excel and not allow right-click "Format Cells".

Further work of dumping & tracing the layout of Excel sheets needs to be done to ultimately correct the issue/mystery of :builtin_black, red, green, etc and how the system xf records relate to them.

I added some basic tests for the Format.border & Format.border_colors.

Owner

zdavatz commented Jun 26, 2012

Very nice! Thank you! Can you update the testcases as well?

Best
Zeno

Contributor

uraki66 commented Jun 26, 2012

The test cases for Format are in the commits. I did not add a new Excel file and the reading tests. I can do that tonight once I get home.

@zdavatz zdavatz merged commit fbc4160 into zdavatz:master Jun 26, 2012

Owner

zdavatz commented Jun 26, 2012

Ok, thank you! Please do it. I already released the new gem.

@jperkin jperkin pushed a commit to joyent/pkgsrc that referenced this pull request Dec 9, 2013

obache Update ruby-spreadsheet to 0.7.3.
=== 0.7.3 / 26.06.2012

* Fix Format borders
* see zdavatz/spreadsheet#6 for full details.
* patches by uraki66@gmail.com
73e8b7a

@jsonn jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Oct 11, 2014

obache Update ruby-spreadsheet to 0.7.3.
=== 0.7.3 / 26.06.2012

* Fix Format borders
* see zdavatz/spreadsheet#6 for full details.
* patches by uraki66@gmail.com
643b93b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment