TableToExcel - Loop

4329
28
06-13-2017 01:24 PM
DougHaller1
New Contributor III

Hi GeoNet and thanks in advance. I'm new to Python. 

My goal is to write a script that converts all the shapefiles in a gdb into a csv (although I will take an Excel spreadsheet, too).  I plan to convert the final program into a script tool with parameters for which gdb to access and where to save the spreadsheets. I can get a single shapefile to convert into an Excel spreadsheet. I would like to loop through the gdb and convert each shapefile to a unique csv (for this case, let's assume that the gdb contains only shapefiles).

My code fails and I have received a couple of different error messages depending on the variable I use for the in_table argument (hope I have that right).  

I suspect that I am not correctly naming my in_table and out_xls variables.

Here's a screen shot of my code. Sorry for the small size, not sure how to enlarge the text.

tabletoexcel loop

Tags (2)
0 Kudos
28 Replies
curtvprice
MVP Esteemed Contributor

What is getOutput?

.getOutput is a method called on a result object. This is the most direct way to get the result value from GetCount (or any other tool that returns a result.) The result is a string, so that's why he wrapped it with int() -- to convert '45' to 45 for a count of 45 rows.

FC_Basson
MVP Regular Contributor

Yes just change the workspace and output folder on your side.

0 Kudos
DougHaller1
New Contributor III

Thanks FC.

Question:

This part of your code (below) looks like a parameter in a script tool. Do I need to create a script tool and designate this as a parameter? If so, I think it should be an output. What data type is it considered.  Thanks again.

.getOutput(0))

0 Kudos
BlakeTerhune
MVP Regular Contributor

Curtis Price‌ already answered this for you above...

.getOutput is a method called on a result object. This is the most direct way to get the result value from GetCount (or any other tool that returns a result.) The result is a string, so that's why he wrapped it with int() -- to convert '45' to 45 for a count of 45 rows.
DougHaller1
New Contributor III

Thanks for the reminder.

0 Kudos
DougHaller1
New Contributor III

Thanks FC!

Your code works for me. I need to take it a few steps further to create a script tool for my specific needs.  Much appreciated.

0 Kudos
BlakeTerhune
MVP Regular Contributor

Glad you found a solution! Don't forget to Mark a reply as the Correct Answer.

0 Kudos
curtvprice
MVP Esteemed Contributor
Excel files are limited to 65535 rows:

This is true for .xls format, but not .xlsx.

Understanding how to use Microsoft Excel files in ArcGIS—Help | ArcGIS Desktop 

0 Kudos
DougHaller1
New Contributor III

THANKS ALL. I will review each of the replies in detail and try each suggestion.

Doug

0 Kudos