tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.43k stars 402 forks source link

Do Excel files not support Chinese path? #724

Open zhjr2019 opened 7 months ago

zhjr2019 commented 7 months ago
#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 commented 7 months ago

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.