标签:dom overwrite 方法 range play pycharm char imp 对象
# -*- coding: utf-8 -*-
# @Time : 2018/12/6 17:10
# @Author : suchao
# @Disc: : 生成10000条Excel数据
# @File : 1000data.py
# @Software: PyCharm
import xlrd ,xlwt
import random
"""创建一个excel对象"""
book = xlwt.Workbook(encoding=‘utf-8‘,style_compression=0)
"""创建sheet"""
sheet = book.add_sheet(‘test‘,cell_overwrite_ok=True)
"""添加字段"""
sheet.write(0, 0, ‘编号‘)
sheet.write(0, 1, ‘名称‘)
sheet.write(0, 2, ‘DISPLAY_X‘)
sheet.write(0, 3, ‘DISPLAY_Y‘)
sheet.write(0, 4, ‘销售数量‘)
sheet.write(0, 5, ‘销售单价‘)
sheet.write(0, 6, ‘销售收入‘)
sheet.write(0, 7, ‘单位成本‘)
sheet.write(0, 8, ‘销售成本‘)
sheet.write(0, 9, ‘销售毛利‘)
"""写入编号字段数据"""
for id in range(10000):
sheet.write(id + 1, 0, id)
sheet.write(id + 1, 1, "肯德基餐厅"+str(id))
sheet.write(id + 1, 2, round(random.uniform(3, 52), 2))
sheet.write(id + 1, 3, round(random.uniform(73, 135), 2))
sheet.write(id + 1, 4, round(random.uniform(1, 10001), 2))
sheet.write(id + 1, 5, round(random.uniform(1, 10001), 2))
sheet.write(id + 1, 6, round(random.uniform(1, 10001), 2))
sheet.write(id + 1, 7, round(random.uniform(1, 10001), 2))
sheet.write(id + 1, 8, round(random.uniform(1, 10001), 2))
sheet.write(id + 1, 9, round(random.uniform(1, 10001), 2))
book.save(r‘.\chinaXY.xls‘)
标签:dom overwrite 方法 range play pycharm char imp 对象
原文地址:https://www.cnblogs.com/TestSu/p/10084488.html