openpyxl

python处理办公文档的模块

蹲街弑〆低调 提交于 2020-02-01 03:32:53
处理Excel电子表格 Python的openpyxl模块让我们可以在Python程序中读取和修改Excel电子表格,当然实际工作中,我们可能会用LibreOffice Calc和OpenOffice Calc来处理Excel的电子表格文件,这就意味着openpyxl模块也能处理来自这些软件生成的电子表格。关于openpyxl的使用手册和使用文档可以查看它的官方文档。 处理Word文档 利用python-docx模块,Pytho 可以创建和修改Word文档,当然这里的Word文档不仅仅是指通过微软的Office软件创建的扩展名为docx的文档,LibreOffice Writer和OpenOffice Writer都是免费的字处理软件。 处理PDF文档 PDF是Portable Document Format的缩写,使用.pdf作为文件扩展名。接下来我们就研究一下如何通过Python实现从PDF读取文本内容和从已有的文档生成新的PDF文件。 来源: CSDN 作者: soda東風 链接: https://blog.csdn.net/weixin_42568012/article/details/103779691

程序员如何 10 分钟用 Python 画出蒙娜丽莎?

坚强是说给别人听的谎言 提交于 2020-02-01 02:47:20
之前看到过很多头条,说哪国某人坚持了多少年自学使用excel画画,效果十分惊艳。对于他们的耐心我十分敬佩。 但是作为一个程序员,自然也得挑战一下自己。 这种需求,我们十分钟就可以完成! 基本思路 ! 实现这个需求的基本思路是读取这张图片每一个像素的色彩值,然后给excel里的每一个单元格填充上颜色。所以主要用到的是PIL、openpyxl这两个库。 PIL使用 PIL是Python里面做图像处理的时候十分常用的一个库,功能也是十分的强大,这里只需要用到PIL里一小部分的功能。 from PIL import Image img = Image.open(img_path) # 读取图片 width, height = img.size # 获取图片大小 r, g, b = img.getpixel((w - 1, h - 1)) # 获取像素色彩值 Image.open()是PIL里面打开一张图片的函数,支持多种图片类型 img_path是图片路径,可以是相对路径,也可以是绝对路径 img.size是获取图片的size属性,包含图片的宽和高 img.getpixel()是获取图片色彩值的函数,需传入一个tuple或list,值为像素坐标xy openpyxl使用 openpyxl几乎是Python里功能最全的操作excel文件的库了,这里也只需要用到它的一小部分功能。 import

openpyxl读取图片和超链接-详细版

天涯浪子 提交于 2020-01-31 04:05:58
网上资料比较少,自己的办法可能比较笨,但是坚持原创。 应用场景是通过读取excel格子的内容去按预定格式生成word文档,对于对文档格式要求严格的部分行业~~有一定的意义。 add_paragraph和add_run这类基础的不说,CSDN已经很多,主要解决openpyxl如何 跨sheet读取表格、图片等数据 。 使用超链接 自己在xlsx中第二个sheet中创建一个表格,选中表格数据后右键-定义位置,即可看到引用位置 =Sheet2!$A$1:$B$5 我的程序是读取sheet1的内容,所以在sheet中插入一个超链接,选择本地文档位置-sheet2,将刚才的引用位置复制进去-确定。 这样在sheet1中的超链接,点击后将跳转到sheet2, 并且通过openpyxl读取超链接时,才能得到这个引用位置。 自己也可以试试不加引用位置的结果。(其实和锚点的作用类似) 这样得到引用位置后,可用正则表达式,得到python跳转打开sheet2后要读哪些格子内容,这个就是普通读取table的内容,不在赘述。 eval={'A':1,'B':2,'C':3,'D':4,'E':5,'F':6} #翻译格子数的字典 wb=load_workbook('1.xlsx') sheet=wb['Sheet1'] t=sheet.cell(7,5).hyperlink.location

Handling very large files with openpyxl python

