Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using python scripts on ArcGIS 10.2 to read excel files with information and put this results on attribute tables of the ArcGIS.

I know how to create a table, add rows, add fields and send information to tables.

from arcpy import env env.workspace = "F:Tr/Model/Results" output="Tr/Model/Results" arcpy.CreateTable_management(output, "ger_rea.dbf")

Create fields

arcpy.env.workspace = "F:Tr\Model\Results" arcpy.AddField_management("ger_rea.dbf", "Barr", "Text", 50, "", "", "refcode", "NULLABLE", "REQUIRED") arcpy.AddField_management("ger_rea.dbf", "Ge_1", "Float", "", "", 10, "", "NON_NULLABLE", "NON_REQUIRED", "") arcpy.AddField_management("ger_rea.dbf", "Ge_2", "Float", "", "", 10, "", "NON_NULLABLE", "NON_REQUIRED", "")

table_ge_rea="F:Tr\Model\Results\ger_rea.dbf"

Add rows

rows_pa = arcpy.InsertCursor("F:Tr\Model\Results\ger_rea.dbf") for x in range(1, (L_Nod_name_LA+1)): row = rows_pa.newRow() rows_pa.insertRow(row)

Put information on created table

gr=0 with arcpy.da.UpdateCursor(table_ge_rea,["Barr","OID"]) as cursor: for row in cursor: row[0]=Nod_name_GA[gr] row[1]=Act_L_value[ga] cursor.updateRow(row) gr=gr+1

However I need to create an automatically tool and The number os rows and fields of the excel tables can change and consequently tables that I'm creating with arcpy need to change too. For example: where I had a table with fields "Barr", "Ge_1", "Ge_2" I can have "Barr", "Ge_1", "Ge_2", "Ge_3", "Ge_4", etc...

How can I create a table (with arcpy) automatically, knowing the number of fields and rows (information on excel that I know how to read), using a for or while loop?

Thank's!!

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.