So I have excel files with several sheets in each and I'm working on script which will gather data from selected sheets if they exist in file and combine it in one, big sheet. Generally it's working, iterating through files and if desired sheet exist it finds range of cells with data and append it to dataframe. The thing I need to do now is to add header row (column names) to Dataframe, but in sheet those are multiline headers.
To make it look the same in dataframe i need to unmerge cells in top header row and copy value from first cell to rest of them in range which was merged before).
I'm using OpenPyXL for accessing excel sheets. My function receives sheet to work on as only parameter. It looks like this:
def checkForMergedCells(sheet):
merged = ws.merged_cell_ranges
for mergedCell in merged:
mc_start, mc_stop = str(mergedCell).split(':')
cp_value = sheet[mc_start]
sheet.unmerge_cells(mergedCell)
cell_range = sheet[mergedCell]
for cell in cell_range:
cell.value = cp_value
The thing is that cell_range returns a tuple which ends up in getting error message:
AttributeError: 'tuple' object has no attribute 'value' Below you can see screencap during debug which shows values passed in each variable.