2

I used the code:

arcpy.ExcelToTable_conversion(XLSfile, DBFfile)

The data comes across looking fine, but all text fields in the dbf have length of 254. Is there a way, either in the excel file before I export it, or in the dbf after or during the export, to specify the length of that text field to something other than 254?

Things I've figured out so far:
ExcelToTable is pretty good at figuring out which field is which, I don't have any errors where the data came in as the wrong type. The length of the actual data in excel doesn't seem to effect this (unless it is longer than 254 characters, which is another can of worms).

2

When converting xls to DBF table, can I change the length of text fields?

No. Excel does not enforce field lengths or types, so ArcGIS makes some educated guesses. For type it uses the values it finds in the first few fields, and for length it is based on the assumed type. For text fields it sets the length to the max possible length of the field which is 254 characters, to limit truncated values by assuming a shorter field-length.

To force a specific length, you could create a temporary table with your defined field lengths, append your Excel data to that temp table, and then write that temp table out to your DBF file.

From Understanding how to use Microsoft Excel files in ArcGIS

Excel does not enforce field types for values during data entry like standard databases do. Therefore, the field type specified in Excel is not used in determining the field type exposed in ArcGIS. Instead, field type in ArcGIS is determined by a scan of the values in the first eight rows for that field. If the scan finds mixed data types in a single field, that field will be returned as a string field, and the values will be converted to strings.

And from Formatting a table in Microsoft Excel for use in ArcGIS

ArcMap can only read the first 255 characters of a cell. If you have more characters than that, ArcMap converts the field to a BLOB type and you won't be able to read its contents.

  • I believe you, but have you got a source for that information? thanks. – Craig T Apr 8 '17 at 3:50
  • @CraigT Most of it through experience, but I have added a couple of quotes from ArcGIS Desktop help – Midavalo Apr 8 '17 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.