openpyxl

Python search corresponding data in multiple excel and paste to a new excel worksheet

你。 提交于 2019-12-13 02:51:13
问题 i have some excel files in a folder, there's already a worksheet call "service" in each file Notes_111.xlsx Notes_222.xlsx Notes_888.xlsx Workflow : I want to open each .xlsx file, for example, Notes_111.xlsx, then add a new worksheet, name as "code_city", then based on file's name 111 , extract only the code = 111 data from the master dataframe and paste to the new worksheet. then save. Sample master dataframe in another excel file code city 0 111 NY 1 111 CA 2 222 NJ 3 888 WE 4 888 TL i don

AGGREGATE formula not automatically calculating when written to results spreadsheet

不想你离开。 提交于 2019-12-13 02:46:34
问题 I have a python 3.7 script that has been developed using the OPENPYXL (v2.5.10) library to take data from a number of excel workbooks, to process that data and then to write to a separate excel workbook. The results workbook contains around 100 named ranges and numerous formula which all work as expected including automatically calculating when the workbook is opened in excel. I am having trouble with one particular formula group which includes the AGGREGATE function. In this case the formula

openpyxl highlighting multiple cells when one of them is selected upon closing the file

断了今生、忘了曾经 提交于 2019-12-13 01:12:37
问题 I have come across weird behaviour when programmatically highlighting cells in openpyxl which was initially described in this post of mine. I spent some (much more) time investigating this and managed to track the source of this error. I don't know if this is the only way to reproduce it, maybe some steps are not necessary, but the following example code is closest to what I am actually doing: import openpyxl def doStuff(iterations=1, fName='test'): for i in range(iterations): wb = openpyxl

Sorting with openpyxl

隐身守侯 提交于 2019-12-12 22:04:02
问题 I am trying to sort columns from least to greatest using openpyxl. I am open to using other libraries to accomplish this. Here is the code that I have right now, however, nothing is being sorted. from openpyxl import load_workbook wb=load_workbook('NotSorted.xlsx') ws1=wb.get_sheet_by_name('Mean') ws1.auto_filter.add_sort_condition('J2:J21') wb.save('Sorted.xlsx') Any help is greatly appreciated! 回答1: The openpyxl documentation clearly states: This will add the relevant instructions to the

Append a sheet to an existing excel file using openpyxl

不打扰是莪最后的温柔 提交于 2019-12-12 17:57:18
问题 I saw this post to append a sheet using xlutils.copy: https://stackoverflow.com/a/38086916/2910740 Is there any solution which uses only openpyxl? 回答1: I found solution. It was very easy: def store_excel(self, file_name, sheet_name): if os.path.isfile(file_name): self.workbook = load_workbook(filename = file_name) self.worksheet = self.workbook.create_sheet(sheet_name) else: self.workbook = Workbook() self.worksheet = self.workbook.active self.worksheet.title = time.strftime(sheet_name) . . .

Openpyxl fills adjacent cells

纵饮孤独 提交于 2019-12-12 16:30:19
问题 I came across a very peculiar thing. When I try to fill a cell in an excel worksheet with a solid colour it fills adjacent cells, sometimes even dozens. It's odd since I do exactly the same things successfully in other places of my code, it's just this one which is different. I'm slowly running out of ideas on what could be wrong and thought that maybe someone here had a similar issue and solved it. My relevant code is: __incorrectUnitsColour__='FF33CC' cell, sheet =GetCellFromDest(str(named

OpenPyXL always return None for a cell with hyperlink

倾然丶 夕夏残阳落幕 提交于 2019-12-12 10:14:12
问题 (My ultimate purpose is to append clickable cells to existing XLSX .) I use the code below to extract the cell's display value and the hyperlink. from openpyxl import load_workbook xlsFile='hello.xlsx' wbook = load_workbook(xlsFile) wsheet1= wbook.get_sheet_by_name('mysheet') cell1 = wsheet1.cell('A1') print cell1.value print cell1.hyperlink print wsheet1['A1'].value print wsheet1['A1'].hyperlink But it returns the following things: URL1 None URL1 None Why the hyperlink always None ? I did

Manipulate existing excel table using openpyxl

只谈情不闲聊 提交于 2019-12-12 09:46:38
问题 I'm currently honing my python / excel skills, and have run into an issue with openpyxl I am trying to open a workbook, replace rows in an existing table, and save the workbook again. Ideally I'd like to also first be able delete all rows from the table (Though retaining the table structure) My initial workbook contains a sheet named "inputData". In this I have a table named "Data" columns A, B, C and 2 rows of data. I also have a csv file named "input.csv" containing The same columns but 4

Column and row dimensions in OpenPyXL are always None

别来无恙 提交于 2019-12-12 09:36:31
问题 Why is openpyxl reading every row and column dimension as None? This is the case regardless of whether the table was created via openpyxl or within Microsoft Excel. import openpyxl wb = openpyxl.load_workbook(r'C:\data\MyTable.xlsx') ws = wb.active print ws.row_dimensions[1].height print ws.column_dimensions['A'].width prints None and None. These aren't hidden columns/rows. They clearly have dimensions when viewed in Excel. I know that loading the workbook with iterators will prevent the

openpyxl 获取excel 单元格 颜色

∥☆過路亽.° 提交于 2019-12-12 09:36:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> book = openpyxl.load_workbook(filedir) sheet_ = book.get_sheet_by_name(book.get_sheet_names()[0]) sheet_.cell(i, 3).font.color.rgb # 获取 表格内字体颜色 sheet_.cell(i, 3).fill.fgColor.rgb # 获取表格 填充色 颜色 来源: oschina 链接: https://my.oschina.net/xiaohuai4869/blog/3142005