AnsweredAssumed Answered

openpyxl

Question asked by CCweedcontrol on Jan 10, 2018
Latest reply on Jan 12, 2018 by CCweedcontrol

I have the following script, i am trying to export sql table to an excel file. I have installed  the openpyxl library using. C:\Python27\ArcGISx6410.4\Scripts>pip install openpyxl. everything installed fine. I have the following folders openpyxl & openpyxl-2.4.9.dist-info  in C:\Python27\ArcGIS1040\Lib\site-packages. Any ideas on what i am doing wrong?

 

When i runt he following script i get the error.

 

line 3, in <module>
import openpyxl
ImportError: No module named openpyxl

 

Script

 

import pyodbc
import pandas as pd
import openpyxl

cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=csde18;Trusted_Connection=yes', autocommit=True)

cursor = cnxn.cursor()
script = """
SELECT * FROM dbo.Characteristics
"""

df = pd.read_sql(script, cnxn)

writer = pd.ExcelWriter('C:\\Temp\\Characteristics.xlsx')
df.to_excel(writer, sheet_name='bar')
writer.save()

print 'Done'

Outcomes