I been looking for the code to convert an excel into a csv? I also look in ArcHelp for code that can convert excel into a xy eventbut they require csv. So, if I there no way to convert the code to a csv is there a way to make an excell file into a xy event?
# Import arcpy module import arcpy # Local variables: Sheet1 = "D:\\Book1.xls\\Sheet1$" Output_Location = "D:\\" Sheet1Layer = "Sheet1$Layer" # Process: Make XY Event Layer arcpy.MakeXYEventLayer_management(Sheet1, "Easting", "Northing", Sheet1Layer, "", "")
before the code. So this would be the actual priginally published py code from earlier in this thread, part of the package you downloaded: """ This script will convert a table to a .csv file. It will transfer domain descriptions, rather than just their coded values """ import arcpy import os import csv import domainvalues def export_to_csv(dataset, output, dialect): """Output the data to a CSV file""" # create the output writer out_writer = csv.writer(open(output, 'wb'), dialect=dialect) # return the list of field names and field values header, rows = domainvalues.header_and_iterator(dataset) # write the field names and values to the csv file out_writer.writerow(map(domainvalues._encodeHeader, header)) for row in rows: out_writer.writerow(map(domainvalues._encode, row)) if __name__ == "__main__": # Get parameters dataset_name = arcpy.GetParameterAsText(0) output_file = arcpy.GetParameterAsText(1) delim = arcpy.GetParameterAsText(2).lower() dialect = 'excel' if delim == 'comma': pass else: dialect = 'excel-tab' try: export_to_csv(dataset_name, output_file, dialect) except Exception as err: arcpy.AddError('Error: {0}'.format(err))
There's also a tool to convert between tables, excel and csv. You can add it to a model, or adapt the code in your own scripts, or just use it on it's own. Very handy.
import win32com.client xlApp = win32com.client.Dispatch("Excel.Application") #Open Excel xlWb = xlApp.Workbooks.Open(PATH_TO_WORKBOOK) #Open a workbook - change the path xlApp.ActiveWorkbook.SaveAs(PATH_TO_NEW_CSV_FILE, FileFormat=24) #Save to csv - FileFormat=24 means .csv xlApp.ActiveWorkbook.Close(SaveChanges=0) #Close Workbook xlApp.Quit() #Close Excel
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.