Comments (2)
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.
For the record: all conversion functions provided by the C++ Standard library have been deprecated in C++17. Since wide strings are only used on Windows, your solution is a very good alternative 👍 In fact, I'm already using that in some projects. To avoid the memory leak at the end of your code snippet (the wchar_t
array never gets deleted) and to avoid copying unnecessarily, the alternative to std::wstring_convert
could be the following (slightly adapted version of your code):
#ifdef _MSC_VER
#include <stringapiset.h>
std::wstring path::wstring() const
{
const std::string & path_str = string();
int size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path_str.c_str(), static_cast<int>(path_str.length()), nullptr, 0);
if (size > 0)
{
std::wstring path_converted(size, L'\0');
size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path_str.c_str(), static_cast<int>(path_str.length()), path_converted.data(), size);
return path_converted;
}
else
{
return {};
}
}
#endif
from xlnt.
Wow.Thank you for your reply. Your code has taken into account a memory leak issue that I did not consider. Based on your explanation, I have also learned a lot. Finally, thank you again
from xlnt.
Related Issues (20)
- Loading file fails with error: attribute 'localSheetId' expected HOT 4
- Parse error!(xlnt::exception : bad cell coordinates: (#REF!))
- This is really a good library for xlsx, but the document may need improved?
- number_serialiser::deserialise returns wrong result due to buffer not being null terminated
- Unexpected attribute 'ca' when working with formular in xlsx file.
- Is it possible to write a whole record i.e std::vector<std::string> into the xlnt::worksheet instead of writing cell by cell?
- Throw "counts don`t match" exception HOT 1
- How do I insert a picture as embedded in a cell ? HOT 1
- When string tables entries exceed 1000, a ',' is being inserted in the string table number, resulting in errors opening file HOT 1
- C++23 aligned storage deprecation warning
- Reference counting issues with xlnt::format_impl
- Do Excel files not support Chinese path? HOT 1
- Fresh release HOT 2
- Errors when try to use in Windows
- Crash on Release HOT 1
- Cloning project failed HOT 1
- Read xls file? HOT 1
- password
- error in Add Password: wb.save("lots_of_properties.xlsx","password");
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xlnt.