openpyxl

How to create nested dictionaries from excel sheet using Openpyxl

给你一囗甜甜゛ 提交于 2020-03-05 06:06:24
问题 I am new to programming and am trying to do the following (so far unsuccessfully): I have an excel spreadsheet with product codes , sellers and prices and am trying to update the prices in my spreadsheet from two different spreadsheets sent by wholesalers. I want a program to correctly search an excel spreadsheet and copy the corresponding price from there to the correct location above. So I want to, for example: download the price for product code '92526' sold by wholesaler A. I want to

【python办公自动化(6期)】8.批量处理调整Excel内容

六眼飞鱼酱① 提交于 2020-03-04 03:08:13
批量处理调整Excel内容 修改字体样式 Font(name=字体名称,size=字体大小, bold=是否加粗,italic=是否斜体,color=字体颜色) import os os . chdir ( 'C:\\Users\\Administrator\\Desktop\\test' ) from openpyxl . styles import Font from openpyxl import load_workbook workbook = load_workbook ( filename = '这是一个表格.xlsx' ) sheet = workbook . active cell = sheet [ 'A1' ] font = Font ( name = '思源黑体 Regular' , size = 12 , bold = True , italic = True , color = 'FF0000' ) cell . font = font workbook . save ( filename = '这是一个表格.xlsx' ) 获取表格中字体的样式 cell.font.属性 import os os . chdir ( 'C:\\Users\\Administrator\\Desktop\\test' ) from openpyxl import load

【python办公自动化(6期)】9.向Excel文件中插入图片、生成柱状图、折线图和饼图

南笙酒味 提交于 2020-03-04 00:14:20
向Excel文件中插入图片、生成柱状图、折线图 插入图片 openpyxl.drawing.image/sheet.add_image() import os os . chdir ( 'C:\\Users\\Administrator\\Desktop\\test' ) from openpyxl import load_workbook from openpyxl . drawing . image import Image workbook = load_workbook ( filename = '这是一个表格.xlsx' ) sheet = workbook . active photo = Image ( '1.jpg' ) photo . height = 100 photo . width = 220 sheet . add_image ( photo , 'C1' ) workbook . save ( filename = '这是一个表格.xlsx' ) 生成图表 插入柱状图 BarChart()/Reference() import os os . chdir ( 'C:\\Users\\Administrator\\Desktop\\test' ) from openpyxl import load_workbook from openpyxl .

Python操作Excel - openpyxl

巧了我就是萌 提交于 2020-03-02 12:40:28
转自 https://www.cnblogs.com/zeke-python-road/p/8986318.html 1、 安装 pip install openpyxl 想要在文件中插入图片文件,需要安装pillow,安装文件:PIL-fork-1.1.7.win-amd64-py2.7.exe   · font(字体类):字号、字体颜色、下划线等   · fill(填充类):颜色等   · border(边框类):设置单元格边框   · alignment(位置类):对齐方式   · number_format(格式类):数据格式   · protection(保护类):写保护 2、 创建 一个 excel 文件 ,并 写入 不同类的内容 # -*- coding: utf-8 -*- from openpyxl import Workbook wb = Workbook() #创建文件对象 # grab the active worksheet ws = wb.active #获取第一个sheet # Data can be assigned directly to cells ws['A1'] = 42 #写入数字 ws['B1'] = "你好"+"automation test" #写入中文(unicode中文也可) # Rows can also be appended

openpyxl writing large file memory issue

北城以北 提交于 2020-03-01 05:20:06
问题 I'm trying to create a 75col by 650k rows document using openpyxl write only workbook, which is said to bear near constant memory footprint, but after a while I get 17.2GB memory usage in activity monitor, here's the code I'm using, am I doing something wrong? def testOPENPYXL(): wb = openpyxl.Workbook(write_only=True) ws = wb.create_sheet() for irow in range(650000): ws.append(['%d' % i for i in range(75)]) path = os.path.expanduser("~/Desktop/test/test.xlsx") wb.save(path) 回答1: The simple

How to check if a large Excel file is protected as quickly as possible?

