openpyxl

How to read merged cells in python using openpyxl?

╄→尐↘猪︶ㄣ 提交于 2020-01-16 09:07:12
问题 I'm trying to read data from the excel file that has merged_cells_range... but the output is not my goal. Pls help me out import openpyxl wb = openpyxl.load_workbook('book1.xlsx') sheet = wb.get_sheet_by_name('info') all_data=[] print(sheet.merged_cells.ranges) for row_index in range(1,sheet.max_row+1): row=[] for col_index in range(1,sheet.max_column+1): vals = sheet.cell(row_index,col_index).value if vals =='': for crange in sheet.merged_cells.ranges: rlo,rhi,clo,chi = crange if rlo<=row

Openpyxl: Determining which character in a cell value is strikethrough

隐身守侯 提交于 2020-01-15 03:15:08
问题 I'll first mention that I'm using Python 2.7 and Openpyxl 2.4.1 Essentially I have a sheet in a workbook that I'm cleaning. I'm going through each cell and checking if there is Strikethrough text. Assume I'm looking in Column A: for i in range(1, sheet.max_row+1): my_cell = sheet['A'+str(i)] if my_cell.font.strikethrough == True: #here's the tricky part I know that it is possible to determine whether or not a cell contains strikethrough characters, but I would like to find which characters in

openpyxl - populating a column using a list

别来无恙 提交于 2020-01-14 14:46:29
问题 So I have been trying to use openpyxl with my Python 3.5 project to produce an excel file that has the top row(B1 to M1) being Months and the column(A2 to length of list) being items from a list I have. Now I can get the top row working fine using this: for row in ws1.iter_rows('B1:M1'): counter=0 for cell in row: cell.value = months[counter] counter=counter+1 However I cannot use the same method to populate the column. I have tried: for row in range(2, 1 + len(firstNameList)): test=0 for col

openpyxl - populating a column using a list

守給你的承諾、 提交于 2020-01-14 14:46:11
问题 So I have been trying to use openpyxl with my Python 3.5 project to produce an excel file that has the top row(B1 to M1) being Months and the column(A2 to length of list) being items from a list I have. Now I can get the top row working fine using this: for row in ws1.iter_rows('B1:M1'): counter=0 for cell in row: cell.value = months[counter] counter=counter+1 However I cannot use the same method to populate the column. I have tried: for row in range(2, 1 + len(firstNameList)): test=0 for col

openpyxl - populating a column using a list

女生的网名这么多〃 提交于 2020-01-14 14:46:06
问题 So I have been trying to use openpyxl with my Python 3.5 project to produce an excel file that has the top row(B1 to M1) being Months and the column(A2 to length of list) being items from a list I have. Now I can get the top row working fine using this: for row in ws1.iter_rows('B1:M1'): counter=0 for cell in row: cell.value = months[counter] counter=counter+1 However I cannot use the same method to populate the column. I have tried: for row in range(2, 1 + len(firstNameList)): test=0 for col

How to save in openpyxl without losing formulae?

自闭症网瘾萝莉.ら 提交于 2020-01-14 13:43:07
问题 Because I need to parse and then use the actual data in cells, I open an xlsm in openpyxl with data_only = True . This has proved very useful. Now though, having the same need for an xlsm that contains formuale in cells, when I then save my changes, the formulae are missing from the saved version. Are data_only = True and formulae mutually exclusive? If not, how can I access the actual value in cells without losing the formulae when I save? When I say I lose the formulae, it seems that the

Openpyxl “Numbers Stored as Text”

被刻印的时光 ゝ 提交于 2020-01-14 10:38:10
问题 I've done some extensive searching on StackOverflow as well as many other sites and can't seem to find a solution that will work for me. Background: - New to Python (and coding in general) - Using Pycharm w/ Openpyxl - I work a lot in Excel and have been trying to automate some small daily tasks using python to increase my understanding of the language Situation: - I am trying to modify an existing xlsx sheet, and have been able to successfully change formatting like column width, zoom, etc.

openpyxl chage font size of title & y_axis.title

谁都会走 提交于 2020-01-14 10:09:06
问题 I am currently struggling with changing the font of y axis title & the charts title itself. I have tried to create a font setting & applying it to the titles - with no luck what so ever. new_chart.y_axis.title = chart_dict['y_title'] ft = Font(name='Calibri', size=11, bold = False, italic = False, vertAlign = None, underline = 'none', strike = False, color = 'FF000000') new_chart.y_axis.title.font = ft Is there any easy setting for this - like: chart.y_axis.title.some_size_attrib = 12 or am I

Python: Openpyxl outputs “None” for empty cells

℡╲_俬逩灬. 提交于 2020-01-14 06:23:11
问题 The below code should go through directories, open files, convert etc. The thing is when a cell is empty, the resulting CSV file outputs "None" in its place. Any reason why and can this be remedied? Thanks import os from openpyxl import load_workbook import csv for subdir, dirs, files in os.walk("C:\Users\Alan\Downloads\Knowledge\HOW DO I"): for file in files: filepath = subdir + os.sep + file wb = load_workbook(filename=filepath) sh = wb.active your_csv_file = open(filepath.replace(".xlsx","

Python openpyxl read until empty cell

限于喜欢 提交于 2020-01-14 03:00:09
问题 I'm trying to read one column out of my Excel-file until it hits an empty cell, then it needs to stop reading. My code so far: import openpyxl import os def main(): filepath = os.getcwd() + "\test.xlsx" wb = openpyxl.load_workbook(filename=filepath, read_only=True) ws = wb['Tab2'] for i in range(2, 1000): cellValue = ws.cell(row=i, column=1).Value if cellValue != None: print(str(i) + " - " + str(cellValue)) else: break; if __name__ == "__main__": main() By running this i get the following