ファイルをデータ構造に変換し、データ構造をテーブル(文字列の配列の配列)のように変換し、CSVライブラリを使用してファイルに出力します。
require 'yaml'
require 'csv'
yaml_txt = File.read 'input.yaml'
yaml_data = YAML.load yaml_txt
csv_table = [
[1,'hello world', true],
['a', 'b', 3.14159, 'c', 2, 3e8],
[nil, 'another row', 'bla']
]
#replace this^ with something that converts the yaml_data into a 2D array
File.open 'output.csv', 'w' do |f|
f.puts(csv_table.map do |row|
CSV.generate_line row
end.join "\n")
end
現在の例では、生成されます:output.csvで
1,hello world,true
a,b,3.14159,c,2,300000000.0
,another row,bla
を。
あなたは次のオプションをCSVスプレッドシートを開くことができます。
![alt text](https://i.stack.imgur.com/peKfa.png)
、考えますここであなたの目標についてもう少し具体的に...ヤムルとスプレッドシートとのやりとりとその問題はどういうものですか? –
.xlsにエクスポートしようとしていますか? –
申し訳ありませんが、私はこのような結果はhttp://cl.ly/3r1V353t0N0D263c3w1v – Raecoo