懵懂的女人 提交于 2020-02-29 09:10:31
问题 How to check if excel file is protected with password the fastest way (without trying to open it and placing an exception)? Updated: from zipfile import * from openpyxl import load_workbook filename = 'Z:\\path_to_file\\qwerty.xlsm' # protected one try: wb = load_workbook(filename, data_only=True, read_only=True) except (BadZipfile) as error: print(is_zipfile(filename)) A problem is that I got False as an output, thus I cannot get rid of the exception and replace it with is_zipfile()

csv与openpyxl函数

余生颓废 提交于 2020-02-29 00:46:13
csv与openpyxl函数 csv函数 常用的存储数据的方式有两种——存储成csv格式文件、存储成Excel文件(不是复制黏贴的那种) 前面,我有讲到json是特殊的字符串。其实,csv也是一种字符串文件的格式,它组织数据的语法就是在字符串之间加分隔符——行与行之间是加换行符,同列之间是加逗号分隔。 为什么要加分隔符?因为不加的话,数据都堆在一起,会显得杂乱无章,也不方便我们之后提取和查找。这也是一种让数据变得有规律的组织方式。 它可以用任意的文本编辑器打开(如记事本),也可以用Excel打开,还可以通过Excel把文件另存为csv格式(因为Excel支持csv格式文件)。 另外,用csv格式存储数据,读写比较方便,易于实现,文件也会比Excel文件小。但csv文件缺少Excel文件本身的很多功能,比如不能嵌入图像和图表,不能生成公式。 import csv #引用csv模块。 csv_file = open(‘demo.csv‘,‘w‘,newline=‘‘,encoding=‘utf-8‘) #创建csv文件,我们要先调用open()函数,传入参数:文件名“demo.csv”、写入模式“w”、newline=‘‘、encoding=‘utf-8‘。 加newline=‘ ‘参数的原因是,可以避免csv文件出现两倍的行距(就是能避免表格的行与行之间出现空白行)

Alter the style of all cells with openpyxl

可紊 提交于 2020-02-27 23:26:25
问题 I'm using openpyxl 2.0.3 with python2.7. Is there a way to apply a style to every cell in a worksheet? Lets say I want to change the font of all cells, similar to how I would open an excel document, hit ctrl+a, right click and change the format. 回答1: There is no method to do this. At the moment the best approach would probably be to set the style for all the relevant columns or rows style = Style(…) for col in 'ABCD': ws._styles['A'] = style I think we'll be working on improving handling

win7下安装openpyxl

坚强是说给别人听的谎言 提交于 2020-02-27 12:39:05
想使用python来操作Excel,看资料据说openpyxl非常好用,于是到https://pypi.python.org/pypi/openpyxl下载了安装包。下面就来说说安装步骤,也算是对自己的操作的一个备忘。 1、安装python(步骤略)下载地址:https://www.python.org/downloads/windows/ 2、下载openpyxl,地址https://pypi.python.org/packages/source/o/openpyxl/openpyxl-2.3.1.tar.gz 3、解压openpyxl-2.3.1.tar.gz到任意目录下。如python/openpyxl-2.3.1 4、CMD窗口到python/openpyxl-2.3.1目录下,找到setup.py文件,在命令行下输入:python setup.py install 回车即可。 5、全程不用干预,等待出现Finished processing dependencies for openpyxl==2.3.1,表示安装成功。 6、测试,在python环境下输入   >>>import openplyxl   >>>help(openpyxl) 出现 安装成功! 来源: https://www.cnblogs.com/SunOne/p/4994249.html

Finding hidden cells using openpyxl

隐身守侯 提交于 2020-02-20 11:33:07
问题 I've been trying to write a script to copy formatting from one workbook to another and, as anyone dealing with openpyxl knows, it's a big script. I've gotten it to work pretty well, but one thing I can't seem to figure out is how to read from the original if columns are hidden. Can anyone tell me where to look in a workbook, worksheet, column or cell object to see where hidden columns are? 回答1: Worksheets have row_dimensions and column_dimensions objects which contain information about