前言
利用python读取 xls,xlsx,csv,doc,docx,pdf 格式的文件
python版本3.10.4
读取xls
pip install xlrd==2.0.1
wps的.et文件也可以读取
import xlrd
wb = xlrd.open_workbook(path)
# 获取所有工作表
for index,value in enumerate(wb.sheet_names()):
sheet = wb[index]
# 获取工作表总行数
rows = sheet.nrows
# 获取工作表总列数
cols = sheet.ncols
# 总行,总列
# 获取某一单元格内容(行, 列),列表从0开始r
for r in range(0, rows):
for c in range(0, cols):
if sheet.cell(r, c).value:
print(sheet.cell(r, c).value)
读取xlsx
pip install openpyxl==3.1.1
import openpyxl
# 获取工作簿对象
wb = openpyxl.load_workbook(path)
# 获取所有工作表
for index,value in enumerate(wb.sheetnames):
sheet = wb[wb.sheetnames[index]]
# 获取工作表总行数
rows = sheet.max_row
# 获取工作表总列数
co

本文介绍了使用Python3.10.4读取不同格式文件的方法,包括xlrd和openpyxl处理xls/xlsx,docx模块读取docx,转换后读取doc,以及pdfplumber处理pdf,还涉及csv读取。此外,提到了前端和Spring框架的相关技术。

3595

被折叠的 条评论
为什么被折叠?



