开发者

Ruby: parse csv data to pdf

开发者 https://www.devze.com 2023-03-13 07:09 出处:网络
I am using prawn gem to generate pdf document how one can parse data from csv to pdf i have used the code some thing like this

I am using prawn gem to generate pdf document

how one can parse data from csv to pdf

i have used the code some thing like this

Prawn::Document.generate("user.pdf", :page_layout => :landscape) do
  exa_url = "D:/userReport.csv"
  csv_data = open(exa_url).read.lines.to_a
  headers = CSV.parse(csv_data[6]).first
  body = CSV.parse(csv_data[7..-1].join)
开发者_Python百科  table body, :headers => headers, :font_size =>10, :position=>:centere
end

it me gives an error,

Is there any other approach, or other advice to fix this


headers = CSV.parse(csv_data[6]).first doesn't mention pos, but your error message does. So you are looking at some error inside CSV.parse (I guess).

Most likely your csv_data Array doesn't contain what you think it does or is otherwise invalid.

In other words, it sounds like you're dealing solely with an issue of parsing CSV data. Try reducing your code to a simpler case and investigate your CSV data.

Good luck.


Sounds like you have an issue with opening your CSV file. I'd recommend doing some irb detective work and making sure csv_data = open(exa_url).read.lines.to_a is working. Sounds like you're trying to interact with csv_data and it's nil.

0

精彩评论

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