LoginSignup
5
4

More than 5 years have passed since last update.

Axlsxでセル内の改行を反映する

Posted at

改行がうまく反映されなかったため調べていたところ、axlsxのissueの中に解決策が書かれていたのでそれをメモしておきます。

改行コードは\r\nです。

環境

  • Mac Yosemite
  • Ruby 2.2.1
  • Rails 4.2.1
  • axlsx_rails

解決策

以下を追加する。

xlsx_package.use_shared_strings = true

全コード

app/views/hoges/download.xlsx.axlsx
xlsx_package.use_shared_strings = true
xlsx_package.workbook do |wb|
  wb.add_worksheet do |ws|
    ws.add_row ["abc\r\ndef"]
  end
end

参考URL

https://github.com/randym/axlsx/issues/252#issuecomment-27264190

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4