Https://github.com/mkleehammer/pyodbc/wiki/Cursorusing PYODBC to read a database, the process is basically the same as when you configure the Connect object, the following is the Excel:default is read-only, if you want to write a sentence, see the last. Import PyodbcStep One: Create a Connect objectstr=r ' d:\work_studio\solarplates\fine_structure_plates_20171221.xlsx '
conn_info= ' Driver={microsoft Excel DRIVER (*.xls, *.xlsx, *.xlsm, *.XLSB)};D bq= ' +str+ '; '
Cnxn=pyodbc.connect (conn_info,autocommit=true)
#读写EXCEL这句一定要加上Step Two: Create a Cursor object
crsr=cnxn.cursor ()Step three: Execute SQL command execute ()sql= ' select * FROM [1988.12.18 (I)
$] '
rows=crsr.execute (SQL)Fourth Step: Output the required informationFor
s in rows:
#这里S就是返回信息中的一条,
print (S. Image number to be scanned)
#根据字段名称输出内容
print (s[0])
#根据索引号输出print (
crsr.description)#这句话是获得 The Frame properties, field names, types, and other information
for this table . Can be seen as a 2-tier tuple structure in which each tuple indicates some information,Gets the information for the table through the cursor object of the linked object.((' need to sweep image number ', <class ' str ';, None, 255, 255, 0, True),(' Time on film ', <class ' str ';, None, 255, 255, 0, True),(' remark ', <class ' str ';, None, 255, 255, 0, True)) Fifth step: Close cursors and linkscrsr.close ()cnxn.close ()
Python-excel Read-pyodbc