import xlrd
from xlutils.copy import copy
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def read_whitelist():
whitelist = {}
with open('data/white_organizations.txt','r') as f:
for l in f.readlines():
whitelist[l.strip()]=1
f.close()
show_whitelist(whitelist)
return whitelist
def show_whitelist(whitelist):
print '-------白名单开始-------'
for k in whitelist.keys():
print k
print '-------白名单结束-------'
def excel_read_test():
data_rb = xlrd.open_workbook('data\\test.xlsx')
data_wb = copy(data_rb)
table = data_rb.sheets()[0]
nrows = table.nrows
ncols = table.ncols
sheet_wb = data_wb.get_sheet(0)
whitelist = read_whitelist()
for i in range(1,nrows):
org_name = str(table.cell(i,6).value).strip()
if whitelist.has_key(org_name):
sheet_wb.write(i,8,1)
else:
sheet_wb.write(i,8,0)
data_wb.save("data\\result.xls")
def show_organization(table):
nrows = table.nrows
ncols = table.ncols
for i in range(1,nrows):
print str(table.cell(i,6).value).strip()
def write_cell(table):
data_rb = xlrd.open_workbook('data\\test.xlsx')
data_wb = copy(data_rb)
sheet_wb = data_wb.get_sheet(0)
sheet_wb.write(4,4,1)
print '写入完成'
data_wb.save("data\\result.xls")
def mulu():
with open('data/mulu_white.txt','w') as fw:
with open('data/mulu.txt','r') as f:
for l in f.readlines():
print l.split('\t')[1].strip()
fw.write(l.split('\t')[1].strip()+'\n')
if __name__ == '__main__':
excel_read_test()