STEP1: 导入相关库
import os
from openpyxl import load_workbook
STEP2: 构建存放路径,将上传文件下载到服务器该路径下
excel_stus = request.FILES.get("excel_stus") # 获取文件
path = os.path.join("media","files",excel_stus.name) # 存放操作后的文件
with open(path,"wb") as f:
for line in excel_stus:
f.write(line)
STEP3: 通过python操作excel表格
加载某一个excel文件
wb = load_workbook(path)
# print("wb.sheetnames",wb.sheetnames)
获取sheet对象
worksheet = wb.worksheets[0]
获取单元格内容
for line in work_sheet.iter_rows(min_row=3):
# print("line",line)
# for cell in line:
# print(cell.value)
print(line[索引值].value) # 索引值从 0 开始
标签:stus,openpyxl,表格,excel,print,path,line,wb
From: https://www.cnblogs.com/zylyehuo/p/17527937.html