创建期间的 CSV 文件格式选项
我有以下代码,其中包含 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
I have the following code which contains data for the csv file.Now i want the data to be displayed aligned left for all the columns.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CSV 文件不能有格式。列中没有对齐的概念。这只是逗号分隔的值!
CSV files cannot have formatting. There's no concept of alignment in columns. It's just comma separated values!