openpyxl

how to read the xlsx color infomation by using openpyxl

余生长醉 提交于 2019-12-03 15:14:41
I am using openpyxl to read excel file. For my application, i need to read the background color of the cell in the xlsx file But i cant find how to load those color info. I tried to use cell.style.fill.color.index, but it only return FFFFFFFF as background which is not correct to the file i read. Does openpyxl support reading color format? UPDATE (2014): I updated openpyxl to v. 2.2. They seem to have resolved the problem that I documented in my original answer (see below). I am now able to successfully retrieve the background color after I've set it manually through Excel. However, the syntax

Python 2.7 Openpyxl UserWarning

倾然丶 夕夏残阳落幕 提交于 2019-12-03 14:50:44
Why do I receive this warning message every time I run my code? (below). Is it possible to get rid of it? If so, how do I do that? My code: from openpyxl import load_workbook from openpyxl import Workbook wb = load_workbook('NFL.xlsx', data_only = True) ws = wb.active sh = wb["Sheet1"] ptsDiff = (sh['J127'].value) print ptsDiff The code works but I get this warning message: Warning (from warnings module): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/openpyxl/reader/worksheet.py", line 320 warn(msg) UserWarning: Unknown extension is not supported and will

xlsx and xlsm files return badzipfile: file is not a zip file

我是研究僧i 提交于 2019-12-03 14:48:21
I'm trying to open both an xlsx file and an xlsm file both give me the same error badzipfile: file is not a zip file here is what I'm typing: import openpyxl wb=openpyxl.load_workbook('c:\\users\\me\\documents\\filename.xlsm', keep_vba=True) wb2=openpyxl.load_workbook('c:\\users\\me\\documents\\filename2.xlsx') both load_workbook commands result in the same error. They both exist at that location. why am I getting this error? The same problem occurred to me, and then I noticed the following: When I created the .xlsx file from file manager, by creating new document with .xlsx format, I had the

Python处理Excel数据

拈花ヽ惹草 提交于 2019-12-03 14:25:21
前段时间做了个小项目,帮个海洋系的教授做了个数据处理的软件。基本的功能很简单,就是对Excel里面的一些数据进行过滤,统计,对多个表的内容进行合并等。之前没有处理Excel数据的经验,甚至于自己都很少用到Excel。记得《Python核心编程》的最后一章里有讲到用Win32 COM操作office, 看了一下讲的不是很清楚。google了一下找到不少能处理excel数据的模块。对比了一下最终选定了openpyxl,openpyxl专门用于处理Excel2007及以上版本产生的xlsx文件。不幸的是我所得到的数据中xls和xlsx都有,不过转换并不是什么难事,就暂时吧这个问题忽略了。 模块的安装过程非常简单,官网上有简单的使用说明和API文档,整体来说使用非常容易,也基本能满足我的需求。对于Excel文件,我所需要的只是从中将相应位置的数据读取出来,以及把数据写入到对应的位置中去。而其间数据的处理,通过python可以很容易地完成。 1. Excel数据的类型及组织方式 openpyxl中定义了多种数据格式,我只涉及到了其中最重要的三种: NULL: 空值,对应于python中的None,表示这个cell里面没有数据。 numberic: 数字型,统一按照浮点数来进行处理。对应于python中的float。 string: 字符串型,对应于python中的unicode。

How to use field name or column header in openpyxl?

北城以北 提交于 2019-12-03 13:47:11
See my code below. This code works very well, but I would like to do two things. One thing is I made if statement with or much shorter than actual for example. I have many columns like this, not all next to each other. I would like it to be shorter. Also, sometimes I may not know exact column letter. So I want to know if there is a way to know the column name or header. Like the values that would be in very top row. So I can test to see if it is one of those values to always perform function on that cell if it's in the specified column. I can't find openpyxl function to do column name. Not

openpyxl convert CSV to EXCEL

浪子不回头ぞ 提交于 2019-12-03 10:16:42
问题 How can I convert a CSV file with : delimiter to XLS (Excel sheet) using openpyxl module? 回答1: Well here you go... import csv from openpyxl import Workbook from openpyxl.cell import get_column_letter f = open(r'C:\Users\Asus\Desktop\herp.csv') csv.register_dialect('colons', delimiter=':') reader = csv.reader(f, dialect='colons') wb = Workbook() dest_filename = r"C:\Users\Asus\Desktop\herp.xlsx" ws = wb.worksheets[0] ws.title = "A Snazzy Title" for row_index, row in enumerate(reader): for

Python 2.7 Openpyxl UserWarning

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Why do I receive this warning message every time I run my code? (below). Is it possible to get rid of it? If so, how do I do that? My code: from openpyxl import load_workbook from openpyxl import Workbook wb = load_workbook('NFL.xlsx', data_only = True) ws = wb.active sh = wb["Sheet1"] ptsDiff = (sh['J127'].value) print ptsDiff The code works but I get this warning message: Warning (from warnings module): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/openpyxl/reader/worksheet.py", line 320 warn(msg)

Losing merged cells border while editing Excel file with openpyxl

柔情痞子 提交于 2019-12-03 07:43:58
I have two sheets in an Excel file and the first one is a cover sheet which I don't need to edit. There are few merged cells in the cover sheet. But when I edit the file using openpyxl not even touch the cover sheet, I lose borders from the merged cells. Is there any fix to this problem? I am using Load_workbook('excel file') to load the excel file and saving it with a different filename. Actual solution is to patch the libraries code by including this snippet after including the library, it fixes the problem. (Note: don't worry about missing definitions, e.g. COORD_RE, i.e. the patch is self

Python - Automatically adjust width of an excel file's columns

[亡魂溺海] 提交于 2019-12-03 07:25:58
问题 Newbie - I have a Python script that adjusts the width of different columns of an excel file, according to the values specified: import openpyxl from string import ascii_uppercase newFile = "D:\Excel Files\abc.xlsx" wb = openpyxl.load_workbook(filename = newFile) worksheet = wb.active for column in ascii_uppercase: if (column=='A'): worksheet.column_dimensions[column].width = 30 elif (column=='B'): worksheet.column_dimensions[column].width = 40 elif (column=='G'): worksheet.column_dimensions

Fastest Way To Run Through 50k Lines of Excel File in OpenPYXL

有些话、适合烂在心里 提交于 2019-12-03 06:57:20
I'm using openpyxl in python, and I'm trying to run through 50k lines and grab data from each row and place it into a file. However.. what I'm finding is it runs incredibely slow the farther I get into it. The first 1k lines goes super fast, less than a minute, but after that it takes longer and longer and longer to do the next 1k lines. I was opening a .xlsx file. I wonder if it is faster to open a .txt file as a csv or something or to read a json file or something? Or to convert somehow to something that will read faster? I have 20 unique values in a given column, and then values are random