python3 使用openpyxl 处理excel表格数据
直接贴代码,注释很清楚
import openpyxl
import time
import os
import threading
class mExcelManager:def __init__(self,filerootpath,filename):self.allmodels = []self.zimu = ["A", "B", "C", "D", "E", "F","G", "H", "I", "J", "K", "L","M", "N", "O", "P", "Q", "R","S", "T", "U", "V", "W", "X","Y", "Z"]self.filerootpath = filerootpathself.filename = filenameself.result_excel_name = ""# 读取excel表格def read_excel_data(self,defaultmax_column=12):wb = openpyxl.load_workbook(filename=self.filename, read_only=True, )ws = wb.activemodel = []print(ws.max_row)for index in range(2, ws.max_row):if model.__len__() > 1:self.allmodels.append(model)model = []# print("read datas =>")if self.allmodels.__len__() == 200:time.sleep(0.1)continuefor rowindex in range(1,defaultmax_column):data = ws[""+self.zimu[rowindex] + str(index)].valuemodel.append(data)#写入excel表格,写入速度比较慢def write_to_excel(self,file_path_name):wb = openpyxl.load_workbook(filename=file_path_name)ws = wb.activestart_time = time.time()count = 0while (True):if self.allmodels.__len__() > 0:model = self.allmodels.pop(0)ws.append(model)wb.save(file_path_name)count = count + 1currenttime = time.time()useseconds = int(currenttime) - int(start_time)print("write datas "+ " time:" + str(useseconds) +" count: " + str(count))else:time.sleep(0.01)continue# 创建表格def create_excel(self,filename,sheet_name = "",title = ""):self.result_excel_name = filenamewb = openpyxl.Workbook()if sheet_name.__len__()>0:wb.create_sheet("Name", 0)ws = wb.activeif title.__len__() >0:ws.title = "bob"wb.save(filename=filename)
python3 使用openpyxl 处理excel表格数据相关推荐
- python3读取excel数据-Python3读取和写入excel表格数据的示例代码
python操作excel主要用到 xlrd 和 xlwt 这两个库,xlrd读取excel表格数据, 支持 xlsx和xls格式的excel表格 :xlwt写入excel表格数据: 一.python ...
- python使用openpyxl处理excel表格数据
python使用openpyxl处理excel表格数据 前言 一.安装openpyxl包 二.读取excel数据 1. 获取excel表格的页码 2. 获取excel表格某一行的数据 3. 获取exc ...
- Python3读取和写入excel表格数据
目录 一.python读取excel表格数据 1.读取excel表格数据常用操作 2.xlrd模块的主要操作 3.读取单元格内容为日期时间的方式 4. 读取合并单元格的数据 二.python写入exc ...
- python 显示表格数据_python显示excel表格数据-怎么用python读取excel表格的数据
怎么用python读取excel表格的数据 #导入包 import xlrd #设置路径 path='C:\\Users\\jyjh\\Desktop\\datap.xlsx' #打开 data=xl ...
- Python3 编写处理Excel表格数据筛选脚本用到的一些方法
记录下之前用python3 写的一个处理Excel表格数据筛选脚本用到的一些方法. 本文内容比较杂,可按需跳转翻看. pandas是一个内容十分丰富的库,我也只不过用到其中处理excel的方法,对这个 ...
- python3 写入excel表格数据_Python3读取和写入excel表格数据
目录 python操作excel主要用到 xlrd和xlwt 这两个库,xlrd读取excel表格数据, 支持 xlsx和xls格式的excel表格 :xlwt写入excel表格数据: 一.pytho ...
- python导入excel表格-Python 将Excel表格数据导入MySQL数据库
今天分享一个刚刚完成的Python脚本,一个实用的小技能,就是利用Python代码,将EXCEL表格数据导入到MySQL数据库中!话不多说,下面代码示例. Excel表格数据.jpg 1示例代码: i ...
- Python 使用 pandas 和 openpyxl 读取 excel 表格(读取指定行和列)
前言 在使用Python处理表格时,pandas 和 openpyxl是使用最多的两个库.现在我来简单记录一下这两个库在处理Excel表格时一些常用操作. 1.使用pandas操作excel表格 (1 ...
- python读excel表格数据绘制图表_Python读取Excel数据生成图表 v2.0
原博文 2020-06-15 15:09 − ## Python读取Excel数据生成图表 v2.0 ## 一.需求背景 自己一直在做一个周基金定投模拟,每周需要添加一行数据,并生成图表.以前一直是用 ...
最新文章
- 第四课.LinuxShell编程
- android rebound平移,Android 仿 IOS 拖拽回弹之进阶 ReboundFrameLayout
- 【Java系列】从JVM角度解析Java核心类String的不可变特性
- OCP 042全真试题讲解
- 【Flask】RESTful的响应处理
- boost::transform_iterator用法的测试程序
- CanalSharp.AspNetCore v0.0.4-支持输出到MongoDB
- 前端模板引擎artTemplate---高性能JavaScript模板引擎
- Hadoop学习之路(十三)MapReduce的初识
- 再一次站在捆绑销售风口的携程该何去何从?
- .NET常见错误大全
- Windows Server 2008 优化
- 【BZOJ2654】tree
- 屏幕镜像显示无法连接服务器,苹果屏幕镜像连接失败原因
- 电脑网线,电脑网线主要分类
- vue3.Vue实例
- python地理空间_Python批量下载地理空间数据云数据!Python无所不能!-站长资讯中心...
- 2018 抖音热门歌曲大全
- 消防信号总线原理_消防总线隔离模块作用及工作原理?
- 美团程序员提问:应届生,工资34k,算多吗?