python导出excel,随机生成姓名、手机号
朋友想要个随机手机号的excel,python写法比java简单些
不多说 直接上代码
import xlwt
import random
from datetime import datetime
style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on', num_format_str='#,##0.00')
style1 = xlwt.easyxf(num_format_str='D-MMM-YY')
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')
ws.write(0, 0, "姓名", style0)
ws.write(0, 1, "国家", style0)
ws.write(0, 2, "手机号", style0)
ws.write(0, 3, "单位", style0)
for i in range(1, 10000, 1):
xing = '赵钱孙李周吴郑王金木水火土石天地日月星光江河湖海田泉风霜雨雪雷电山岭崖谷丘岩云雾浪'
ming = '人间四月芳菲尽山寺桃花始胜开金木水火土石天地日月星光江河湖海田泉风霜雨雪雷电山岭崖谷丘岩云雾浪'
x = random.choice(xing)
m = "".join(random.choice(ming) for i in range(1, 3))
name = x + m
prelist = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "147", "150", "151", "152",
"153", "155", "156", "157", "158", "159", "186", "187", "188"]
randomPre = random.choice(prelist)
Number = "".join(random.choice("0123456789") for i in range(8))
phoneNum = randomPre +Number
ws.write(i, 0, name)
ws.write(i, 1, "中国大陆")
ws.write(i, 2, phoneNum)
ws.write(i, 3, "测试单位")
else:
print("循环结束")
wb.save('E:\myPythonProject\example.xls')
导出效果
天蓝999: 可以的,我看的另一篇,我面试时90%以上的题目在下边这个博客里:https://knife.blog.csdn.net/article/details/121219272
CV大法: 您好,能不能麻烦您提供一下完整的代码
ppblue248: 可以用,谢谢
x渔: 👍🏻👍🏻👍🏻👍🏻
风吹过雲海: 无语茄,找了一个小时!