↘锁芯ラ 提交于 2020-01-30 10:53:15
问题 I have a spreadsheet with 11,000 rows and 10 columns. I am trying to copy each row with selected columns, add additional information per line and output to a txt. Unfortunately, I am having really bad performance issues, files start to slug after 100 rows and kill my processor. Is there a way to speed this up or use better methodology? I am already using read_only=True and data_only=True Most memory intensive part is iterating through each cell : for i in range(probeStart, lastRow+1): dataRow

Getting Excel cell background themed color as hex with openpyxl

我与影子孤独终老i 提交于 2020-01-25 08:52:28
问题 I'm reading *xlsx files with openpyxl python library, and within other data I want to get information on cells background color. This code I was using normally, while my worksheets contained only standard colors, then it returned me something like "FFFFC000" in a string format that I can use further. color = cell.fill.start_color.index After I've met documents containing cells of themed colors it returns me just integers like '1' or '9' for such cells, as I can guess it equals to column of

How do I install packages to Anaconda from locally built tar.gz

核能气质少年 提交于 2020-01-25 07:32:05
问题 I want to edit the package openpyxl and reinstall the edited version to anaconda. I downloaded the source code from here https://bitbucket.org/openpyxl/openpyxl/downloads/. I then edited the source python files I needed to - the edits are shown at the bottom of this page in case it is relevant > https://bitbucket.org/openpyxl/openpyxl/issues/1237/unable-to-save-wb-with-3d-bar-chart-from I then used the following command to create the tar file from my edited source code, as explained here

Openpyxl adjust image between two cells

假如想象 提交于 2020-01-25 00:24:47
问题 I'm trying to adjust image between two cells using openpyxl. My problem is that worksheet.add_image(image, position) method only accepts top-left position of image. Is there any way how to scale my image between two (top-left, bottom-right) cells? I tried to compute dimensions using height = sum([worksheet.row_dimensions[start_row+i].height for i in range(img_cols)]) and then setting it as from openpyxl.drawing.image import Image Image(image_filename, size=[width,height]) but that doesn't

penpyxl basic function demo code

£可爱£侵袭症+ 提交于 2020-01-24 01:45:23
Openpyxl basic function demo code demo code: #!/usr/bin/env python # -*- coding: utf-8 -*- """ summary description - openpyxl basic功能练习 - https://openpyxl.readthedocs.io/en/default/usage.html :REQUIRES: :TODO: :AUTHOR: Pengtao.Fan :ORGANIZATION: :CONTACT: fanpengtao@gmail.com :SINCE: Sun Aug 7 21:21:38 2016 :VERSION: 0.1 """ #=============================================================================== # PROGRAM METADATA #=============================================================================== __author__ = '' __contact__ = '' __copyright__ = '' __license__ = '' __date__ = 'Sun Aug 7

Using openpyxl to find rows that contain cell with specific value (Python 3.6)

浪尽此生 提交于 2020-01-23 03:33:45
问题 I am completely new to openpyxl so, as you can imagine, I am having pretyy hard times when I try to make use of it. I have an excel report that contains only one sheet (called Sheet 1). I'd like to search all cells for those that contain specific string (product name ABC in this case). Then I would like to copy contents of every cell in the rows that contain cell with ABC product name. And assign every cell to a variable. To give you better idea of what I am trying to achieve I'll give you an

工资条自动生成

好久不见. 提交于 2020-01-22 18:04:49
年终绩效分配结果出来了,领导要求每人要清楚地知道自己的情况。要求:总绩效和各分类都要清楚。这就表示我们要给每人六个纸条,一个总的,五个分的。打出来,裁开,分发给每个人!累死人。所以,我就想能否每人生成一个表,直接A4打印! 表的结构大致是这个样子。总绩效表和五个分绩效表。我的想法是:根据每个人的姓名生成一张表,把每个绩效表中对应姓名的数据行写入到该表中。调整格式打印输出即可。尝试的过程中,填了不少坑,但是把OpenPyXl这个库倒是大体上整明白了。不废话,直接上代码: # open a excel file import openpyxl from openpyxl.utils import get_column_letter, column_index_from_string from openpyxl.styles import Border, Side, Alignment border_a = Border( left=Side(border_style='thin', color='FF000000'), right=Side(border_style='thin', color='FF000000'), top=Side(border_style='thin', color='FF000000'), bottom=Side(border_style='thin',