作用:用于操作Excel

代码示例

#!/usr/bin/python3
# -*- coding: UTF-8 -*-
# 保存数据到Excel

import xlwt

workbook = xlwt.Workbook(encoding="utf-8")  #创建workbook 对象
worksheet = workbook.add_sheet("sheet1")    # 创建工作区

# 写入数据

worksheet.write(0,0,"hello")    # 第一个参数是行,第二个参数是列。第三个参数是内容
workbook.save('test.xls')

### 写个九九乘法表

```python
import xlwt

workbook = xlwt.Workbook(encoding="utf-8")  #创建wookbook 对象
worksheet = workbook.add_sheet("九九乘法表")    # 创建工作区

# 写个九九乘法表

for row in range(0,9):  # 行

    for col in range(0,row+1):   # 列
      
        worksheet.write(row,col,"%d * %d = %d"%(col+1,row+1,(col+1)*(row+1)))

workbook.save('test2.xls')