当前位置:   article > 正文

python电子表格类_python 操作excel表格

python中% (j, excel[i][j])

Python 操作excel 表格

#coding=utf-8

import xlsxwriter

#1.创建excel 对象

work = xlsxwriter.Workbook('hello.xlsk')#在当前目录下创建一个Excel文件

#2. 创建表格

worksheet = work.add_worksheet('int')

#3.写入内容

title_index = ["A","B","C","D","E","F"]

title = ["int","for","while","range","mk","二狗".decode("utf-8")]

data = [18,19,20,21,17,26]

#创建一个格式

b = work.add_format({"blod":True})

for i,j in enumerate(title_index)

point = "%s%s"%(j,1)

content = title[i]

worksheet.write(point,content,b)

for i,j in enumerate(title_index):

point = "%s%s"%(j,2)

content = data[i]

worksheet.write(point,content)

#数据统计

worksheet.write("G2","=SUM(A2:F2)")

#把数据在Excel表中生成图表

chart = work.add_chart({"type":"column"})#创建一个柱状图

#column 柱状图

#area 面积图

#bar 条形图

# line 折线图

# radar 雷达图

chart.add_series(

{

"categories":"=int!$A$1:$F$1",#类别标签的范围

"values":"=int!$A$2:$F$2",#图标数据的范围

"line":{"color":"red"}#图标线条的属性

})

worksheet.insert_chart("A4",chart)

#关闭并且保存操作

work.close()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/147674
推荐阅读
相关标签
  

闽ICP备14008679号