ArcMap 中的 运行 ExportReport Python 代码出错

Getting error in running ExportReport Python code in ArcMap

我无法使用 Arcgis 10.2 的 ExportReport 功能生成 pdf 报告。收到 IOError 错误:无法打开报告模板

尝试了不同的模板文件,但仍然出现此错误。 模板目录正确。检查了所有目录位置。

代码

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

完整的错误数据:

运行时错误 追溯(最近一次通话): 文件“”,第 7 行,位于 文件 "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\utils.py",第 181 行,在 fn_ 中 return fn(*args, **kw) ExportReport 中的文件 "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\mapping.py",第 515 行 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, 范围, field_map), True)) IOError:无法打开报告模板

在 try/except/finally 中执行你的代码,看看这是否给出了一些提示:

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\test.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