xlrd详解

简介: xlrd详解
# pip install xlrd==1.2.0
"""
    1.高版本的包不支持xlsx格式的文件,
    2.如果想操作xlsx请安装低版本的包
    这边 索引是从0开始的
"""

import xlrd

xls_file_src = "xls_demo.xls"
xlsx_file_src = "xlsx_demo.xlsx"


#############获取sheet名字###############
def get_sheet_names():
    wb = xlrd.open_workbook(xls_file_src)
    sheet_names = wb.sheet_names()
    print(sheet_names)
    
    
############最大值###############
def get_max_index():
    wb = xlrd.open_workbook(xlsx_file_src)
    sheeet_names = wb.sheet_names()
    for sheet_name in sheeet_names:
        sheet_obj = wb.sheet_by_name(sheet_name)
        max_rows = sheet_obj.nrows
        max_cols = sheet_obj.ncols
        print(f"sheet_name = {sheet_name} max_rows={max_rows} max_cols={max_cols}")
        
        
############获取所有的值###############
def get_cell_value():
    wb = xlrd.open_workbook(xlsx_file_src)
    sheeet_names = wb.sheet_names()
    for sheet_name in sheeet_names:
        sheet_obj = wb.sheet_by_name(sheet_name)
        max_rows = sheet_obj.nrows
        max_cols = sheet_obj.ncols
        for row_index in range(max_rows):
            for col_index in range(max_cols):
                value = sheet_obj.cell_value(row_index, col_index)
                print(value)


相关文章
|
IDE PyTorch 网络安全
|
关系型数据库 MySQL Shell
Docker从入门到精通——MySQL数据持久化
Docker从入门到精通——MySQL数据持久化
942 0
|
2月前
|
自然语言处理 开发者
拿下30个第1名的腾讯混元翻译模型,开源!
腾讯混元又带来一个在国际机器翻译比赛拿下30个第1名的翻译模型Hunyuan-MT-7B,它总参数量仅7B,支持33个语种、5种民汉语言/方言互译,是一个能力全面的轻量级翻译模型。
410 0
|
项目管理 开发工具 git
git push 报错 pre-receive hook declined
git push 报错 pre-receive hook declined
5313 0
git push 报错 pre-receive hook declined
|
10月前
|
存储 移动开发 程序员
alist对接钉钉sso登录
本文介绍了如何将Alist与钉钉SSO登录对接。Alist是一个基于Go语言开发的文件管理程序,支持多平台和多种存储方式。通过设置自定义头部、配置钉钉开放平台应用及回调参数,并获取Client ID和Client Secret,可实现钉钉SSO登录功能。最后根据需求配置用户权限,默认权限值可通过相加不同权限数字获得。成品展示了一个美观且实用的文件管理系统。
alist对接钉钉sso登录
|
区块链
C 标准库 - <locale.h>详解
`&lt;locale.h&gt;` 是 C 标准库中的头文件,用于处理地域设置(locale),影响程序的行为,如数字、货币和日期格式化。重要类型包括 `locale_t`;宏有 `LC_ALL`、`LC_COLLATE` 等;主要函数包括 `setlocale`、`newlocale`、`frelocale`、`duplocale`、`strcoll` 和 `mblen`。
389 12
|
算法 数据挖掘 机器人
【路径规划】基于RRT算法和改进人工势场法的无人机任务规划方法研究(Python代码实现)
【路径规划】基于RRT算法和改进人工势场法的无人机任务规划方法研究(Python代码实现)
660 0
|
存储 监控 关系型数据库
PostgreSQL的备份策略是什么?
【8月更文挑战第4天】PostgreSQL的备份策略是什么?
208 7
|
数据挖掘 Python
【Python】已解决 ImportError: Missing optional dependency ‘xlrd‘. Install xlrd >= 1.0.0 for Excel support
【Python】已解决 ImportError: Missing optional dependency ‘xlrd‘. Install xlrd >= 1.0.0 for Excel support
2041 0
|
机器学习/深度学习 TensorFlow 算法框架/工具
使用Python实现深度学习模型:跨平台模型移植与部署
【7月更文挑战第10天】 使用Python实现深度学习模型:跨平台模型移植与部署
847 1