Read Excel files from Python[转]
2023-09-14 08:59:42 时间
http://scienceoss.com/read-excel-files-from-python/
Use the excellent xlrd package, which works on any platform. That means you can read Excel files from Python in Linux! Example usage:
Open the workbook
import xlrd wb = xlrd.open_workbook(myworkbook.xls)
Check the sheet names
wb.sheet_names()
Get the first sheet either by index or by name
sh = wb.sheet_by_index(0) sh = wb.sheet_by_name(uSheet1)
Iterate through rows, returning each as a list that you can index:
for rownum in range(sh.nrows): print sh.row_values(rownum)
If you just want the first column:
first_column = sh.col_values(0)
Index individual cells:
cell_A1 = sh.cell(0,0).value cell_C4 = sh.cell(rowx=3,colx=2).value
(Note Python indices start at zero but Excel starts at one)
Turns out the put_cell() method isn’t supported, so ignore the following section (Thanks for the heads up, John!)
Put something in the cell:
row = 0 col = 0 ctype = 1 # see below value = asdf xf = 0 # extended formatting (use 0 to use default) sh.put_cell(row, col, ctype, value, xf) sh.cell(0,0) # text:uasdf sh.cell(0,0).value # asdf
Possible ctypes: 0 = empty, 1 = string, 2 = number, 3 = date, 4 = boolean, 5 = error
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!相关文章
- pycharm导入Python_python简单项目
- Python爬虫之数据写入
- ipad写python代码用什么软件_iPad 能用来写代码吗?有哪些必备软件推荐?[通俗易懂]
- 苹果电脑python官网下载步骤-Python下载和安装图文教程[超详细]
- 【python】Excel转json「建议收藏」
- python教程:用简单的Python编写Web应用程序
- Anaconda:初学Python、入门机器学习的首选
- 【说站】python中mainloop()方法的使用
- 【说站】python如何在二维图像上进行卷积
- 【说站】python生成器的调用理解
- 【说站】python Pool常用函数有哪些
- Python标识符的命名规则,下列哪些是对的?_python标识符不能使用关键字
- Python的特点是什么_python具有的特点
- 关于python中lambda函数的描述_Python全局变量
- Python 生成随机数_python 随机字符串
- 使用Python根据原始Excel表格批量生成目标Excel表格
- Python xlwt数据保存到 Excel中以及xlrd读取excel文件画图
- python-Python与SQLite数据库-SQLite数据库的基本知识(一)
- python-Python与SQLite数据库-SQLite数据库的基本知识(二)
- python-Python与MongoDB数据库-处理MongoDB查询结果
- python学习之旅详解编程语言
- 使用POI生成Excel文件,可以自动调整excel列宽详解编程语言
- 使用Python编程连接MySQL数据库(python连mysql)
- Python输出函数print()总结(python print())详解编程语言
- python学习Linux、Python,体验自由的乐趣(lexlinux)
- 极速提升业务效率:利用Excel快速导入Oracle数据库(excel数据导入oracle)
- Python实现MySQL数据库的读取(python读取mysql)
- 如何将Excel数据导入MySQL数据库学习MySQL中Excel的基本用法(mysql中excel)
- Excel与Oracle精准大数据统计分析利器(excel和oracle)
- 用Python写的图片蜘蛛人代码
- python创建和使用字典实例详解
- python基础教程之循环介绍