Python ReportLab-创建表时出错

Python ReportLab-创建表时出错,python,reportlab,Python,Reportlab,这是我第一次使用ReportLab,我试图编辑一个现有的脚本,该脚本完全符合我的要求,但当我尝试运行该脚本时,出现了以下错误 脚本- import os, arcgisscripting, datetime, getpass, string from reportlab.lib.pagesizes import A4 from reportlab.platypus import * from reportlab.lib import colors from reportlab.lib.styl

这是我第一次使用ReportLab,我试图编辑一个现有的脚本,该脚本完全符合我的要求,但当我尝试运行该脚本时,出现了以下错误

脚本-

import os, arcgisscripting, datetime, getpass, string

from reportlab.lib.pagesizes import A4
from reportlab.platypus import *
from reportlab.lib import colors
from reportlab.lib.styles import ParagraphStyle

myWorkspace = r"W:\City.gdb"
myReportFolder = r"W:\Reports"
myLogosFolder = r"W:\Logos"
OpenPDF = "true"

gp = arcgisscripting.create(9.3)


#setup geoprocessor
gp.workspace = myWorkspace
gp.toolbox = "analysis"
gp.OverwriteOutput = 1
mySelectedGroupsFC = myWorkspace + os.sep + "SelectedGroups"
myNewBusinessFC = myWorkspace + os.sep + "New_Businesses"
myBufferFC = myWorkspace + os.sep + "Buffer"
myReportTable = myWorkspace + os.sep + "FINAL_TABLE"

#obtain Selected groups
mySelGroupsCursor = gp.searchcursor(mySelectedGroupsFC)
mySelectedGroups = mySelGroupsCursor.next()

#obtain New Business groups
myNewBusinessCursor = gp.searchcursor(myNewBusinessFC)
myNewBusiness = myNewBusinessCursor.next()

#obtain Buffer
myBufferCursor = gp.searchcursor(myBufferFC)
myBuffer = myBufferCursor.next()

#setup PDF doc
Author = getpass.getuser() #gets OS user name
pdf_file_name = myNewBusiness.POSTCODE
pdf_file = myReportFolder + os.sep + pdf_file_name + ".pdf"

doc = SimpleDocTemplate(pdf_file, pagesize=A4)

#array of report elements
parts = []

#
#HEADER
#
parstyle = ParagraphStyle(name='Title', fontName='Helvetica', fontSize=12, alignment=1, spaceAfter=20)
p = Paragraph('<b><u>Report</u></b>', parstyle)
parts.append(p)

p = Paragraph('The following community groups are located within <b><u>' + myBuffer.Buffer + 'metres  of -  <b><u>' + myNewBusiness.Postcode + '<\b><\u>.',parstyle)
parts.append(p)

#
#TABLE
#

while myBuffer:
    parstyle = ParagraphStyle(name='Title', fontName='Helvetica', fontSize=11, alignment=0, spaceAfter=15, spaceBefore =15)
    p = Paragraph('<b><u>Community groups within ' + myBuffer.Buffer + ' metres of ' + myNewBusiness.Postcode  + '</u><\b>', parstyle)
    parts.append(p)

    data = []
    parstyle = ParagraphStyle(name='Title', fontName='Helvetica', fontSize=11, alignment=0)    

    while mySelectedGroups:
        selectedGroups_desc = 'Community ID:'+ '<i>' + mySelectedGroups.Community_ID + '<\i>' + 'Organisation Name :' + mySelectedGroups.Organisation_Name  
        p = Paragraph(selectedGroups_desc, parstyle)
        mySelectedGroups = mySelGroupsCursor.next()


    #build and format table
    t=Table(data, colWidths=(100,100))
    t.setStyle(TableStyle([
        ('ALIGN',(0,0),(-1,-1),'CENTER'),
        ('VALIGN',(0,0),(-1,-1),'TOP'),
        ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
        ('BOX', (0,0), (-1,-1), 0.25, colors.black),
        ('TOPPADDING', (0,0), (-1,-1), 10),
        ]))
    parts.append(t)

myBuffer = myBufferCursor.next()

#Footnote
parstyle = ParagraphStyle(name='Title', fontName='Helvetica', fontSize=11, alignment=0, spaceAfter=15, spaceBefore=15)
p = Paragraph('''Should you have any further questions **''', parstyle)
parts.append(p)


#Build document
doc.build(parts)

del mySelGroupsCursor, myNewBusinessCursor, myBufferCursor

#Open document
if OpenPDF == "true":
    os.startfile(pdf_file)
