python3 excel文件的读与写
2024-10-18 22:27:23
from openpyxl import load_workbook
class RwExcelFile: def read_Excel(self,file_path):
'''
读取excel中所有数据并以列表形式返回
:param file_path:
:return:
'''
excel_File = load_workbook(file_path)
sheet_names = excel_File.sheetnames
list_column = []
list_row = []
list_sheet = []
for i in sheet_names:
excel_File_sheet=excel_File[i]
for j in range(1,excel_File_sheet.max_row+1):
for k in range(1,excel_File_sheet.max_column+1):
list_column.append(excel_File_sheet.cell(j,k).value)
list_row.append(list_column)
list_column = []
list_sheet.append(list_row)
list_row = []
excel_File.close()
return list_sheet def write_Excel(self,file_path,sheetname,row,cloumn,T_value):
'''
向excel指定位置写入值
:param file_path: 文件地址
:param sheetname: sheet名
:param row: 行
:param cloumn:列
:param T_value: 值
:return: 无返回
'''
excel_File = load_workbook(file_path)
excel_File[sheetname].cell(row,cloumn,T_value)
excel_File.save(file_path)
excel_File.close()
最新文章
- tomcat 远程调试
- 支付宝即时到账API,网站收到回调页面,输出验证失败,log中responseTxt=错误的问题
- Anywhere服务建立及连接步骤
- 用 Docker 快速配置前端开发环境
- Android 开发技巧
- C#多线程问题整合
- iOS校验身份证是否合法
- 深刻理解iosBlock
- 02_3中方式的反射,通过Class.forName获得Class对象,通过类.class获得字节码对象,通过类实例.getClass()的方式获得Class对象
- [CC-BSTRLCP]Count Binary Strings
- javaMail实现收发邮件(一)
- 有向连通图增加多少边构成强联通(hdu3836,poj1236)
- FastAdmin 环境变量 env 配置
- HDU 4762 Cut the Cake(高精度)
- LINUX 查找替换命令 总结
- 反编译示例:mxd检查
- zabbix自定义key监控redis
- webpack中多模块依赖
- Node-sqlite3多字段插入数据问题
- 基于flask做权限控制