0

I have a script that converts an ESRI feature class attribute table to an excel file. Problem is it adds an object ID field in the process. This screws up the file for an upload to a database using a .dtt app that references a set array. Therefore I need the script to read the output excel file and add everything to a new excel file without the first column. Everything leading up to the xlrd and xlwt functions is working fine so I will exclude everything prior to the Table to excel conversion:

arcpy.TableToExcel_conversion(outTemplate, outXL)
print "arcpy.AddMessage(Creating GoLive_+glName)"

workbook = xlrd.open_workbook(outXL)
writeBook = r"S:Upload\SVRSTA00.xls"

sheet = workbook.sheet_by_index(0)

cell_range_value = 0
for value in sheet.col(32):
    cell_range_value += 1
print cell_range_value

dct1 = {}
for i in range(1, cell_range_value,1):
    data = [sheet.cell_value(i, col) for col in range(sheet.ncols)[1:]]
    cell_value_class = sheet.cell(i,32).value
    cell_value_id = data
    dct1[cell_value_class] = cell_value_id

print 

workbook = xlwt.Workbook()
sheet = workbook.add_sheet('SVRSTA00')

for index, value in enumerate(dct1):
    sheet.write(0, index, value)

workbook.save(writeBook)

This is the error I'm getting:

ValueError: column index (u'181011020') not an int in range(256)

1 Answer 1

1

Excel supports until 256 columns, pay attention in the value (from 0 to 255) of the column.

You could use openpyxl, it's more flexible and helpful

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.