Gem 导出、读取 excel 用哪个 gem 包比较好啊

winse · August 29, 2017 · Last by tinyfeng replied at August 30, 2017 · 2099 hits

我现在用的是 SpreadSheet,但是当我读取模板文件后进行动态插入或者删除行时,没有达到像实际操作 excel 删除行的效果,而且样式也经常失效😂

模板:

我想在中间多加几行,代码:

current_row = 1
5.times.each do |i|
  sheet.insert_row current_row, [i + 1, 22, '', '80.19', '']
  current_row += 1
end

然而效果完全不同。。。

而且 spreadsheet 还不支持图片插入

Reply to lypdarling

生成 excel 用这个 gem 方便吗

Reply to winse

具体的可以看下 Railscast #362 和 #396

xlsx 格式可以用这个 gem rubyXL

简单的 excel 我都是用 erb 生成 xml 格式的

用过 roo 读 excel, axlsx 输出 excel. 都还不错

Reply to zhanglinjie

支持生成嵌套 cell 么

Reply to zhanglinjie

:change_horizontal_alignment 这个方法有些问题啊

sheet.change_row_horizontal_alignment current_row, 'center'
current_row += 1
sheet.change_row_horizontal_alignment current_row, 'right'

期望前一行问题居中对齐,后一行居右对齐,但是结果全部居右了😅 而且为啥我导出的文件都有问题

你这个分奇偶行的

current_row = 1
5.times.each do |i|
  sheet.insert_row current_row, [i + 1, 22, '', '80.19', '']
  current_row += 2
end

这样再试试

You need to Sign in before reply, if you don't have an account, please Sign up first.