1. 假设已经安装带有sliqte 库的Python环境
我的是Python2.5
2. 下载 python xls 写操作包(xlwt)并安装
3. 下面就是代码(db2xls.py):
import sqlite3 as sqlite
from xlwt import *
#MASTER_COLS = ['rowid', 'type','name','tbl_name', 'rootpage','sql']
def sqlite_get_col_names(cur, table):
query = 'select * from %s' % table
cur.execute(query)
return [tuple[0] for tuple in cur.description]
def sqlite_query(cur, table, col = '*', where = ''):
if where != '':
query = 'select %s from %s where %s' % (col, table, where)
else:
query = 'select %s from %s ' % (col, table)
cur.execute(query)
return cur.fetchall()
de