python如何创建excel文件_python创建Excel文件数据的方法

# -*- 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‘)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值