mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 20:05:55 +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)
|
Table.connection.execute(sql)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -223,7 +223,7 @@ class ZipExport < ApplicationRecord
|
||||||
file = FileUtils.touch(
|
file = FileUtils.touch(
|
||||||
"#{directory}/#{handle_name(table_name)}_#{i}_Step#{step_asset.step.position+1}}.csv"
|
"#{directory}/#{handle_name(table_name)}_#{i}_Step#{step_asset.step.position+1}}.csv"
|
||||||
).first
|
).first
|
||||||
File.open(file, 'wb') { |f| f.write(table.contents) }
|
File.open(file, 'wb') { |f| f.write(table.to_csv) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ class ZipExport < ApplicationRecord
|
||||||
table_name = table.name.presence || 'Table'
|
table_name = table.name.presence || 'Table'
|
||||||
table_name += i.to_s
|
table_name += i.to_s
|
||||||
file = FileUtils.touch("#{directory}/#{table_name}.csv").first
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue