mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-29 03:35:25 +08:00
Generate table.csv
This commit is contained in:
parent
01d48cf679
commit
93bd461a83
2 changed files with 13 additions and 2 deletions
|
@ -128,4 +128,15 @@ class Table < ApplicationRecord
|
|||
Table.connection.execute(sql)
|
||||
end
|
||||
end
|
||||
|
||||
def to_csv
|
||||
require 'csv'
|
||||
|
||||
data = JSON.parse(contents)['data']
|
||||
CSV.generate do |csv|
|
||||
data.each do |row|
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -223,7 +223,7 @@ class ZipExport < ApplicationRecord
|
|||
file = FileUtils.touch(
|
||||
"#{directory}/#{handle_name(table_name)}_#{i}_Step#{step_asset.step.position+1}}.csv"
|
||||
).first
|
||||
File.open(file, 'wb') { |f| f.write(table.contents) }
|
||||
File.open(file, 'wb') { |f| f.write(table.to_csv) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -233,7 +233,7 @@ class ZipExport < ApplicationRecord
|
|||
table_name = table.name.presence || 'Table'
|
||||
table_name += i.to_s
|
||||
file = FileUtils.touch("#{directory}/#{table_name}.csv").first
|
||||
File.open(file, 'wb') { |f| f.write(table.contents) }
|
||||
File.open(file, 'wb') { |f| f.write(table.to_csv) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue