Python 用openpyxl库从excel表格中获取内容(实例)
2023-09-14 09:01:28 时间
从文件中读取第5列含有‘手机’的行,并输出满足条件的第二、五列数据。
import os
from openpyxl import load_workbook
full_fn = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'exam.xlsx')
wb = load_workbook(full_fn)
sh = wb['Sheet1']
rows = sh.max_row
for i in range(1,rows+1):
i2=cell(row=i,column=2).value
i5=cell(row=i,column=5).value
if i5 is None:
pass
elif u'手机' in i5:
print(i2+'\t'+i5)
wb.close()
注: sh = wb['Sheet1'] 已替代之前的老版本函数 sh = wb.excel.get_sheet_by_name('Sheet1');尽管它目前还可以工作,但python有"已弃用函数"的警告提示。
相关文章
- python实现矩阵的转置_Python实现矩阵转置的方法分析
- python fileinput_Python之fileinput模块学习「建议收藏」
- python jieba库_Python jieba库的使用说明「建议收藏」
- Python实现XMind测试用例快速转Excel用例
- python表情代码_Python实现表情包的代码实例[通俗易懂]
- lambda python表达式_Python的条件表达式和lambda表达式实例
- python图像识别与提取_图像分类python
- 如何利用python读excel数据_python在excel应用实例
- Python开发 之 Python3读写Excel文件(较全)[通俗易懂]
- 上手Python之模块
- python 爬虫 ip池怎么做,有什么思路?
- python处理Excel实现自动化办公教学(含实战)【一】
- Win10下Python虚拟环境virtualenv安装和使用
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(优化版)
- Python 搭配 C++ 让性能直接拉满
- Python:Excel自动化实践入门篇 乙
- Python的Flask框架使用Redis做数据缓存的配置方法
- 快速安装Excel:Linux用户指南(linux安装excel)
- mssql数据快速转换称Excel格式(mssql转excel)
- Python中使用MySQL数据库的操作技巧(mysql_python)
- Python修改Excel数据的实例代码