写入数据:

# -*- coding:utf-8 -*-
import xlwt
workbook = xlwt.Workbook()  # 新建一个工作簿
sheet = workbook.add_sheet("tab")  # 在工作簿中新建一个表格
title=["title1","title2","title3","title4"]
content=["111","222","333","444"]
for i in range(0, 3):  # 行数
    for j in range(0, len(title)):  # 列数
        if i == 0:#第0行为标题行
            sheet.write(0, j, title[j])
        else:
            sheet.write(i , j, content[j])  # 向表格中写入数据
workbook.save("test.xls")  # 保存工作簿

 

读出数据:

# -*- coding:utf-8 -*-
import xlrd

path = u"C:\\读取表格\\表格.xls"#
workbook = xlrd.open_workbook(path)
sheet = workbook.sheet_by_index(0)
for row in range(sheet.nrows):
    for col in range(sheet.ncols):
        print(sheet.row(row)[col].value)#按行读取excel

 

相关文章:

  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2021-04-14
  • 2022-12-23
  • 2021-06-19
猜你喜欢
  • 2021-08-18
  • 2021-07-13
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-05-25
相关资源
相似解决方案