一、读取excel中内容
1.导入模块 : from openpyxl import load_workbook
2.打开excel : workbook = load_workbook("python12.xlsx")
3.定位表单: sheet = workbook[‘Sheet1‘]
5.读取第4行第5列的数据:data1 = sheet.cell(4, 5).value
6. 获取最大行: max_row = sheet.max_row
7.获取最大列:max_col = sheet.max_col
8.写数据到第4行第3列:sheet.cell(4,3).value = "New data"
9.第8条改完数据后,一定要保存到工作簿:workbook.save("python12.xlsx")
(保存数据的时候,一定要确保xlsx表是处于关闭状态的,否则会运行出错)
二、通过workbook新建excel表
1.导入模块 :from openpyxl import Workbook
2.创建工作簿:workbook = Workbook()
3.通过workbook创建表格:workbook.save("python13.xlsx")
原文地址:https://www.cnblogs.com/kulankadamei/p/10087938.html
时间: 2024-10-08 09:29:13