本帖最后由 Fangdidididi 于 2022-3-14 00:24 编辑
[Ruby] 纯文本查看 复制代码 require 'rubyXL'
require 'json'
`ls *.json`.split("\n").each do |name|
name = name.gsub(".json","")
workbook = RubyXL::Workbook.new
worksheet = workbook[0]
File.open("#{name}.json","r").readlines.each_with_index do |line,i|
puts "----------------#{i}"
# next if i >80000
puts doc = JSON.parse(line)
if i == 0
doc.keys.each_with_index do |k,l|
worksheet.add_cell(i,l,k)
end
end
p doc.keys
doc.keys.each_with_index do |key,l|
worksheet.add_cell(i+1,l,doc[key].to_s)
end
end
workbook.write("#{name}.xlsx")
end
读取当前目录下的json后缀文件,并将json数据转换成excel |