Arcpy Python looping through layers and export to Excels bring back blank excels

706
1
Jump to solution
09-29-2021 05:00 AM
Vag
by
New Contributor

I have an issue here, the code is working but whenever is running the excels coming out blank, if I close the arc and open it back and add only the export code is working if not I constantly see blank excels

Is a kind of bag that, I need to add any code to say before you export save the process I don't know why is happening that

import arcpy

ribbon_list = [
            ['Ribbon A/STR_WRP1_RibbonA_COL_Duct_For_TRR''L0bt_duct_route','L9STR_WRP1_RibbonA_COL_Duct_For_TRR_KN'],
['Ribbon B/STR_WRP1_RibbonB_COL_Duct_For_TRR''L0bt_duct_route','L8STR_WRP1_RibbonB_COL_Duct_For_TRR_KN']
]
for ribbon in ribbon_list:
      field_pairs = [[ribbon[1] + ".duct_stat", ribbon[2] + ".duct_stat"],
               [ribbon[1] + ".duct_cap", ribbon[2] + ".duct_cap"],
               [ribbon[1] + ".sub_inst", ribbon[2] + ".sub_inst"],
               [ribbon[1] + ".de_silt", ribbon[2] + ".de_silt"],
               [ribbon[1] + ".comments", ribbon[2] + ".comments"],
               [ribbon[1] + ".status", ribbon[2] + ".status"]]
fc = ribbon[0]
for field_pair in field_pairs:
          online_field = field_pair[0]
          kn_field = field_pair[1]
          selection_fc = arcpy.management.SelectLayerByAttribute(fc, 'NEW_SELECTION'where_clause=online_field + ' <> ' + kn_field)
arcpy.management.CalculateField(selection_fc, online_field, '!' + kn_field + '!', 'PYTHON3')
print(time.asctime())

#################################################### EXPORTING from Feature Layer to xlsx files #####################################################################

import arcpy

ribbon_layers = [
               ["Ribbon A/STR_WRP1_RibbonA_COL_Duct_For_TRR", "STR_WRP1_RibbonA_COL_Duct_For_TRR.xlsx"],
               ["Ribbon B/STR_WRP1_RibbonB_COL_Duct_For_TRR", "STR_WRP1_RibbonB_COL_Duct_For_TRR.xlsx"],
               ["DFE_Warrenpoint_TRR", "DFE_Warrenpoint_TRR.xlsx"],
               ["Warrepoint Duct Blockage", "Warrepoint Duct Blockage.xlsx"],
]

for ribbon_layer in ribbon_layers:
           layer_name = ribbon_layer[0]
           export_files = ribbon_layer[1]
           arcpy.TableToExcel_conversion(layer_name, export_files, 'ALIAS', 'DESCRIPTION')
print(time.asctime())

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Vag
by
New Contributor

The solution has been found now with clear selection 

current_project = arcpy.mp.ArcGISProject("CURRENT")
maps = current_project.listMaps()
for map_sel in maps:
map_sel.clearSelection()

  

View solution in original post

0 Kudos
1 Reply
Vag
by
New Contributor

The solution has been found now with clear selection 

current_project = arcpy.mp.ArcGISProject("CURRENT")
maps = current_project.listMaps()
for map_sel in maps:
map_sel.clearSelection()

  

0 Kudos