python使用xlrd模块可以读取xls和xlsx文件.

import xlrd
import os

file_addr = "E://test.xlsx"
# xlsx文件存在
if os.path.exists(file_addr):
# 读取内容 xls_file
= xlrd.open_workbook(file_addr)
# 取第一个sheet页 xls_sheet
= xls_file.sheets()[0]
# 第一个sheet页的行数和列数 nrows
= int(xls_sheet.nrows) ncols = int(xls_sheet.ncols)
# 读取每一行,一般不读第一行,因为是表头
for now in range(1,nows):
拿到每行的数据,结构是列表,通过索引取每一个字段内容
rows_value = xls_sheet.row_values(row)

 结束!

相关文章:

  • 2022-02-08
  • 2022-01-10
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-08-09
  • 2021-08-04
猜你喜欢
  • 2021-04-16
  • 2021-08-11
  • 2021-12-13
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
相关资源
相似解决方案