mirror of
https://github.com/docusealco/docuseal
synced 2026-11-04 06:42:32 -05:00
optimize xlsx export
This commit is contained in:
1 parent
4b00c896e4
commit
b8c1691bd7
4 files changed
+16
-17
No files matched your search
@@ -19,22 +19,19 @@ module Submissions
|
||||
end
|
||||
|
||||
def rows_to_xlsx(rows)
|
||||
workbook = RubyXL::Workbook.new
|
||||
worksheet = workbook[0]
|
||||
worksheet.sheet_name = Time.current.to_date.to_s
|
||||
|
||||
headers = build_headers(rows)
|
||||
headers.each_with_index do |column_name, column_index|
|
||||
worksheet.add_cell(0, column_index, column_name)
|
||||
end
|
||||
|
||||
rows.each.with_index(1) do |row, row_index|
|
||||
extract_columns(row, headers).each_with_index do |value, column_index|
|
||||
worksheet.add_cell(row_index, column_index, value)
|
||||
io = StringIO.new
|
||||
|
||||
Xlsxtream::Workbook.open(io) do |workbook|
|
||||
workbook.write_worksheet(Time.current.to_date.to_s) do |sheet|
|
||||
sheet << headers.to_a
|
||||
|
||||
rows.each { |row| sheet << extract_columns(row, headers) }
|
||||
end
|
||||
end
|
||||
|
||||
workbook.stream.string
|
||||
io.string
|
||||
end
|
||||
|
||||
def rows_to_csv(rows)
|
||||
|
||||
Reference in new issue
Block a user