openpyxl

Adding a text box to an excel chart using openpyxl

不羁岁月 提交于 2020-01-05 04:52:28
问题 I'm trying to add a text box to a chart I've generated with openpyxl, but can't find documentation or examples showing how to do so. Does openpyxl support it? 回答1: I'm not sure what you mean by "text box". In theory you can add pretty much anything covered by the DrawingML specification to a chart but the practice may be slightly different. However, there is definitely no built-in API for this so you'd have to start by creating a sample file and working backwards from it. 回答2: I also haven't

Write formula to Excel with Python error

喜欢而已 提交于 2020-01-05 04:09:13
问题 I try to follow this question to add some formula in my excel using python and openpyxl package. That link is what i need for my task. but in this code : for i, cellObj in enumerate(Sheet.columns[2], 1): cellObj.value = '=IF($A${0}=$B${0}, "Match", "Mismatch")'.format(i) i take an error at Sheet.columns[2] any idea why ? i follow the complete code. i have python 2.7.13 version if that helps for this error. ****UPDATE**** COMPLETE CODE : import openpyxl wb = openpyxl.load_workbook('test1.xlsx'

Python script erroneously erases created chart in .xlsx file

让人想犯罪 __ 提交于 2020-01-04 13:36:51
问题 I tried to write a script using Python which takes some specific values from all the .csv files stored in a hierarchy of folders. These values are copied at some specific cells in a destination file (.xlsx) which has already been created. The destination file also has some existing empty charts (in separate sheets) which are to be populated with the values provided by the script. Unfortunately, after I run the script, although it works and I have the desired values copied in the cells, for

Python script erroneously erases created chart in .xlsx file

强颜欢笑 提交于 2020-01-04 13:36:15
问题 I tried to write a script using Python which takes some specific values from all the .csv files stored in a hierarchy of folders. These values are copied at some specific cells in a destination file (.xlsx) which has already been created. The destination file also has some existing empty charts (in separate sheets) which are to be populated with the values provided by the script. Unfortunately, after I run the script, although it works and I have the desired values copied in the cells, for

Py2Exe openpyxl importerror

旧城冷巷雨未停 提交于 2020-01-03 19:08:36
问题 I have a python application that depends on openpyxl and works well when running it through the python interpreter. However, when creating an exe with py2exe. The exe was generated but when I click on it I get an error and the following log is generated: Traceback (most recent call last): File "excelTest.py", line 1, in <module> File "openpyxl\__init__.pyc", line 30, in <module> File "openpyxl\workbook\__init__.pyc", line 5, in <module> File "openpyxl\workbook\workbook.pyc", line 16, in

Excel数据读取

怎甘沉沦 提交于 2020-01-03 14:28:19
一、openpyxl和excel的介绍 1、安装openpyxl模块 pip install openpyxl 2、Excel中的三大的对象 workbook:工作簿对象 sheet:表单对象 cell:表格对象 3、 读写 Excel 表格中的数据 import openpyxl # 第一步: 打开工作簿(读取excel文件中所有的数据保存为工作簿对象) workbook = openpyxl.load_workbook( r"C:\project_14day_v1\cases.xlsx" ) # 第二步:选中表单对象 sheet = workbook[ "login" ] # 第三步:通过表单选中表格读取数据 # 1、读取内容 : 第五行,第 一 列 data = sheet.cell(row=5,column=1) print(data.value) # 2、写入内容 sheet.cell(row=7,column=3,value= '("","")' ) # 写入内容之后,一定要保存才会生效 workbook.save( r"C:\project_14day_v1\cases.xlsx" ) # 3、获取最大行和最大列 # 最大行 print(sheet.max_row) # 最大列 print(sheet.max_column) # 4、rows:按行获取所有的格子对象

Python dataframe illegal character error into 'ascii' codec decode error

人走茶凉 提交于 2020-01-03 05:41:08
问题 I am attempting to write a pandas dataframe to excel. Initially, I received openpyxl.utils.exceptions.IllegalCharacterError which I resolved with: def export_file(clients): clients = clients.applymap(lambda x: x.encode('unicode_escape'). decode('utf-8') if isinstance(x, str) else x) clients.to_excel('all_clients.xlsx') return() Which then resulted in: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 17: ordinal not in range(128) However, if i resolve the unicode error I

Openpyxl deleting cells

点点圈 提交于 2020-01-03 01:45:17
问题 i want to pick the last 20 items of a list copy them a new spreadsheet, and once copied i want to delete them from the first spreadsheet. i have the first part going (copy the last 20) but im not sure how to delete that cell so it doesnt appear as none after i save it. filtered = [-20:] how do i delete those 20 cells from the spreadsheet? def cell_values(somesheet): # extract the last 20 items from the worksheet filtered = [x for x in somesheet.rows if x is not None] last20 = filtered[-20:]

Python and openpyxl is saving my shared workbook as unshared

谁都会走 提交于 2020-01-02 20:45:38
问题 Using Python and openpyxl I have a code that goes into a workbook, adds a bunch of information to some cells every day, and then closes and saves it. My problem is that if this workbook is open the code doesn't work (obviously). By making the workbook shared(multiple users can edit at once) I can overcome this problem, however after the code runs once, python saves and then reverts it back to a closed, unshared workbook. Anyone know if openpyxl can save as shared? I'm not finding anything

pass openpyxl data to pandas

你。 提交于 2020-01-02 10:58:26
问题 I am splitting "full name" fields into "first name", middle name" and "last name" fields from data from an excel file. I couldn't figure out how to do that in pandas, so I turned to openpyxl. I got the variables split as I desired. But, since adding columns to openpyxl for the new fields is not easy, I thought I would pass the values to pandas. I'm generating the dataframe that I need when I run the code, but once I send the df to ExcelWriter, only the last row is added to the Excel file. The