openpyxl

Openpyxl updating sheet and maintaining graphs and images

怎甘沉沦 提交于 2019-12-01 20:39:01
I just created a script with openpyxl to update a xlsx file that we usually update manually every month. It work fine, but the new file lost all the graphs and images that were in the workbook. Is there a way to keep them? openpyxl version 2.5 will preserve charts in existing files. Rishil Antony Use xlwings instead, it works as a wrapper on pywin32 and can preserve the existing Excel graphs, pivot-tables, etc. 来源: https://stackoverflow.com/questions/37214983/openpyxl-updating-sheet-and-maintaining-graphs-and-images

openpyxl find cell or row by value

百般思念 提交于 2019-12-01 17:55:39
问题 Is there a method anyone knows of where I can find a cell or row in a document if I have a value other than iterating through the whole document to search for it? Case is, I have to very large spread sheets that I need to compare and I am doing that by using a single UUID that exists in each record in each sheet. So, basically: ws1 = rows1 ws2 = rows2 for row1 in rows1: uuid = row1[0].value comp = row1[1].value for row2 in rows2: if row2[0] = uuid if row2[0] = comp do-stuff() This seems more

openpyxl cell style not reporting correctly

时光毁灭记忆、已成空白 提交于 2019-12-01 16:20:14
Using the python library openpyxl I am reading an XLSX file created in excel 2007. it is empty apart from cell A1 which is coloured yellow and has the value "test" written in it. I can easily retrieve the value from that cell, however when I attempt to determine the fill colour I get the following results: this_sheet.cell("A1").style.fill.start_color returns "FFFFFF" this_sheet.cell("A1").style.fill.end_color returns "FF0000" Testing this on other blank cells I get exactly the same results, and trying to retrieve the font style information keeps returning calibri size 11 (our system default).

openpyxl cell style not reporting correctly

こ雲淡風輕ζ 提交于 2019-12-01 15:06:47
问题 Using the python library openpyxl I am reading an XLSX file created in excel 2007. it is empty apart from cell A1 which is coloured yellow and has the value "test" written in it. I can easily retrieve the value from that cell, however when I attempt to determine the fill colour I get the following results: this_sheet.cell("A1").style.fill.start_color returns "FFFFFF" this_sheet.cell("A1").style.fill.end_color returns "FF0000" Testing this on other blank cells I get exactly the same results,

Determine if worksheet is empty in openpyxl

冷暖自知 提交于 2019-12-01 14:08:29
I have an application where I write to a worksheet to the last column + 2 if there is already data and to the last column + 1 if the worksheet is empty. I get what I think is an empty worksheet as follows: from openpyxl.workbook.workbook import Workbook book = Workbook() sheet = book.active When I do sheet.max_row and sheet.max_column , I get 1 for both properties. I would like to get zero, so I do the following: if sheet.max_row == 1 and sheet.max_column == 1 and not sheet['A1'].value: start_col = 1 else: start_col = sheet.max_column + 2 Having to check the value of the cell seems a bit

Copy paste column range using OpenPyxl

浪尽此生 提交于 2019-12-01 13:02:50
问题 Hi so I am trying to copy and paste W7:W46 column into another worksheet. The code I have so far, col_j = New_Burden['W'] for idx, cell in enumerate(col_j,1): ws1.cell(row = idx, column = 10).value = cell.value is able to copy over the entire column, but unfortunately transfers the various headers as well. One solution I have tried is: for row in New_Burden['W7:W46']: for cell in row: ws1.cell(row = 2, column = 10).value = cell.value But that only copies the first value of W7 回答1: Copy a

openpyxl chart error bar styles

£可爱£侵袭症+ 提交于 2019-12-01 12:47:25
I've been assigned a "simple" task of collecting series of data columns to a results workbook. The results workbook contains necessary formulas and charts to analyze the results. The data is generated by an image analysis application I've written in python as series of excel workbooks. Now the problem is that openpyxl drops any existing charts in excel workbooks. I've spent the day figuring out how to use openpyxl charts for which there is some documentation and chart errorbars for which there are no examples whatsoever. There is the source which has terse comments.. Using win32com extension

KeyError when saving workbook

牧云@^-^@ 提交于 2019-12-01 11:33:52
问题 The file transactions.xlsx is not updated and this is precisely due to add_chart(). If I comment out add_chart all these errors does not arise but I want to draw chart and this is the only method I know. transanctions2.xlsx file is created but it is corrupted whereas bunch of errors do come up. from openpyxl.chart import BarChart, Reference wb1 = xl.load_workbook('transactions.xlsx') sheet = wb1['Sheet1'] cell = sheet.cell(1, 1) for row in range(2, sheet.max_row + 1): cell = sheet.cell(row, 3

openpyxl chart error bar styles

不羁岁月 提交于 2019-12-01 11:32:26
问题 I've been assigned a "simple" task of collecting series of data columns to a results workbook. The results workbook contains necessary formulas and charts to analyze the results. The data is generated by an image analysis application I've written in python as series of excel workbooks. Now the problem is that openpyxl drops any existing charts in excel workbooks. I've spent the day figuring out how to use openpyxl charts for which there is some documentation and chart errorbars for which

openpyxl.load_workbook(file, data_only=True doens't work?

99封情书 提交于 2019-12-01 11:07:49
Why does x = "None" instead of "500"? I have tried everything that I know and searched 1 hour for answer... Thank you for any help! import openpyxl wb = openpyxl.Workbook() sheet = wb.active sheet["A1"] = 200 sheet["A2"] = 300 sheet["A3"] = "=SUM(A1+A2)" wb.save("writeFormula.xlsx") wbFormulas = openpyxl.load_workbook("writeFormula.xlsx") sheet = wbFormulas.active print(sheet["A3"].value) wbDataOnly = openpyxl.load_workbook("writeFormula.xlsx", data_only=True) sheet = wbDataOnly.active x = (sheet["A3"].value) print(x) # None? Should print 500? From the documentation openpyxl never evaluates