I am trying to create a report that will list both the field name and the field alias for every table we have in our geodatabases. I know there is no existing tool that can do this and I have found several python scripts that can do things such as batch edit the alias field but I am just looking to display both fields for each table or a null value in the case of no alias shown. I am working in Arc 10.3.1.
2 Answers
You can use the following Python function below to create an excel spreadsheet report:
import os
from xlwt import Workbook, Borders, Font, XFStyle
import arcpy
def createFieldReport(fc, out_excel):
"""create an excel spreadsheet showing field names and alias
fc -- feature class
out_excel -- output excel spreadsheet (should end in .xls)
"""
if not out_excel.endswith('.xls') and not out_excel.endswith('.xlsx'):
out_excel += '.xls'
wb = Workbook()
ws = wb.add_sheet('Sheet 1')
# width dict, to autofit columns
widths = {0: 11, 1: 12}
# set header styles
fntHeaders = Font()
fntHeaders.bold = True
fntHeaders.height = 220
# write headers
ws.write(0, 0, 'Field_Name')
ws.write(0, 1, 'Field_Alias')
# freeze headers
ws.set_panes_frozen(True)
ws.set_horz_split_pos(1)
# write values
for i,f in enumerate(arcpy.ListFields(fc)):
ws.write(i+1, 0, f.name)
ws.write(i+1, 1, f.aliasName)
# update width if wider than last or default
if len(f.name) > widths[0]:
widths[0] = len(f.name)
if len(f.aliasName) > widths[1]:
widths[1] = len(f.aliasName)
# autofit width (reads width dict in case you add more fields)
for i, w in widths.iteritems():
ws.col(i).width = w * 350
wb.save(out_excel)
return out_excel
if __name__ == '__main__':
fc = r'C:\some_path\togeodatabase\featureclass'
output = r'C:\Temp\test.xls'
createFieldReport(fc, output)
os.startfile(output)
To apply this to an entire geodatabase you could simply iterate through each feature and call the createFieldReport()
on each feature class and create a unique name by grabbing the feature class name.
-
1If this solved your problem please click the green tick Accept button next to it to thank the answerer for their effort.– PolyGeo ♦Commented Jan 21, 2016 at 20:04
X-Ray for ArcGIS will do this, although it may output far more information than you require.
X-Ray for ArcCatalog will help you:
- Develop and refine geodatabase designs
- Analyze the differences between two geodatabase designs
- Merge two different designs in to a new consolidated geodatabase design
- Check for reserved RDBMS field names in your design
- Replace and reorder fields in a current geodatabase (via GP Script)
- Import a design with geoprocessing
- Localize field aliases and descriptions in your geodatabase
- Populate workspace descriptions for your design
- Create a data dictionary and diagram for your design