Python编程-Office操作-操作Excel(中)
例子文件如下:
一些复杂的读取操作
getCells.py
import openpyxl wb = openpyxl.load_workbook('example.xlsx') sheet = wb.get_sheet_by_name('Sheet1') print(sheet.cell(row=1, column=2).value) # from 1 to 8 step is 2 for i in range(1, sheet.max_row + 1, 2): print(i, sheet.cell(row=i, column=2).value) print('------------------------------------------------') # enumerate range cells for rowOfCellObjects in sheet['A1':'C3']: for cellObj in rowOfCellObjects: print(cellObj.coordinate, cellObj.value) print('**************************************') print('------------------------------------------------') # enumerate the whole sheet for i in range(1, sheet.max_row + 1): for j in range(1, sheet.max_column + 1): print(i, sheet.cell(row=i, column=j).coordinate, sheet.cell(row=i, column=j).value) print('**************************************')
运行结果:
Apples
1 Apples
3 Pears
5 Apples
7 Strawberries
------------------------------------------------
A1 2015-04-05 13:34:02
B1 Apples
C1 73
**************************************
A2 2015-04-05 03:41:23
B2 Cherries
C2 85
**************************************
A3 2015-04-06 12:46:51
B3 Pears
C3 14
**************************************
------------------------------------------------
1 A1 2015-04-05 13:34:02
1 B1 Apples
1 C1 73
**************************************
2 A2 2015-04-05 03:41:23
2 B2 Cherries
2 C2 85
**************************************
3 A3 2015-04-06 12:46:51
3 B3 Pears
3 C3 14
**************************************
4 A4 2015-04-08 08:59:43
4 B4 Oranges
4 C4 52
**************************************
5 A5 2015-04-10 02:07:00
5 B5 Apples
5 C5 152
**************************************
6 A6 2015-04-10 18:10:37
6 B6 Bananas
6 C6 23
**************************************
7 A7 2015-04-10 02:40:46
7 B7 Strawberries
7 C7 98
**************************************
相关文章
- Python 日期和时间_python 当前日期时间_python日期格式化
- python: 安装DeOldify库:黑白图片上色(Python 3.7.15)
- 零Python编程基础,如何在10分钟内合并1000个Excel表格?
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(LabelFrame/Checkbutton/Radiobutton)
- Python语言学习:解决python版本升级问题集合(python2系列→Python3系列)导致错误的总结集合
- Python:利用python代码编程实现将视频的avi格式转换为MP4格式
- 100天精通Python(数据分析篇)——第57天:Pandas读写Excel(read_excel、to_excel参数说明+代码实战)
- 【Python自动化办公】批量将Excel表格数据导出为PDF文件
- Python编程:twine模块打包python项目上传pypi
- Python编程:命令行python和python -m的区别
- Python编程:python-attrs模块的简单使用
- python自动化测试学习-Python测试框架之unittest和pytest
- 一篇文章告诉你Python接口自动化测试中读取Text,Excel,Yaml文件的方法
- 【计算机二级Python】模拟试卷第7套选择题
- 前端必备技能知识:JS导出Blob流文件为Excel表格、Vue.js使用Blob的方式实现excel表格的下载(流文件下载)
- python零基础学编程:Python是什么?为什么Python这么火,学Python能干什么?
- Python开发案例之用Python子进程关闭Excel自动化中的弹窗