我试图使用TableFactory
创建一个表,但是几乎没有文档,我只能找到twoexamples。PDFTable
函数确实输出了一个PDF,但是它似乎没有找到数据!你知道吗
我的代码:
#Import module components
from TableFactory import *
# Build the data setup required
ids = ['a','b','c','d','e','f','g','h','i']
lon = [-80.15765381, -80.40131378, -80.56086731, -80.52893066,
-80.24595642, -80.7718277, -80.877388, -79.9454422, -79.84288025]
lat = [ 0.34739658, -0.39966396, -0.91119879, 0.83061123, 0.67057306,
-0.1843673, -0.18189907, 0.43762371, 0.45526683]
depth = [ 14044, 4942, 7000, 13107,
6281, 7000, 1172, 4825, 6730]
rows4 = TableRow()
setattr(rows4, 'ids', ids)
setattr(rows4, 'lon', lon)
setattr(rows4, 'lat', lat)
setattr(rows4, 'depth', depth)
invoicerow = RowSpec(ColumnSpec('ids', 'Event ID'),
ColumnSpec('lon', 'Longitude'),
ColumnSpec('lat', 'Latitude'),
ColumnSpec('depth', 'Depth'))
lines = invoicerow.makeall(rows4)
#create the tables
#HTML
HTMLTable('Invoices by Customer',
'Amount of each invoice, sorted by invoiceid',
headers=invoicerow).render(lines)
# Excel
SpreadsheetTable('Invoices by Customer',
'Amount of each invoice, sorted by invoiceid',
headers=invoicerow).render(lines)
# PDF
pdfmaker = PDFTable('My title',
headers=invoicerow)
open('invoicetable.pdf', 'wb').write(pdfmaker.render(lines))
但它并没有产生我所期望的结果:
你很接近!下面是我如何稍微修改的:
基本上,TableFactory需要的是行对象列表,而不是列列表。我将您的列列表(
ids
、lon
、lat
、depth
)转换为TableFactory可以处理的DataRow对象列表。你知道吗相关问题 更多 >
编程相关推荐