1、读取
import xlrd
from xlrd import xldate_as_tuple
import datetime
data1 = xlrd.open_workbook(r'/Users/zjk/IdeaProjects/test_Python/resource/province/data1.xlsx')
table = data1.sheets()[0]
tables = []
#将excel表格内容导入到tables列表中
def import_excel(excel):
for rown in range(excel.nrows):
array = {'last_province':'','send_pv':'','show_pv':'','show_uv':'','open_pv':'','open_uv':''}
array['last_province'] = table.cell_value(rown,0)
array['send_pv'] = table.cell_value(rown,1)
array['show_pv'] = table.cell_value(rown,2)
array['show_uv'] = table.cell_value(rown,3)
array['open_pv'] = table.cell_value(rown,4)
array['open_uv'] = table.cell_value(rown,5)
tables.append(array)
if __name__ == '__main__':
_path = r'/Users/zjk/IdeaProjects/test_Python/resource/province/aim_province.txt'
with open(_path,'r' ,encoding="utf-8") as file:
pro_list = file.read()
#将excel表格的内容导入到列表中
import_excel(table)
for i in tables:
values = list(i.values())
if (i['last_province'] in pro_list) & (i['last_province'] != '蒙古'):
print(str(values[0])+'t'+str(values[1])[0:-2]+'t'+str(values[2])[0:-2]+'t'+str(values[3])[0:-2]+'t'+str(values[4])[0:-2]+'t'+str(values[5])[0:-2])