news 2026/3/8 12:13:42

python用openpyxl操作excel-读取sheet中数据

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
python用openpyxl操作excel-读取sheet中数据

python用openpyxl操作excel-读取sheet中数据

import logging import com.pro001.log.pro_log_config as pro_log_config from openpyxl import Workbook, load_workbook from openpyxl.styles import Font, Alignment, Side, PatternFill, Border import os import datetime import random import pandas as pd def excel_read_sheet_data(file_path, sheet_name): """ 读取Excel文件指定sheet内容 """ if not os.path.exists(file_path): logger.error(f'文件{file_path}不存在!') return None wb = load_workbook(file_path) if not wb: logger.error(f'文件{file_path}不存在!') return None if sheet_name not in wb.sheetnames: logger.error(f'文件{file_path}中不存在{sheet_name}工作表!') return None # 获取指定sheet的行数和列数 print('-' * 40, 'read_data_rows', '-' * 40) all_rows = [] ws = load_workbook(file_path, data_only=True)[sheet_name] for row in ws.iter_rows(): data_rows = [cell.value for cell in row] all_rows.append(data_rows) print('rows data:', data_rows) print('all rows data:\n', all_rows) return all_rows def main(): """主函数""" excel_read_sheet_data(r'F:\appData\20251207_211304.xlsx', 'TB01') if __name__ == '__main__': print('-' * 60) main()

读取结果如下:

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/3/7 5:58:29

基于Spring Boot的在线教育平台(源码+lw+部署文档+讲解等)

课题介绍本课题聚焦传统线下教育场景受限、优质教育资源分配不均的痛点,开展基于Spring Boot的在线教育平台的设计与实现工作。系统以Java作为核心开发语言,依托Spring Boot框架搭建轻量高效的后端服务架构,负责处理用户认证、课程管理、在线…

作者头像 李华
网站建设 2026/3/4 8:14:25

基于Python+django的智能停车系统的设计与实现(源码+lw+部署文档+讲解等)

课题介绍本课题聚焦传统停车场管理效率低、车位利用率不足、车主找位难的痛点,开展基于PythonDjango的智能停车系统的设计与实现工作。系统以Python作为核心开发语言,依托Django框架搭建高效稳定的后端服务架构,负责处理车位状态监测、车辆进…

作者头像 李华
网站建设 2026/3/3 15:29:37

基于Python+Django的智能停车管理系统(源码+lw+部署文档+讲解等)

课题介绍本课题聚焦传统停车场管理效率低、车位利用率不足、车主找位难的痛点,设计并开发基于PythonDjango的智能停车管理系统。系统以Python作为核心开发语言,依托Django框架搭建高效稳定的后端服务架构,负责处理车位状态监测、车辆进出管理…

作者头像 李华
网站建设 2026/3/3 20:53:46

代码随想录 1971.寻找图中是否存在路径

方法一&#xff1a;并查集class Solution {private int[] p;public boolean validPath(int n, int[][] edges, int source, int destination) {p new int[n];for(int i 0;i < n;i){p[i] i;}for(int[] e : edges){p[find(e[0])] find(e[1]);}return find(source) find(d…

作者头像 李华
网站建设 2026/3/3 22:04:59

告别等待:CentOS 7.6镜像极速下载方案

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容&#xff1a; 设计一个CentOS 7.6镜像加速下载工具。利用多线程、CDN优选和P2P技术提升下载速度。自动选择最快的镜像站点&#xff0c;支持断点续传。包含速度测试功能&#xff0c;可实时显示下载…

作者头像 李华