Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StyleFrame.read_excel ignores merge cells #76

Open
nddeshmukh1610 opened this issue Jul 14, 2020 · 4 comments
Open

StyleFrame.read_excel ignores merge cells #76

nddeshmukh1610 opened this issue Jul 14, 2020 · 4 comments

Comments

@nddeshmukh1610
Copy link

Hi Team,

trying to read excel having few merged cells, noticed StyleFrame.read_excel ignores merge cells

Python 3.8.3
StyleFrame 3.0.2
openpyxl 3.0.2
pandas 1.0.5

Any fix or workaround ?

Thanks,
Nandlal

@DeepSpace2
Copy link
Owner

Hi.
StyleFrame.read_excel uses pandas.read_excel, and they provide a very similar output when dealing with merged cells.

Consider the sheet:

image

Then reading with both pandas.read_excel and StyleFrame.read_excel we get a very similar output:

df = pd.read_excel('merged_cells_test.xlsx')
print(df)
sf = StyleFrame.read_excel('merged_cells_test.xlsx')
print(sf)

outputs

     a     b
0    1   6.0
1    2   7.0
2  3 8   NaN
3    4   9.0
4    5  10.0

     a     b
0    1   6.0
1    2   7.0
2  3 8   nan
3    4   9.0
4    5  10.0

If you notice any different behavior please add some more information, such as how the sheet you are trying to read looks like and what dataframe you get after reading.

@nddeshmukh1610
Copy link
Author

Hi,

I appreciate your quick response.

I need to preserve the Style (cell color, format, merged cells, header format, etc.) when I'm merging two excels.
I understood we can do it using StyleFrame.read_excel(filename,0, read_style=True)

but while reading excel using StyleFrame.read_excel(filename,0, read_style=True) we are not able to preserve the merged cells.

Sample input has below content

image

But StyleFrame.read_excel(filename,0, read_style=True) reading it as

image

Is there any way to read the excel with preserving merged cell ?

Thanks,
Nandlal

@DeepSpace2
Copy link
Owner

DeepSpace2 commented Jul 17, 2020

As a temp workaround, I created a temp branch that will preserve merged cells data when using read_style=True then to_excel().save(), but it still does not allow to merge/unmerge arbitrary cells. It will only preserve merged cells from the file that is being read.

You can give it a try by pip installing from the branch directly:

pip install -U git+https://github.com/DeepSpace2/StyleFrame@preserving-merged-cells

@nddeshmukh1610
Copy link
Author

Hi team,

thanks for your kind help, I have tested enhancement and it is working as expected.

regards,
Nandlal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants