开发者

CSV file formatting options during creation

I have the fo开发者_开发知识库llowing 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