沒啥說的,直接上代碼。。。
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import xlwt
import time
import random
book = xlwt.Workbook(encoding='utf-8')
sheet = book.add_sheet('sheet1', cell_overwrite_ok=True)
row_col_list = [9, 10]
def set_title():
title_kwgs = {
"colnum1": "colnum1_name", "colnum2": "colnum2_name", "colnum3": "colnum3_name",
"colnum4": "colnum4_name", "colnum5": "colnum5_name",
"colnum6": "colnum6_name", "colnum7": "colnum7_name", "colnum8": "colnum8_name",
"colnum9": "colnum9_name", "colnum10": "colnum10_name"
}
for i in range(1):
for j in range(row_col_list[1]):
sheet.write(i, j, title_kwgs["colnum%s" % str(j + 1)])
def excel_data_generator():
col_kwgs = {
"colnum1":"colnum1_value", "colnum2":"colnum2_value", "colnum3":"colnum3_value",
"colnum4":"colnum4_value", "colnum5":"colnum5_value",
"colnum6":"colnum6_value", "colnum7":"colnum7_value", "colnum8":"colnum8_value",
"colnum9":"colnum8_value", "colnum10":"colnum10_value"
}
colnum5_begin = int(str(random.Random.random(random.Random())).replace('0.', ''))
for i in range(1, row_col_list[0] + 1):
for j in range(row_col_list[1]):
if j == 4:
sheet.write(i, j, str(colnum5_begin))
colnum5_begin += 1
else:
sheet.write(i, j, col_kwgs["colnum%s" % str(j + 1)])
book.save("D:\\testdata\\haha\\test%s.xls" % str(time.time()).replace('.', ''))
# time.sleep(1)
# print('function executed!')
if __name__ == '__main__':
for i in range(10):
set_title()
excel_data_generator()
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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