1

I have spreadsheet that looks like the following as a CSV but is saved as an XLS file:

'foo', 'bar', ''
'', '', ''

I run the following ruby code:

require 'rubygems'
require 'spreadsheet'

t = Spreadsheet.open 'test.xls'
t.worksheet(0).row(0)[2] = 'qux'

format = Spreadsheet::Format.new :color=> :blue, :pattern_fg_color => :yellow, :pattern => 1
t.worksheet(0).row(0).set_format(2, format)

t.write('test_out.xls')

The new file looks like:

'foo', 'bar', 'qux'
'', '', ''

but nothing is colored. Why?

olleicua
  • 2,039
  • 2
  • 21
  • 33
  • I'm not familiar with ruby, but with other programming platforms there is no row 0 in Excel. Try switching `row(0)` to `row(1)` – Joseph Oct 04 '13 at 18:44
  • 2
    Joseph - The 'qux' line works with row(0) – Automate This Oct 04 '13 at 18:46
  • this is clearly documented in the api for the spreadsheet gem (the library I'm using) here: http://spreadsheet.rubyforge.org/GUIDE_txt.html The fact that I was able to write 'qux' in the first row of the sheet successfully strongly suggests that will not help. – olleicua Oct 04 '13 at 18:47
  • 1
    @joseph4tw: In ruby, it starts with `0` :) – Siddharth Rout Oct 04 '13 at 18:48
  • 1
    [THIS](http://stackoverflow.com/questions/7730112/ruby-spreadsheet-row-background-color) thread shows that what you have should work... provided it is not a csv file. DISCLAIMER: I have never worked with Ruby (or any of her friends or sisters :P) – Siddharth Rout Oct 04 '13 at 18:50
  • @PortlandRunner and Siddharth, thanks guys! "The more you know" :) – Joseph Oct 04 '13 at 18:55
  • @olleicua: Did u check the link that I gave in my previous comment? – Siddharth Rout Oct 04 '13 at 18:58
  • @SiddharthRout yes, thank you. This is the first I've seen anything use Rows as 0 based, which is a nice touch to be honest. I had plenty of issues remembering that for a while. – Joseph Oct 04 '13 at 19:01
  • @joseph4tw: My apologies. My last comment was meant for `olleicua` Amended it. Got confused between you two.. – Siddharth Rout Oct 04 '13 at 19:03
  • @SiddharthRout Yep that's what I was going off of. It is a .xls file. It's supposed to work but its not. Is it possible that this is a limitation of the .xls format? – olleicua Oct 06 '13 at 19:32

0 Answers0