2012-04-02 37 views

回答

3

沒有嘗試過了,但也許下面將指向你在正確的方向:

nb_format = Spreadsheet::Format.new :number_format => '$#,###.##' 
cell.set_format(0, nb_format) 
+0

currency_format =電子表格:: Format.new:number_format => '$#,## 0.00 _); [紅色]($#,## 0.00)' 片.row(index).set_format(5,currency_format) 這對我更好。 – 2012-04-02 11:10:54

1

如果你想使用Excel內置的貨幣格式中的一種,一個黑客是使用Excel格式化一個電子表格單元格(比如第1行,列A),並帶有您想要的格式。保存它,然後使用Excel給出該單元格的spreadsheet gemread the format。在我的情況下,我得到_([$$-409]* #,##0.00_);_([$$-409]* \\(#,##0.00\\);_([$$-409]* \"-\"??_);_(@_)作爲美元的格式。然後就可以用它像這樣:

currency_format = Spreadsheet::Format.new number_format: "_([$$-409]* #,##0.00_);_([$$-409]* \\(#,##0.00\\);_([$$-409]* \"-\"??_);_(@_)" 
sheet.row(r).set_format(col, currency_format)