2

アクション内の関連するコードは次のとおりです。

# XLS
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet
currency_format = Spreadsheet::Format.new :number_format => '0.00'

sheet1.row(0).concat 'Example header', 'Example header 2', 'Example header 3'



    @transactions.each_with_index do |tx, index|

      row = sheet1.row(index + 1)
      row.push tx.attr1, tx.attr2, tx.attr3      
      row.set_format(1, currency_format)
      row.set_format(2, currency_format)

    end


data = StringIO.new '';
book.write data


respond_to do |format|
  format.xls { send_data data.string, :disposition => "attachment; filename=transactions.xls" }
end

正常にエクスポートされ、セルを数値としてフォーマットできますが、Excel(Macの場合)では、数値フォーマットされた列の値を合計することはできません。通貨フォーマットを選択できますか?

ありがとう

4

1 に答える 1

3

'$#,###.##'数値形式として使用します。詳細については、スプレッドシート gemを使用した通貨数値形式を参照してください。

于 2013-03-23T08:04:07.250 に答える