1、调用Workbook()对象中的add_sheet()方法
1
2
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')
2、通过add_sheet()方法中的write()函数将数据写入到excel中,然后使用save()函数保存excel文件
1
2
3
4
5
6
7
ws.write(0, 0, 1234.56, style0)
ws.write(1, 0, datetime.now(), style1)
ws.write(2, 0, 1)
ws.write(2, 1, 1)
ws.write(2, 2, xlwt.Formula("A3+B3"))
wb.save('example.xls')
完整代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import xlwtfrom datetime import datetime
style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',num_format_str='#,##0.00')
style1 = xlwt.easyxf(num_format_str='D-MMM-YY')
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')
ws.write(0, 0, 1234.56, style0)
ws.write(1, 0, datetime.now(), style1)
ws.write(2, 0, 1)
ws.write(2, 1, 1)
ws.write(2, 2, xlwt.Formula("A3+B3"))
wb.save('example.xls')
程序执行结果如下:
更多Python知识,请关注:Python自学网!!
(推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)
JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式。它基于ECMAScript (欧洲计算机协会制定的js规范)的一个子集,采用完全独立于编程语言的文本格式来存储和表示数据。JSON 是 JS 对象的字符串表示法,它使用文本表示一个 JS 对象的信息,本质是一个字符串。
任何支持的类型都可以通过 JSON 来表示,例如字符串、数字、