You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library is awesome! I'm using it a lot since it makes working with Excel files very simple.
I have a proposal: Allow the user to specify the sheet they want to modify.
I write a lot of functional programming and I can't remember if it's possible to overwrite a class function at import, so instead I've modified the sheet2dict to return a specified sheet when openpyxl opens the file.
in main.py:
defxlsx_to_dict(self, path, select_sheet=None):
""" Read a Worksheet and return it as array of dictionaries :param self: Worksheet Object :param path: Path to XLSX file :return: Array of rows as dictionaries """book=load_workbook(path)
ifselect_sheet==None:
sheet=book.activeelse:
sheet=book[select_sheet]
I don't know if this is the most elegant way to select a sheet, but it works for me.
I suppose to import all worksheets by default - I think the maximum is 32 - into a larger dictionary, <edit I didn't complete my thought>, that there could be a clever way to put dictionaries in dictionaries, but this might be too convoluted since I assume most users will just use one sheet.
Another option is just to continue creating Worksheet() objects with different names and sheets selected.
The text was updated successfully, but these errors were encountered:
Actually, this is a good idea @bai-yi-bai! I also thought about it a long time ago :)
I think the style in which you wrote the example code is fine 👍
I tested it and this way we wouldn't break anything in the code ⚡️
If you want to do PR, please do it and we can then merge it into sheet2dict.
Many thanks 🙏
I also created another test Excel file for testing and everything looked fine. I think I created the pull request correctly from PyCharm/Github on my personal PC. I'm excited to replace the version on my work PC.
BTW, I found my way here from the post on HackerNews a few weeks ago.
This library is awesome! I'm using it a lot since it makes working with Excel files very simple.
I have a proposal: Allow the user to specify the sheet they want to modify.
I write a lot of functional programming and I can't remember if it's possible to overwrite a class function at import, so instead I've modified the sheet2dict to return a specified sheet when openpyxl opens the file.
in main.py:
The user would then read an Excel file like this:
I don't know if this is the most elegant way to select a sheet, but it works for me.
I suppose to import all worksheets by default - I think the maximum is 32 - into a larger dictionary, <edit I didn't complete my thought>, that there could be a clever way to put dictionaries in dictionaries, but this might be too convoluted since I assume most users will just use one sheet.
Another option is just to continue creating Worksheet() objects with different names and sheets selected.
The text was updated successfully, but these errors were encountered: