运行环境:
1.Python2.7
2.xlwt、xlrd python 开发包(pip install 安装即可)
代码如下:
#!/usr/bin/env python
#_coding:utf-8 _
import os
import db_connect_chenjie
import xlwt,xlrd
from xlutils.copy import copy
import sys
reload(sys)
sys.setdefaultencoding(‘utf8’)
os.environ[‘NLS_LANG’]=‘SIMPLIFIED CHINESE_CHINA.UTF8’
读取Excel函数如下所示:其中filename:为需要读取文件的文件名,flag代表读取文件中第几个Sheet文件。
def read_excel(filename,flag):
excel_value=[]
data = xlrd.open_workbook(filename)
table=data.sheet_by_index(int(flag))
nrows = table.nrows
for i in range(nrows):
if i != 0:
table_clos0 = table.row_values(i)[0]
excel_value.append(table_clos0)
else:
continue
return excel_value
下面函数为更新Excel文件的函数,其中filename:需要更新的Excel文件,flag:表示第几个Sheet 文件,Para