Rails AXLSX gem试图合并最后一行创build的单元格
我有一个在那里创build行的逻辑的axlsx文件。 我有一个检查在那里,当一定条件满足,我想合并最后创build的单元格。 我怎样才能做到这一点?
我已经看到如何合并单元格的唯一方法是通过指定单元格来合并,如下所示:
sheet.merge_cells "A2:B2"
但如果我有一个dynamic工作表,我如何合并最后一行创build的单元格?
Axlsx merge_cells接受一个string,就像在你的例子中,或者一个单元格数组一样。 就此而言,您可以使用行,列和它们的单元格集合来查找并传入要合并的单元格的数组。
就像是:
sheet.merge_cells sheet.rows.last.cells
作为参考,这里是工作表#merge_cell的文档
# Creates merge information for this worksheet. # Cells can be merged by calling the merge_cells method on a worksheet. # @example This would merge the three cells C1..E1 # # worksheet.merge_cells "C1:E1" # # you can also provide an array of cells to be merged # worksheet.merge_cells worksheet.rows.first.cells[(2..4)] # #alternatively you can do it from a single cell # worksheet["C1"].merge worksheet["E1"] # @param [Array, string] cells def merge_cells(cells) merged_cells.add cells end