[ruby语言]Spreadsheet合并单元格(行/列)

关于Spreadsheet合并单元格,有两种方式,第一种是通过Format把相邻的单元格:align => :merge,如下:

book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => "test"

format = Spreadsheet::Format.new(:weight => :bold,:size => 14,
                             :align => :merge, :color=>"white", :border=>:medium,   
                             :border_color=>"black", :pattern => 1 ,  
                             :pattern_fg_color => "black")

row1 = sheet1.row(1)

10.times do |i|
           row1.set_format(i,format)  
 end

这种方式的弊端是麻烦,不能合并列

第二种方式比较简单操作,如下所示:

sheet1.merge_cells(start_row, start_col, end_row, end_col)

只要把填写起始行/列,结束行/列填写就可以,很高效的解决了合并单元格的麻烦.



你可能感兴趣的:([ruby语言]Spreadsheet合并单元格(行/列))