Export layers of a gdb as excel table

3331
22
Jump to solution
02-16-2021 05:06 PM
JoelRodriguez95
New Contributor II

Hello everybody,

I'm new in this world of arcpy and I would like poder export all of layer of a gbd to an excel format, I tried with several this foro's scripts but I can't get the result, this is my script actual but not funcionate.

import arcpy

from arcpy import env

env.workspace = r" C:\Users\LAP77\Desktop\JR\Veg_Hidro_Final.gdb"

output_folder = of = r" C:\Users\LAP77\Desktop\JR\Veg_Hidro_Final\Excel"

for fc in arcpy.ListFeatureClasses("*"):

        fc_name= of+ "\\"+fc+".xls" 

        print(fc_name)

        arcpy.TableToExcel_conversion(fc,fc_name, "NAME", "CODE")

 

0 Kudos
22 Replies
DanPatterson
MVP Esteemed Contributor

try printing the "fc" name as well to make sure it exists and that it is a geodatabase table. 

You just printed the output xls name.


... sort of retired...
0 Kudos
DanPatterson
MVP Esteemed Contributor

spaces in the path.... isn't a path if it is the first character especially

raw encoding won't help for that either


... sort of retired...
0 Kudos
JoelRodriguez95
New Contributor II

Thanks for your time, and I'm sorry for not verified the spaces.

import os
import arcpy
from arcpy import env

env.workspace = r"C:\data.gdb"
output_folder = r"C:\output"

for fc in arcpy.ListFeatureClasses("*"):
    out_xls = os.path.join(output_folder, r'{}.xls'.format(fc))
    env.overwriteOutput = True
    fc_path = os.path.join(env.workspace, fc)
    fc_table_view = arcpy.MakeTableView_management(fc_path, "tview")
    arcpy.TableToExcel_conversion(fc_table_view, out_xls)

 

0 Kudos