openpyxl

Openpyxl compare cells

岁酱吖の 提交于 2020-01-06 14:01:29
问题 I have 2 sheets with some data (18k rows each) and need to check if value from source.xlsx exists in a target.xlsx file. The rows in the source file should be unique. If the cell from source file exists in the target file (in specific column) then in next column in target file need to fill value from some column which is in the source file. It is quite tricky so example would look like: target.xlsx <table><tbody><tr><th>Data</th><th>price</th><th> </th></tr><tr><td>1234grt </td><td> </td><td>

用Python在Excel里画出蒙娜丽莎

北慕城南 提交于 2020-01-06 13:20:12
之前看到过很多头条,说哪国某人坚持了多少年自学使用excel画画,效果十分惊艳。 对于他们的耐心我十分敬佩。 但是作为一个程序员,自然也得挑战一下自己。 这种需求,我们十分钟就可以完成! mona-lisa 基本思路 实现这个需求的基本思路是读取这张图片每一个像素的色彩值,然后给excel里的每一个单元格填充上颜色。所以主要用到的是 PIL 、 openpyxl 这两个库。​ PIL使用 PIL 是Python里面做图像处理的时候十分常用的一个库,功能也是十分的强大,这里只需要用到 PIL 里一小部分的功能。 from PIL import Imageimg = 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

Editing workbooks with rich text in openpyxl

别来无恙 提交于 2020-01-06 11:11:15
问题 I was wondering if openpyxl can read and/or write rich text into excel. I am aware that this question was asked once before in 2012 linked below, but I am not sure if this has changed. As it stands load_workbook() seems to throw away rich text formatting. As for a specific problem, I need to open, edit, and save a workbook where some cells have both superscripted and normal text in one cell. When I save the workbook, the format of the first character of the cell is applied to the rest of the

openpyxl reading column width from a .xlsx and writing it to a new .xlsx: width is different in a new file

混江龙づ霸主 提交于 2020-01-06 08:18:36
问题 I am using openpyxl to work with .xlsx files in Python . I have a sample.xlsx file from which I want to get a list of title fields and column width to use in the file generated by my script. At first I create a list with column names and their corresponding widths. So I use: filter_list = {"name": [], "width": []} row_count = sheet.max_row for i in range(row_count): cell = sheet.cell(row, i + 1) if cell.value: filter_list["name"].append(cell.value) filter_list["width"].append(sheet.column

Trying to format dates in column with openpyxl

回眸只為那壹抹淺笑 提交于 2020-01-06 04:54:06
问题 sourcefile.xlsx has column "A" with cell using the date format mm/dd/yyyy or 9/10/2019. When the column "A" cells are copied from source to new destination sheet, the date formatting is changed to 2019-09-10 0:00:00: I am struggling to identify a way to preserve the date format in the source file mm/dd/yyyy. Is that possible? If not, could I somehow use iter_rows to iterate through the column and set the date? I have tried: import datetime for row in ws3.iter_rows(min_row=6, max_row=None, min

Invalid mode or filename when using openpyxl in python 2.7

做~自己de王妃 提交于 2020-01-06 02:33:51
问题 I am trying to write something in an existing workbook with the openpyxl tools. But i am getting Err no 22 and dont know why. My Script looks like this : #Reading & writing to a workbook from openpyxl import Workbook from openpyxl.compat import range from openpyxl.cell import get_column_letter wb = Workbook() dest_filename = 'J:\Python_Script\book2.xls' ws = wb.active ws.title = "Tabelle 1" for col_idx in range(1, 40): col = get_column_letter(col_idx) for row in range(1, 600): ws.cell('%s%s'%

Not able to install lxml verison 3.3.5 in ubuntu

自古美人都是妖i 提交于 2020-01-06 02:20:08
问题 I am using openpyxl python package in my application. I am getting the following message when using the same. /usr/local/lib/python2.7/dist-packages/openpyxl/ init .py:31: UserWarning: The installed version of lxml is too old to be used with openpyxl warnings.warn("The installed version of lxml is too old to be used with openpyxl") Openpyxl requires lxml version 3.2.5 or above, and the version in my machine is 3.2.0. When I try to upgrade lxml to the latest version ie 3.3.5, it is getting

用Python在Excel里画出蒙娜丽莎

狂风中的少年 提交于 2020-01-05 14:58:37
之前看到过很多头条,说哪国某人坚持了多少年自学使用excel画画,效果十分惊艳。 对于他们的耐心我十分敬佩。 但是作为一个程序员,自然也得挑战一下自己。 这种需求,我们十分钟就可以完成! mona-lisa 基本思路 实现这个需求的基本思路是读取这张图片每一个像素的色彩值,然后给excel里的每一个单元格填充上颜色。所以主要用到的是 PIL 、 openpyxl 这两个库。​ PIL使用 PIL 是Python里面做图像处理的时候十分常用的一个库,功能也是十分的强大,这里只需要用到 PIL 里一小部分的功能。 from PIL import Imageimg = 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

openpyxl - increment of x and y axis ticks

跟風遠走 提交于 2020-01-05 08:25:14
问题 The bar chart I'm creating is auto scaling the Y axis tick increments starting at 0 as 0, .5, 1, 1.5 etc. I would like to have it increment in only whole numbers, ie 0, 1, 2, 3, 4 etc. I've tried chart.y_axis.tickLblSkip = 1 but had my doubts because I believe this is just the label itself, not the actual tick marks. Is there a way to control this? I see in the documentation you can control the overall scale of the axis with chart.y_axis.scaling.min and max but this isn't what I'm looking for

Openpyxl iterating through cells, can't compare cells to string

我怕爱的太早我们不能终老 提交于 2020-01-05 05:37:14
问题 I am having issues iterating through every cell in a workbook and comparing the call's value to a string object. I am able to successfully compare to datetime objects in the workbook but when it comes to regular 'String' objects nothing is being printed, and the cells are not updating. wb = openpyxl.load_workbook(pathz, read_only=False) ws = wb.active for row in ws.iter_rows(): for cell in row: if cell.value == a: print("Found datetime cell") cell.value = newDate if cell.value == "Hello":