-3

I have a file geodatabase from esri (gdb) and I would like to extract or export all domains with all values into a xls sheet. I don't know if this is possible. My python knowledge is dumbed. I would be really happy if somebody could help me.

Thank you for your answer, I tried it, but it gave me an error back.

ValueError Tracebck (most recent call last) In [2]: Line 13: worksheet.cell(target_row + idx, target_column).value = domain

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\openpyxl\cell\cell.py, in value: Line 215: self._bind_value(value)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\openpyxl\cell\cell.py, in _bind_value: Line 184: raise ValueError("Cannot convert {0!r} to Excel".format(value))

ValueError: Cannot convert <Workspace Domain object object at 0x000002782AC64C90> to Excel

2 Answers2

0

This uses the arcpy library to read the domains from your file and openpyxl to write the sheet.

You will need these two Python libraries installed. (I'm assuming you mean xlsx not the older xls btw):

import arcpy
import openpyxl

domains = arcpy.da.ListDomains("YourFile.gdb")
dest_filename = 'output.xlsx'
target_row = 1
target_column = 1
workbook = openpyxl.Workbook()
worksheet = workbook.active
for idx, domain in enumerate(domains):
    worksheet.cell(target_row + idx, target_column).value = domain.name
workbook.save(filename=dest_filename)
Crapicus
  • 214
  • 2
  • 9
0

See the edit to my original answer...

The line starting worksheet.cell(target_row + idx, target_column).value = domain needs .name on the end.

UPDATE:

Duplicate the line with .name on the end for each property of the domain you want in a new column !! Making sure you add +1 then +2 etc to target_column for each property. Then change .name to fields mentioned in this list describing the domain object:

https://pro.arcgis.com/en/pro-app/2.8/arcpy/data-access/domain.htm

E.g.

worksheet.cell(target_row + idx, target_column + 1).value = domain.domainType
worksheet.cell(target_row + idx, target_column + 2).value = domain.description

They will just work.

You will only be able to use the properties marked as String though unless you are prepared to convert the others data types to strings correctly and add them in the same way.

To do that you will need to learn about converting data types in Python like dictionaries etc. to strings.

I've got you 90% of the way - got data from your file into a spreadsheet which is a solid foundation for you to complete your task.

Crapicus
  • 214
  • 2
  • 9
  • the excel got written but it consist just of one column, where all domain names get written down in each row. but the values are not included. – Fabian Zentner Aug 20 '22 at 10:32