openpyxl

Update rows and column using openpyxl from python

谁都会走 提交于 2019-12-11 10:47:08
问题 Problem: Add "(C)" or "(S)" in every column or row in an excel file by using openpyxl - python. Example of a patient record or list of exercises The list will have dozens if not hundreds of exercises for every (physical therapy) patient. Exercise Repetition Running 5 minutes Walking 10 minutes Squats 3x12 curls 3x12 .... ..... I want to add an indicator to the exercises: (C) for Cardio (S) for Strenght Note: There will be more indicators (~20). We have thousands of files of patients records

How to persist Excel References in formulas across worksheets where the worksheet is blank?

折月煮酒 提交于 2019-12-11 09:56:15
问题 Is it possible in Excel to create a template with formula to other named empty sheets such that the references to the cells always remain and don't end up like this? ='Data'!#REF! I am using python, pandas and openpyxl to populate multiple named worksheets with various pandas dataframes. The 1st, 2nd and 3rd sheets are templates with references to the other worksheets. Why is this required : If I have data in the template of say 10 rows and write a dataframe of 5 rows the remaining 5 existing

Openpyxl : need the max number of rows in a column that has data in Excel

我的梦境 提交于 2019-12-11 07:58:22
问题 I need the last row in a particular column that contains data in Excel. In openpyxl sheet.max_row or max_column gets us the maximum row or column in the whole sheet. But what I want is for a particular column. My scenario is where I have to get some values from database and append it to the end of a particular column in Excel sheet. In this screenshot, if I want max_column containing data in column 'C', it should return 10: In the above image if I want last cell containing data of column 'C',

Using Named Ranges in Excel with a selection of cells?

时光毁灭记忆、已成空白 提交于 2019-12-11 05:57:14
问题 Is it possible in Excel to use a defined named range such as myArray refers to =summary_data!$C$2:$H$6 Then use this name in another sheet to paste the contents of the data to a given range =summary_data!$C$2:$H$6 The reason to do this is that I am injecting data into other sheets in a template and the front sheet takes the data from many sheets. Currently I can do this with single cells using the following but defining each individual cell is tedious: =INDIRECT("'" &V1& "'!" & "summary_data

from openpyxl.styles import Style, Font ImportError: cannot import name Style

佐手、 提交于 2019-12-11 05:42:23
问题 While running a python code, I am facing the following error : sbassi-mbpro:FacebookEventScraper-master sbassi$ python facebook_event_scraper.py Traceback (most recent call last): File "facebook_event_scraper.py", line 13, in <module> from openpyxl.styles import Style, Font ImportError: cannot import name Style python -V Python 2.7.10 回答1: Looking at the source code for openpyxl.styles, the __init__.py file doesn't define any name: Style . Perhaps you were looking for NamedStyle instead? 来源:

Style Normal exists already - Python - OpenPyxl

為{幸葍}努か 提交于 2019-12-11 05:33:50
问题 I have looked into many stackoverflow questions but none of them seemed to solve my problem. I am using Python and Openpyxl to fill a whole row with red given a certain condition. I did all the importations necessary : from openpyxl.styles import PatternFill, NamedStyle, Color from openpyxl.styles.colors import RED And my code is the following : for cell in sheet[i]: cell.style = NamedStyle(fill=PatternFill(patternType='solid', fill_type='solid', fgColor=Color(RED))) When I ask to print the

TypeError: 'generator' object is not subscriptable, csv file

Deadly 提交于 2019-12-11 05:27:01
问题 I am getting the typeerror: 'generator' object is not subscriptable when trying to make lists of information in several csv files, sort them so that I get the information I need and put that information into a new .xlsx file. I am wondering if anyone here can help me with where I am going wrong. Is it the csv files that cannot be accessed or is there something wrong with my code? (I did not add the entire code, only the code where I get the error) Code: import csv import operator from

Differences between xlwings vs openpyxl Reading Excel Workbooks

孤者浪人 提交于 2019-12-11 05:23:30
问题 I've mostly only used xlwings to open ( read-write ) workbooks (since the workbooks I read have complicated macros). But I've recently begun using openpyxl to open ( read-only ) workbooks when I've needed to read thousands of workbooks to scrape some data. I've noticed that there is a considerable difference between how xlwings and openpyxl read workbooks. I believe xlwings relies on pywin32 to read workbooks. When you read a workbook with xlwings.Book(<filename>) the actual workbook opens up

Python/Pandas: Loop to append Excel files ONLY if each Excel file contains certain values

你离开我真会死。 提交于 2019-12-11 05:14:04
问题 I have the following code: dfs = [] for f in files_xlsx: city_name = pd.read_excel(f, "1. City", nrows=1, parse_cols="C", header=None, skiprows=1) country_code = pd.read_excel(f, "1. City", nrows=1, parse_cols="C", header=None, skiprows=2) data = pd.read_excel(f, "1. City", parse_cols="B:J", header=None, skiprows=8) data['City name'] = city_name.iat[0,0] data['City code'] = country_code.iat[0,0] dfs.append(data) df = pd.concat(dfs, ignore_index=True) I would like to run the loop if and only

Python make reading a Excel file faster

社会主义新天地 提交于 2019-12-11 03:56:22
问题 I made a script that reads an Excel document en checks if the first row contains "UPDATED". If so it writes the whole row to another Excel document with the same Tab name. My Excel document is 23 sheets with 1000 lines on each sheet, and now it takes more than 15 minutes to complete this. Is there a way to speed this up? I was thinking about multithreading or multiprocessing but i don't know which one is better. UPDATE: the fact that my program took 15 minutes to run was al caused by the READ