3

I am unable to generate pdf report using ExportReport function of ArcGIS 10.2. getting error of IOError: Could not open report template

I tried different template files but still getting this error. Template directory is correct. checked all the directory positions.

Code

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Users\Abrar ahmad\Documents\ArcGIS\New_Rwp_Cencus(12-17-2014).mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd, "",df):
if lyr.name == "New_Districts_5_without_limit":
 arcpy.mapping.ExportReport(lyr,r"C:\Users\Abrar ahmad\Documents\ArcGIS\test.rlf",r"C:\Users\Abrar ahmad\Documents\ArcGIS\ProjectReport2.pdf","USE_RLF")
del mxd

Complete Error Data:

Runtime error 
Traceback (most recent call last):
 File "<string>", line 7, in <module>
 File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_
 return fn(*args, **kw)
 File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\mapping.py", line 515, in ExportReport
 return report_source._arc_object.ExportReport(*gp_fixargs((report_layout_file, output_file, dataset_option, report_title, starting_page_number, page_range, report_definition_query, extent, field_map), True))
IOError: Could not open report template
Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Mar 7, 2015 at 16:35
5
  • Does some other process have open or editing 'C:\Users\Abrar ahmad\Documents\ArcGIS\test.rlf'? Commented Mar 7, 2015 at 17:24
  • Or is this about writing rights in windows? Do you have admin rights on your computer? Please elaborate. Commented Mar 7, 2015 at 17:35
  • @ragnvald yes i have admin rights. Commented Mar 7, 2015 at 17:37
  • @RichardMorgan no other process is opened Commented Mar 7, 2015 at 17:37
  • @alinaa Edit your question to incorporate this information. This makes your question "better". Our comments are here to help you give us all a better question :-) Welcome here by the way :-) Commented Mar 7, 2015 at 17:40

1 Answer 1

2

I got it working by error handling. But now its not working on template where definition query is added. Do I need to add definition query in code also?

Code:

import arcpy 
import sys 
import traceback 
mxd = arcpy.mapping.MapDocument(r"C:\Users\Abrar ahmad\Documents\ArcGIS\New_Rwp_Cencus(12-17-2014).mxd") 
try: 
 df = arcpy.mapping.ListDataFrames(mxd)[0] 
 for lyr in arcpy.mapping.ListLayers(mxd, "",df): 
 if lyr.name == "New_Districts_5_without_limit": 
 arcpy.mapping.ExportReport(lyr,r"C:\Users\Abrar ahmad\Documents\ArcGIS\ReportLatest.rlf",r"C:\Users\Abrar ahmad\Documents\ArcGIS\ProjectReport2.pdf","USE_RLF") 
except arcpy.ExecuteError: 
 # Get the tool error messages 
 msgs = arcpy.GetMessages(2) 
 # Return tool error messages for use with a script tool 
 arcpy.AddError(msgs) 
 # Print tool error messages for use in Python/PythonWin 
 print msgs 
except: 
 # Get the traceback object 
 tb = sys.exc_info()[2] 
 tbinfo = traceback.format_tb(tb)[0] 
 # Concatenate information together concerning the error into a message string 
 pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1]) 
 msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n" 
 # Return python error messages for use in script tool or Python Window 
 arcpy.AddError(pymsg) 
 arcpy.AddError(msgs) 
 # Print Python error messages for use in Python / Python Window 
 print pymsg + "\n" 
 print msgs 
finally: 
 del mxd 
Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
answered Mar 7, 2015 at 17:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.