ExcelToTable_conversion -- Table not in Geodatabase

1359
4
Jump to solution
12-13-2013 10:23 AM
JonathanMulder
New Contributor III
Greetings,

I'm running the following code to convert an Excel spreadsheet to a dbf table inside a geodatabase.  But when I look at the geodatabase in ArcCatalog, the geodatabase does not contain the table.  Anty ideas?
CurrentDate = "20130625" OutName = "tempgdb.gdb" InSpreadsheet = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurements_" + CurrentDate + ".XLS" arcpy.ExcelToTable_conversion(InSpreadsheet,OutName)


Actually, my ultimate goal is to import points (Longitude, Latitude, Elevation) from a spreadsheet, but it seems I have to convert the spreadsheet to a table first, right?

Thanks for any help you can provide.

Jon Mulder
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
WilliamCraft
MVP Regular Contributor
So what is your ultimate goal?  To generate and render points inside of ArcMap from your X,Y fields from the spreadsheet? 

In looking at the part of the code you provided, I think the reason no table ever gets created in your geodatabase is because the GP tool doesn't know where "tempgdb.gdb" is located on the file system.  Additionally, you need to specify the NAME of the output table.  Try something like this:

CurrentDate = "20130625"
OutName = "C:\folder_containing_your_source_GDB\tempgdb.gdb\OutputTable"
InSpreadsheet = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurements_" + CurrentDate + ".XLS"
arcpy.ExcelToTable_conversion(InSpreadsheet,OutName, "Sheet1")

Note that I've added an optional parameter to the GP tool above to reflect the Excel sheet name. 

Check your geodatabase after that and see if the table is there.  If so, that explains how to import the XLS into a file geodatabase. 

In terms of getting those points to appear on the map, from within ArcMap launch ArcToolbox and navigate to the Make XY Event Layer (Data Management) tool under Data Management.  Follow the directions from the help topic below to generate the points from your latitude and longitude fields once you point the tool to the new table in your file geodatabase from above. 

http://resources.arcgis.com/en/help/main/10.2/index.html#//00170000006z000000

View solution in original post

0 Kudos
4 Replies
RobertBorchert
Frequent Contributor III
Geodatabases contain Info Tables. 

you can export to a .dbf
0 Kudos
WilliamCraft
MVP Regular Contributor
So what is your ultimate goal?  To generate and render points inside of ArcMap from your X,Y fields from the spreadsheet? 

In looking at the part of the code you provided, I think the reason no table ever gets created in your geodatabase is because the GP tool doesn't know where "tempgdb.gdb" is located on the file system.  Additionally, you need to specify the NAME of the output table.  Try something like this:

CurrentDate = "20130625"
OutName = "C:\folder_containing_your_source_GDB\tempgdb.gdb\OutputTable"
InSpreadsheet = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurements_" + CurrentDate + ".XLS"
arcpy.ExcelToTable_conversion(InSpreadsheet,OutName, "Sheet1")

Note that I've added an optional parameter to the GP tool above to reflect the Excel sheet name. 

Check your geodatabase after that and see if the table is there.  If so, that explains how to import the XLS into a file geodatabase. 

In terms of getting those points to appear on the map, from within ArcMap launch ArcToolbox and navigate to the Make XY Event Layer (Data Management) tool under Data Management.  Follow the directions from the help topic below to generate the points from your latitude and longitude fields once you point the tool to the new table in your file geodatabase from above. 

http://resources.arcgis.com/en/help/main/10.2/index.html#//00170000006z000000
0 Kudos
JonathanMulder
New Contributor III
Thanks very much for your suggestions.  I've modified the code, and now it works.

Also, I had thought that the geoprocessor knew where the table was because I define the workspace as that directory.

Off to the next step!  Much appreciated!

Jon Mulder

# Set the workspace.
env.workspace = "G:\Documents\GIS\HydstraData"
arcpy.env.overwriteOutput = True

## Set the Spatial Reference.
Spatial_Reference = "PROJCS['NAD_1983_California_Teale_Albers',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Albers'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',-4000000.0],PARAMETER['Central_Meridian',-120.0],PARAMETER['Standard_Parallel_1',34.0],PARAMETER['Standard_Parallel_2',40.5],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]"

OutFolderPath = env.workspace
OutName = "tempgdb.gdb"
##Check if geodatabase exists.
if arcpy.Exists(OutName):
    ##Delete geodatabase.
    arcpy.Delete_management(OutName)
##Create geodatabase.    
arcpy.CreateFileGDB_management(OutFolderPath,OutName)

DateStart = date(2013,6,25)
DateEnd = date(2013,6,26)
for dt in rrule(DAILY, dtstart=DateStart, until=DateEnd):
    CurrentDate = dt.strftime("%Y%m%d")
    print CurrentDate
    ##Create Point Shapefile from spreadsheet.
    InSpreadsheet = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurements_" + CurrentDate + ".XLS"
    X_Coords = "Longitude"
    Y_Coords = "Latitude"
    Z_Coords = "MeanData"
    Out_Layer = "Data_" + CurrentDate
    OutTableName = os.path.join(OutFolderPath,OutName,"Data_" + CurrentDate)
    print OutTableName
    arcpy.ExcelToTable_conversion(InSpreadsheet,OutTableName)
print "Completed."


Results:
20130625
G:\Documents\GIS\HydstraData\tempgdb.gdb\Data_20130625
20130626
G:\Documents\GIS\HydstraData\tempgdb.gdb\Data_20130626
Completed.
0 Kudos
WilliamCraft
MVP Regular Contributor
Glad it worked for you.  Please mark the correct answer; it will also help others with similar issues.
0 Kudos