#! /opt/local/bin/python
# -*- coding: GBK -*-
import mysql.connector
import xlrd
import sys
name = sys.argv[1]
matrix = {'f04':'2012BAH13F04.xls',
'f02':'2012BAH13F02.xls'}
filename = matrix[name]
cnx =
mysql.connector.connect(user='root',password='hifi2046',host='localhost',database='bah_db')
cursor = cnx.cursor()
cursor.execute("set NAMES GBK")
f = xlrd.open_workbook(r'/Users/joyce/hifi_np/python/paydesk'
+ '/' + filename)
table = f.sheet_by_index(0)
for i in range(1, table.nrows):
field =
table.row_values(i)
field2 =
[x.encode('gbk') if str(type(x)) == "" else x for x in field]
field1 = ["'" + str(x) +
"'" for x in field2]
cursor.execute("insert
into " + name + " values(''," + ",".join(field1) + ");")
cnx.commit()
cursor.close()
cnx.close()