-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Fix UnicodeDecodeError in some VBA file handling #2380
base: main
Are you sure you want to change the base?
Conversation
Thanks! Can you also provide instructions on how to reproduce this issue? See also #2335 |
Hey @fzumstein Thank you for following up on the pull request. Regarding the UnicodeDecodeError issue with xlwings, I encountered it while working on a large VBA project in my professional environment. Initially, I focused on resolving the issue directly as it was impacting our workflow, rather than setting up a detailed reproduction scenario. However, I believe the problem arises when handling VBA files with specific Unicode characters that are not encoded in UTF-8, especially in large projects where various encoding standards might have been used over time |
were you using files that were exported outside of xlwings? |
To clarify, the files I encountered the issue with were indeed part of a larger VBA project, and some of these files may have been exported or edited outside of xlwings before being reintegrated into the project. This mixed handling could be a contributing factor to the encoding discrepancies leading to the UnicodeDecodeError. |
Right, in this case I think it's fair to expect that the user has to use xlwings to do the initial export though. The way you have it now is just covering your specific use case, it wouldn't work for this case: #2335 |
A command line switch for specifying encoding, offers greater flexibility for individual files. Based on my project structure there are some modules using utf8 some using cp932 or LATIN-1 I understand this introduces additional complexity but it might be necessary to ensure robust handling of diverse and collaborative VBA projects. |
Hello,
Is there anything I can do to resolve this problem? |
@zwackelfuss if you can attach a sample workbook to replicate the issue, that would help. Also, if you can report your machine's locale: |
Hello, first time here 👋 I'm running |
I was able to get the export working when setting the reading part of cli.py>vba_edit to Line 867 with open(path, "r", encoding="ISO 8859-1") as f: |
Summary
This pull request addresses the issue where
xlwings
encounters aUnicodeDecodeError
when handling VBA files with encodings other than UTF-8. The proposed changes add a multi-encoding read strategy to theexport_vba_modules
,vba_edit
, andvba_import
functions incli.py
, allowingxlwings
to handle files with different encodings such as 'ISO-8859-1' and 'cp1252', alongside the default 'utf-8'.Changes
export_vba_modules
,vba_edit
, andvba_import
functions to try reading files with 'utf-8', 'ISO-8859-1', and 'cp1252' encodings.UnicodeDecodeError
if all encodings fail, providing clear feedback.Justification
These changes enhance the robustness of
xlwings
in handling VBA files with various encodings, which is a common scenario in diverse environments. It ensures smoother functionality and reduces the likelihood of runtime errors due to encoding issues.Testing
The modifications have been tested in various scenarios to ensure compatibility and functionality across different file encodings.