title: Ruby spreadshet gem, how can I center align a number
body: <p>I'm using <a href="http://spreadsheet.rubyforge.org" rel="nofollow noreferrer">http://spreadsheet.rubyforge.org</a> to generate a spreadsheet and I'm having trouble with something. I'm opening an existing workbook and adding data to it.</p>
  
  <p>I have manged to get number formatting working to some extent, at least excel is seeing this data as a number, but (very un-excel like) the client would like the number aligned in the center :( </p>
  
  <p>My current code looks something like this:</p>
  
  <pre><code>nfmt = Spreadsheet::Format.new :number_format =&gt; '0.00'
  row = sheet.row(1)
  row[0] = "Result"
  row[1] = 45.55
  row.set_format 1, nfmt
  </code></pre>
  
  <p>Maybe a little far fetched but wondered if anybody can help?</p>
  
  <ul>
  <li>Spreadsheet does not modify Formatting at present. That means in particular
  that if you set the Value of a Cell to a Date, it can only be read as a
  Date if its Format was set correctly prior to the change.</li>
  </ul>
  
  <p><strong>Edit for Trevoke</strong></p>
  
  <p>Thanks for helping with this. I've tried your code and it works fine. I guess the difference is I'm editing an existing spreadsheet, in which case the formatting is ignored. Try this:</p>
  
  <pre><code>require 'rubygems'
  require 'spreadsheet'
  
  Spreadsheet.client_encoding = 'UTF-8'
  
  book = Spreadsheet.open "edit_me.xls" # Blank spreadsheet
  
  sheet1 = book.worksheet 0
  
  format = Spreadsheet::Format.new :horizontal_align =&gt; :centre
  sheet1.row(0).default_format = format
  sheet1.row(0).push 'I rule 2!', 43.56
  
  book.write 'edited_you.xls'
  </code></pre>