Module: SqlToXls::SqlToXlsTemple
Instance Method Summary collapse
Methods included from SqlToXlsIo
#execute_sql, #init_sql, #to_xlsx
Instance Method Details
#temple_report(temple_path, sql, start_row) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sql_to_xls/sql_to_xls_temple.rb', line 6 def temple_report(temple_path,sql,start_row) report = execute_sql(sql) add_size = report.first&.size start_row = start_row.to_i file = Spreadsheet.open temple_path list = file.worksheet 0 # 默认sql的列数要和xls模板列数对应 report.each_with_index do |detail,index| add_size.times do |i| list[index+start_row,i] = detail[i] end end xls_report = StringIO.new file.write xls_report xls_report.string end |