如果設置了本地環境變量,可直接執行
#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()
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
