我正在關注this tutorial創建一個使用蝦寶石的pdf文件, 和我發現this reference文檔來生成一個表。如何在Prawn中設置表頭?
如何將標題行和標題標題設置爲每列?
invoiceData = [["foo","bar"]]
pdf.table(invoiceData) do |table|
table.rows(1..3).width = 72
end
我正在關注this tutorial創建一個使用蝦寶石的pdf文件, 和我發現this reference文檔來生成一個表。如何在Prawn中設置表頭?
如何將標題行和標題標題設置爲每列?
invoiceData = [["foo","bar"]]
pdf.table(invoiceData) do |table|
table.rows(1..3).width = 72
end
如果您傳遞:header => true作爲選項,它應該使用數組的第一行作爲重複標題。從文檔:
data = [["This row should be repeated on every new page"]]
data += [["..."]] * 30
table(data, :header => true)
另外,請嘗試新的「自我記錄手冊」。這比rdoc更具說明性。 [pdf手冊](http://cloud.github.com/downloads/sandal/prawn/manual.pdf) – dogenpunk 2011-04-15 16:25:37
這是否適用於多列標題? – 2011-04-15 17:05:30
這個工作對我來說:
pdf.table data, :headers => ['foo', 'bar']
除了@dogenpunk的答案,也可以設置標題行的樣式:
table_data = generate_lots_of_table_data
table_data.unshift %w(id name address) # add headers
table(table_data, header: true) do
row(0).style font_style: :bold # header style
end
免責聲明:這並不回答你的問題。我用Wkhtmltopdf將HTML轉爲PDF。 WAY更容易,儘管有一些配置可以讓它設置。我想我讀了關於使用它的寶石。也許這簡化了配置。我認爲這值得檢查。 – revdrjrr 2011-04-15 15:45:45