-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportToExcel.py
More file actions
43 lines (30 loc) · 1016 Bytes
/
exportToExcel.py
File metadata and controls
43 lines (30 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Importing modules
import arcpy
import xlwt
import pythonaddins
import os
# Selecting the layer and choosing the fields to be exported
inputLayer = arcpy.GetParameterAsText(0)
fieldsName = arcpy.GetParameterAsText(1)
fdList = fieldsName.split(";")
fileName = arcpy.GetParameterAsText(2)
fileLoc = arcpy.GetParameterAsText(3)
fileExtension = '.xls'
# Creating folder
#currDir = os.getcwd()
folderLoc = fileLoc+'\\test'
if os.path.isdir(folderLoc):
arcpy.AddMessage('Exporting data....')
else:
folderLoc = os.chdir(os.mkdir(fileLoc+'\\test'))
book = xlwt.Workbook(encoding ="utf-8")
sheet1=book.add_sheet("Data Source")
cursor = arcpy.da.SearchCursor(inputLayer,fdList)
for k,header in enumerate(fdList):
sheet1.write(0,k,header)
for i,row in enumerate(cursor):
for j,col in enumerate(row):
sheet1.write(int(i)+1,int(j),col)
book.save(folderLoc+'\\'+fileName+fileExtension)