simple_combine_xls 让你合并表格就像画图一样
在使用 simple_combine_xls 之前你必须得知道 ruby 中的 object_id 概念
没错 simple_combine_xls 是基于你分配的 object_id
去合并的单元格,只要单元格的 object_id
相同就会合并在一起
如果你了解 object_id
之后就能很快的去合并一个单元格
你必须传一个二维数组给 simple_combine_xls
city1, city2, city3 = "成都", "南充", "自贡"
spec = "特色"
# menu1, menu2, menu3 的 object_id 都是不同的
menu1, menu2, menu3 = "菜单", "菜单", "菜单"
scenic = "景点"
# 下面的 nil 将不会合并在一起
datas = [
[spec, spec, spec, spec, spec],
[city1, menu1, "串串", scenic, "春熙路"],
[city1, menu1, nil, scenic, "黄龙溪"],
[city1, menu1, "火锅", scenic, "各种免费景点"],
[city2, menu2, "米粉", scenic, "蓝天网吧"],
[city2, menu2, "锅盔", scenic, "鼎盛网吧"],
[city2, menu2, nil, scenic, "五星网吧"],
[city2, menu2, nil, scenic, "各种网吧"],
[city3, menu3, "鲜锅兔", scenic, "7天酒店"],
[city3, menu3, "冷吃兔", scenic, "汉庭酒店"],
[city3, menu3, "各种兔", scenic, nil],
[city3, menu3,"富顺豆花", scenic, nil]
]
使用 drawing
方法去合并单元格
simple_combine_xls = SimpleCombineXls.new(datas)
simple_combine_xls.drawing
# 合并之后 simple_combine_xls.xls 其实就是一个 spreadsheet
simple_combine_xls.xls.write './asd.xls'
# 如果你想对表格进行一个样式操作请查看 https://github.com/zdavatz/spreadsheet
以上代码 将会生成这样的单元格
" "
(一个空格)nil.to_s
可能会合并一些单元格@str = "test"
arr1 = [@str, @str, @str]
arr2 = ["test", "test", "test"]
# 对于 simple_combine_xls 来说 arr1 和 arr2 是完全不同的
# 因为 arr1.map(&:object_id) != arr2.map(&:object_id)