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

Do Excel files not support Chinese path? #724

Open
zhjr2019 opened this issue Dec 4, 2023 · 5 comments
Open

Do Excel files not support Chinese path? #724

zhjr2019 opened this issue Dec 4, 2023 · 5 comments

Comments

@zhjr2019
Copy link

zhjr2019 commented Dec 4, 2023

#include <xlnt/xlnt.hpp>
int main()
{
    xlnt::workbook fault_workbook;
    std::string fault_excel_file = "F:\\中国\\中国20220823224554.xlsx";
    fault_workbook.load(fault_excel_file);
    return 0;
}

error:bad conversion

Do Excel files not support Chinese path?

@doomlaur
Copy link
Contributor

I'm not sure which version of xlnt you are using, but if you're using version 1.5.0, you should maybe use the latest commit from the master branch instead. The issue you describe has been fixed by pull request #607 by using std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>. As explained on cppreference, the previous code converted UTF-8 to UCS-2 (the predecessor of UTF-16) on Windows, causing Unicode code points that need 4 bytes (like emojis) to fail. Unfortunately, the fix has not been released in a stable version of XLNT yet, but at least in my experience, the master branch seems to be even more stable than version 1.5.0, as it contains many bugfixes - so you should definitely give it a go.

@szfbit
Copy link

szfbit commented Oct 18, 2024

But when the file name contains Chinese, calling the workbook.load() function does indeed result in an error: std::range_error。
Upon checking the source code, it was found that the error occurred at the following location:xlocbuf _Throw(range_error("bad conversion")).
If possible, please fix it!Thank you.

@doomlaur
Copy link
Contributor

As discussed in issue #748, this repo has been unmaintained for several years.

In order to continue this great project started by tfussell, we have created a new repo to support further development by the community.

Furthermore, specifically regarding this issue, I have changed the way Unicode conversions are done in Pull Request xlnt-community#29. So @szfbit could you please clone our new fork, build XLNT using the newest commit of our master branch, and tell me if it solved your problem? If not, feel free to open an issue in our new repo with a detailed example that causes the issue you described. Thank you!

@szfbit
Copy link

szfbit commented Oct 18, 2024

Hello, thank you for your reply! My problem has been solved now, just change the encoding format of the source code from GBK to UTF8. I will continue to monitor the new code repository, keep up the good ! @doomlaur

@doomlaur
Copy link
Contributor

@szfbit Perfect, I'm glad to hear that! 😄 Using UTF-8 is always a great idea 😉 However, if you think that the conversion error is also an issue with XLNT, feel free to open an issue in our new repo so that we can take a closer look at it!

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

No branches or pull requests

3 participants