[reportlab-users] looping through text error.
Siddique, Halil
Halil.Siddique at cityoflondon.gov.uk
Fri Apr 13 11:36:33 EDT 2012
Hi all,
I've only just looked at reportlab for the last few days so please bear
with me.
I have a script that was already in use and tried to modify it, what the
code should do is loop through all the records, and append them to a
list, but I cannot get it to work.
Here is the code
import os, arcgisscripting, datetime, string
from reportlab.lib.pagesizes import A4
from reportlab.platypus import *
from reportlab.lib import colors
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.units import inch
myWorkspace = r"W:\ HeartOfTheCity.gdb"
myReportFolder = r"W\Reports"
myLogosFolder = r"W:\ \Images"
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
pdf_file_name = myNewBusiness.Postcode
pdf_file = myReportFolder + os.sep + pdf_file_name + ".pdf"
doc = SimpleDocTemplate(pdf_file, pagesize=A4)
# create a list and add the elements of our document (image, paragraphs,
table, chart) to it
story = []
#First add the the title of the report
#
#HEADER
#
parstyle = ParagraphStyle(name='Title', fontName='Helvetica',
fontSize=12, alignment=1, spaceAfter=20)
p = Paragraph('<b><u> Search Report</u></b>', parstyle)
story.append(p)
#Second add the title
#TITLE
#
p = Paragraph('The following community groups are located within <b><u>'
+ myBuffer.Buffer + ' metres of - <b><u>' + myNewBusiness.Postcode +
'<\b><\u>.',parstyle)
story.append(p)
#Third, add the map image
#MAP
#
map = Image("W:\Heart of the City mapping project 2012\Images" + os.sep
+ myNewBusiness.Postcode + ".jpg", width=5*inch, height=4*inch)
map.hAlign = 'CENTER'
story.append(map)
#Enter while loop for each buffer feature
#while myBuffer:
while myBuffer:
print myBuffer.Buffer
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><br>', parstyle)
story.append(p)
data = []
parstyle = ParagraphStyle(name='Title', fontName='Helvetica',
fontSize=10, alignment=0)
while mySelectedGroups:
selectedGroups_desc = 'Community ID:'+ '<i>' +
mySelectedGroups.Community_ID + '<\i>'+ 'Organisation Name :' +
mySelectedGroups.Organisation_Name + '<br>'
p = Paragraph(selectedGroups_desc, parstyle)
data.append(p)
#print data
mySelectedGroups = mySelGroupsCursor.next()
story.append(data)
#print story
myBuffer = myBufferCursor.next()
#
#FOOTER
#
parstyle = ParagraphStyle(name='Title', fontName='Helvetica',
fontSize=11, alignment=0, spaceAfter=15, spaceBefore=15)
p = Paragraph('''Should you have any further questions **''', parstyle)
story.append(p)
doc.build(story)
del mySelGroupsCursor, myNewBusinessCursor, myBufferCursor
#Open document
if OpenPDF == "true":
os.startfile(pdf_file)
When the code goes into the second while loop (mySelectedGroups), it
loops through and adds the data to the variable data, but when it exits
the loop and goes into story.append(data),an error occurs
AttributeError: 'list' object has no attribute 'getKeepWithNext'
(note I am using the free version of RL, and listflowable isn't
included from what I have read).
So my question is how to a list the values that are looped into my pdf?
Thanks
Halil
-----------------------------------------
THIS E-MAIL AND ANY ATTACHED FILES ARE CONFIDENTIAL AND MAY BE
LEGALLY PRIVILEGED. If you are not the addressee, any disclosure,
reproduction, copying, distribution or other dissemination or use
of this communication is strictly prohibited. If you have received
this transmission in error please notify the sender immediately and
then delete this e-mail. Any part of this e-mail which is purely
personal in nature is not authorised by the City of London. All
e-mail through the City of London's gateway is potentially the
subject of monitoring. All liability for errors and viruses is
excluded. Website: http://www.cityoflondon.gov.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20120413/2adf704e/attachment.htm>
More information about the reportlab-users
mailing list