创建期间的 CSV 文件格式选项

发布于 2024-10-26 10:42:47 字数 853 浏览 1 评论 0原文

我有以下代码,其中包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的那么颓废 2024-11-02 10:43:56

CSV 文件不能有格式。列中没有对齐的概念。这只是逗号分隔的值!

CSV files cannot have formatting. There's no concept of alignment in columns. It's just comma separated values!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文