python按需生成固定数量电话号码并保存为excel(不重复)
如果设置了本地环境变量,可直接执行
#coding=utf-8 # -*- coding: utf-8 -*- import xlwt import random numList = [] #设置表格样式 def set_style(name,height,bold=False): style = xlwt.XFStyle() font = xlwt.Font() font.name = name font.bold = bold font.color_index = 4 font.height = height style.font = font return style def generatorNum(): list = ['139', '188', '185', '136', '155', '135', '158', '151', '152', '153'] str = '0123456789' for i in range(2000): #在这里改所需数量 global numList numList.append(random.choice(list) + "".join(random.choice(str) for i in range(8))) #写Excel def write_excel(): f = xlwt.Workbook() sheet1 = f.add_sheet('number',cell_overwrite_ok=True) row0 = ["number"] global numList print(numList) colum0 = numList #写第一行 for i in range(0,len(row0)): sheet1.write(0,i,row0[i],set_style('Times New Roman',220,True)) #写第一列 for i in range(0,len(colum0)): sheet1.write(i+1,0,colum0[i],set_style('Times New Roman',220,True)) f.save('test.xls') if __name__ == '__main__': generatorNum() write_excel()
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20