我有以下代码,其中包含csv文件的数据。现在我希望数据显示为所有列的左对齐。
CSV.open("projects.csv",'w') do |row|
if user.god?
row << ["Project Name","Manager","Total Resources","Hours Required"]
each_project_detail.each do |project_detail|
row << [project_detail["project_name"], project_detail["manager_name"].join("\n"), project_detail["total_resources"], project_detail["estimated_hours"].round, project_detail["development_hours"].round, project_detail["extra_hours"].round]
end
else
row << ["Project Name","Hours Required","Hours Spent", "Extra Hours"]
each_project_detail.each do |project_detail|
row << [project_detail["project_name"], project_detail["estimated_hours"].round, project_detail["development_hours"].round, project_detail["extra_hours"].round]
end
end
end
答案 0 :(得分:3)
CSV文件无法进行格式化。列中没有对齐的概念。这只是逗号分隔的值!