以下代码python2.7可用。#encoding=utf8
#author: walker
#date: 2014-09-16
#function: 获取指定access文件指定表的所哟字段名
import win32com.client
if __name__ == ‘__main__‘:
accessPathFile = r‘D:\tmp\xxx.mdb‘
conn = win32com.client.Dispatch(r‘ADODB.Connection‘)
DSN = ‘PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=‘ + accessPathFile + ‘;‘
conn.Open(DSN)
rs = win32com.client.Dispatch(r‘ADODB.Recordset‘)
rs.Cursorlocation = 3
tableName = ‘xxxx‘
sql = ‘SELECT TOP 1 * FROM ‘ + tableName
print(sql)
rs.Open(sql, conn)
for i in range(0, rs.Fields.Count):
print(rs.Fields[i].Name)
相关阅读:
*** walker * 2014-09-16 ***
原文:http://walkerqt.blog.51cto.com/1310630/1553180