导入操作系统、arcgisscripting、日期时间、getpass、字符串
从reportlab.lib.pagesizes导入A4
从reportlab.platypus导入*
从reportlab.lib导入颜色
从reportlab.lib.styles导入段落样式
myWorkspace=r“W:\City.gdb”
myReportFolder=r“W:\Reports”
myLogosFolder=r“W:\Logos”
OpenPDF=“true”
gp=arcgisscripting.create(9.3)
#安装地理处理器
gp.workspace=myWorkspace
gp.toolbox=“分析”
gp.OverwriteOutput=1
mySelectedGroupsFC=myWorkspace+os.sep+“SelectedGroups”
myNewBusinessFC=myWorkspace+os.sep+“新业务”
myBufferFC=myWorkspace+os.sep+“Buffer”
myReportTable=myWorkspace+os.sep+“最终表格”
#获取选定的组
myselGroupsUrsor=gp.searchcursor(mySelectedGroupsFC)
mySelectedGroups=mySelGroupsCursor.next()
#获得新的商业团体
myNewBusinessCursor=gp.searchcursor(myNewBusinessFC)
myNewBusiness=myNewBusinessCursor.next()
#获取缓冲区
myBufferCursor=gp.searchcursor(myBufferFC)
myBuffer=myBufferCursor.next()
#设置PDF文档
Author=getpass.getuser()#获取操作系统用户名
pdf_file_name=myNewBusiness.POSTCODE
pdf_file=myReportFolder+os.sep+pdf_file_name+“.pdf”
doc=SimpleDocTemplate(pdf_文件,页面大小=A4)
#报表元素数组
部分=[]
#
#标题
#
parstyle=段落样式(name='Title',fontName='Helvetica',fontSize=12,alignment=1,spaceAfter=20)
p=段落('报告',段落类型)
部分。附加(p)
p=段落('以下社区组位于“+myBuffer.Buffer+”米范围内,距离-”+myNewBusiness.Postcode+”,parstyle)
部分。附加(p)
#
#桌子
#
而myBuffer:
parstyle=段落样式(name='Title',fontName='Helvetica',fontSize=11,alignment=0,spaceAfter=15,spaceBefore=15)
p=段落(“+myBuffer.Buffer+”米范围内的社区组,“+myNewBusiness.Postcode+”,parstyle)
部分。附加(p)
数据=[]
parstyle=段落样式(name='Title',fontName='Helvetica',fontSize=11,alignment=0)
而MySelectedGroup:
selectedGroups_desc='社区ID:'++'+mySelectedGroups.Community_ID++'+'组织名称:'+mySelectedGroups.organization_名称
p=段落(选择组描述,部分样式)
mySelectedGroups=mySelGroupsCursor.next()
#生成和格式化表格
t=表格(数据,冷宽=(100100))
t、 设置样式(表样式)([
('ALIGN',(0,0),(-1,-1),'CENTER'),
('VALIGN',(0,0),(-1,-1),'TOP'),
('INNERGRID',(0,0),(-1,-1),0.25,颜色。黑色),
('BOX',(0,0),(-1,-1),0.25,颜色。黑色),
('TOPPADDING',(0,0),(-1,-1),10),
]))
部分。附加(t)
myBuffer=myBufferCursor.next()
#脚注
parstyle=段落样式(name='Title',fontName='Helvetica',fontSize=11,alignment=0,spaceAfter=15,spaceBefore=15)
p=段落(“‘您是否还有其他问题**’”,parstyle)
部分。附加(p)
#生成文档
文件生成(部件)
del mySelGroupsCursor、myNewBusinessCursor、myBufferCursor
#打开文件
如果OpenPDF==“true”:
os.startfile(pdf_文件)
我得到的错误是:

Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "H:\Report_v2.py", line 100, in <module>
    t=Table(data, colWidths=(100,100))
  File "C:\Python25\Lib\site-packages\reportlab\platypus\tables.py", line 236, in __init__
    raise ValueError("%s must have at least a row and column" % self.identity())
ValueError: <Table@0x010F4710 0 rows x unknown cols>... must have at least a row and column
回溯(最近一次呼叫最后一次):
RunScript中的文件“C:\Python25\Lib\site packages\Pythonwin\framework\scriptutils.py”,第325行
主目录中的exec codeObject__
文件“H:\Report_v2.py”,第100行,在
t=表格(数据,冷宽=(100100))
文件“C:\Python25\Lib\site packages\reportlab\platypus\tables.py”,第236行,在\uuu init中__
raise VALUERROR(“%s”必须至少有一行和一列“%self.identity())
ValueError:。。。必须至少有一行和一列
有什么想法我需要做,因为我有点挣扎


谢谢。

从错误和代码来看,问题似乎是
数据
是空数组
[]
。ReportLab似乎对此感到窒息,所以您只需要向表
t
提供一些数据,它应该可以工作