废话不多说,看代码,不懂的留言。

from openpyxl import *

class ExcelUtil:
''' 读取excel文件内容''' def create_work_book(self, title, index, maxRow, maxColumn, fileName):
"""
:param title: 表名称,
:param index: 表所处位置(第一位从0开始)
:param maxRow: 创建的最大行数
:param maxColumn: 创建的最大列数
:param maxColumn: 文件保存路劲
"""
wb = Workbook()
sheet = wb.create_sheet(title=title, index=index)
sheet.insert_rows(0, maxRow)
sheet.insert_cols(0, maxColumn)
wb.save(fileName) def fill_cell(self, fileName, sheetName, cellIndex, value):
"""
:param fileName: 文件路径
:param sheetName: 表名称
:param cellIndex: 单元格所在位置,如'A1'
:param value: 写入单元格的值
"""
wb = load_workbook(fileName)
sheet = wb[sheetName]
sheet[cellIndex.upper()] = value
wb.save(fileName) def read_cell(self, fileName, sheetName, cellIndex):
"""
:param fileName: 文件路径
:param sheetName: 表名称
:param cellIndex: 单元格所在位置,如'A1'
:return:单元格值
"""
wb = load_workbook(fileName)
sheet = wb[sheetName]
return sheet[cellIndex.upper()].value def batch_read_cell(self, fileName, sheetName):
"""
:param fileName: 文件路径
:param sheetName: 表名
:return: 二维数组
"""
wb = load_workbook(fileName)
sheet = wb[sheetName]
lists = []
for row in sheet.rows:
list=[]
for cell in row:
list.append(cell.value)
lists.append(list)
return lists

python库openpyxl操作excel的更多相关文章

  1. 用python库openpyxl操作excel,从源excel表中提取信息复制到目标excel表中

    现代生活中,我们很难不与excel表打交道,excel表有着易学易用的优点,只是当表中数据量很大,我们又需要从其他表册中复制粘贴一些数据(比如身份证号)的时候,我们会越来越倦怠,毕竟我们不是机器,没法 ...

  2. python用openpyxl操作excel

    python操作excel方法 1)自身有Win32 COM操作office但讲不清楚,可能不支持夸平台,linux是否能用不清楚,其他有专业处理模块,如下 2)xlrd:(读excel)表,xlrd ...

  3. python通过openpyxl操作excel

    python 对Excel操作常用的主要有xlwt.xlrd.openpyxl ,前者xlwt主要适合于对后缀为xls比较进行写入,而openpyxl主要是针对于Excel 2007 以上版本进行操作 ...

  4. Python使用openpyxl操作excel表格

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取 ht ...

  5. python使用openpyxl操作excel总结

    安装openpyxl pip install openpyxl 简单示例 from openpyxl import Workbook #创建一个工作薄对象,也就是创建一个excel文档 wb = Wo ...

  6. python使用openpyxl操作excel

    def initExcel(): file_path = "test.xlsx" file = load_workbook(file_path) table = file[&quo ...

  7. Python使用openpyxl读写excel文件

    Python使用openpyxl读写excel文件 这是一个第三方库,可以处理xlsx格式的Excel文件.pip install openpyxl安装.如果使用Aanconda,应该自带了. 读取E ...

  8. 【转发】Python使用openpyxl读写excel文件

    Python使用openpyxl读写excel文件 这是一个第三方库,可以处理xlsx格式的Excel文件.pip install openpyxl安装.如果使用Aanconda,应该自带了. 读取E ...

  9. python openpyxl 操作 excel

    初识与安装 Openpyxl is a Python library for reading and writing Excel 2010 xlsx/xlsm/xltx/xltm files. 安装 ...

随机推荐

  1. ABP 源码分析汇总之 IOC

    IOC的优点: 1. 依赖接口,而非实现,如下代码, 这样的好处就是,客户端根本不知道PersonService的存在,如果我们换一下IPersonService的实现,客户端不用任何修改, 说的简单 ...

  2. 机器学习经典书籍&论文

    原文地址:http://blog.sina.com.cn/s/blog_7e5f32ff0102vlgj.html 入门书单 1.<数学之美>PDF6 作者吴军大家都很熟悉.以极为通俗的语 ...

  3. 实用SQL语句

    sp_depends t_im_flow 获取到与这个表有关系的存储过程.触发器.函数.视图等.

  4. Angular2-使用Augury来调试Angular2程序

    参考: http://www.jianshu.com/p/efecaea287f2https://augury.angular.io/ https://augury.angular.io/pages/ ...

  5. Linux中pid_t类型为int类型

    1. 查看man手册,找到pid_t,可以通过getpid函数来看 2. 打开sys/types.h 3. 打开bits/types.h 4. 打开bits/typesizes.h 找不到相关的头文件 ...

  6. RabbitMQ消息队列(十)RPC应用2

    基于RabbitMQ RPC实现的主机异步管理 地址原文:http://blog.51cto.com/baiying/2065436,作者大大,我把原文贴出来了啊.不要告我 root@ansible: ...

  7. ZOJ 2971 Give Me the Number (模拟,字符数组的清空+map)

    Give Me the Number Time Limit: 2 Seconds      Memory Limit: 65536 KB Numbers in English are written ...

  8. django 自定义用户表替换系统默认表

    首先新建一个users应用,编写这个应用的models类. from django.contrib.auth.models import AbstractUser class UserProfile( ...

  9. Windows下编译YouCompleteMe流程

    废话 生命在于折腾. 之前不用这个插件的原因: 因为要使这个插件起作用,前前后后需要下载几百MB(win下更是超过了1GB)的东西,包括了Clang编译器,ycmd的c艹源码还有ycm本身的vim s ...

  10. gradle 删除指定目录中的文件和目录

    // 删除bakAPk下的所有非母包文件 task deleTask(type: Delete){ FileTree tree = fileTree(dir: bakPath) tree.each { ...