mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-05-15 14:15:54 -06:00
[GH-ISSUE #148] Error generating an output .xlsx file with MSVC #122
Labels
No labels
awaiting user feedback
bug
cmake
cmake
docs
feature request
in progress
long term
medium term
medium term
pull-request
question
question
ready to close
short term
under investigation
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/libxlsxwriter#122
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @GBangala on GitHub (Feb 14, 2018).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/148
Originally assigned to: @jmcnamara on GitHub.
Hello,
I'm new here, so sorry if I'm doing wrong, and sorry in advance if it's my fault for doing something wrong.
Thanks for the lib, it's truly a great tool ! 👍
I had an olderversion of it working since September 2017, but I had to rebuild it to include the new features (such as data validation) and since I recompiled the last version (at the root (master branch) of the git repo), i have trouble generating an output files.
I mean : the c++ code builds and runs well and returns no error at all (err code = '0'), but the created outputfile is named "t" instead of "tutorial.xlsx". Plus, whenever I try to name it with a relative path like "..\myRelativePath\tutorial.xlsx", no output file is created at all, and the error code is '2'.
To build the libxlsxwriter, I tried :
or
or
Thanks in advance for your answers.
Best regards
@jmcnamara commented on GitHub (Feb 14, 2018):
There is an issue with MSVC where filenames get truncated to one character. However, the following function in the code should take care of that: https://github.com/jmcnamara/libxlsxwriter/blob/master/src/packager.c#L48
This is optionally
#defined in (with#ifdef _WIN32) so check to make sure it is being included.@GBangala commented on GitHub (Feb 14, 2018):
Hi,
Thanks for the quick answer !
I tried to look at the packager.c file and it's already defined and supposedly working.
To try it, I
#define _WIN32just before the#ifndefblock but the end program behaved the same at the end.@jmcnamara commented on GitHub (Feb 14, 2018):
In that case you will need to supply a sample app that demonstrates the issue along with full reproducible instructions on how to reproduce it. Otherwise l won’t be able to debug fix it.
@GBangala commented on GitHub (Feb 14, 2018):
Thanks for the answer.
Excuse me, as I'm still a newbie, I don't get what you want me to send :
@jmcnamara commented on GitHub (Feb 14, 2018):
I’m looking more for a series of steps to follow on how to reproduce it. For example how the code was generated with Cmake. How it is imported into MSVC. How it is linked to an app.
Also, as a first step can you verify in the debugger, or via a printed, that
_open_zipfile_win32()is actually being called.@GBangala commented on GitHub (Feb 14, 2018):
Thanks for taking time explaining me : Ok now I get it ! I'm doing it ASAP, then.
First the debugging step : by putting
printf()s all around the code, I can say : the function_open_zipfile_win32()is actually being called.@GBangala commented on GitHub (Feb 14, 2018):
So here is my step by step process
My plateform is a Windows 10, with MSVisualStudio 2017
BUILD ZLIB V1.2.8 :
In PowerShell
mkdir .\buildcd .\buildcmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX:PATH="D:/InstallLocation/Zlib_1_2_8"In MSVC15 through zlib.sln :
=> Build 'zlib.vcxproj'
=> Build 'RUN_TESTS'
=> Build 'INSTALL'
which results in no error and all files moved to "D:/InstallLocation/Zlib_1_2_8"
BUILD LIBXLSXWRITER :
In PowerShell :
git clone https://github.com/jmcnamara/libxlsxwriter.git .mkdir .\buildcd .\buildcmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX:PATH="D:/InstallLocation/LibXLSXWriter" -DZLIB_ROOT:STRING="D:/InstallLocation/Zlib_1_2_8"In MSVC15 through xlsxwriter.sln :
=> Build 'xlsxwriter.vcxproj'
=> Build 'INSTALL'
which results in no error and all files moved to "D:/InstallLocation/LibXLSXWriter"
LINK MY PROJECT :
In MSVC15 :
-> additional include directories : D:\InstallLocation\LibXLSXWriter; D:\InstallLocation\LibXLSXWriter\include;
-> additional lib directories : D:/InstallLocation/LibXLSXWriter/lib/x64/;
D:\InstallLocation\Zlib_1_2_8\lib;
-> additional dependencies : Debug\xlsxwriter.lib; zlibd.lib;
I did to put
printf("debug _open_zipfile_win32()");in the packager.c code to be sure that the function would be called :-> rebuilt "xlexwriter.vcxproj" -> rebuilt "INSTALL"
-> rebuilt "myProj" -> run -> the printed message appears.
I think I described all I did. Do you need more informations ?
@jmcnamara commented on GitHub (Feb 16, 2018):
Thanks for the detailed instructions. I was able to replicate the issue.
I need to debug it but as a workaround, change the following for that
zipOpen()is called instead of_open_zipfile_win32(). You can do that by changing the#ifdef _WIN32to something non-existentialist like#ifdef _WIN32_zzzz:https://github.com/jmcnamara/libxlsxwriter/blob/master/src/packager.c#L102
That will get your app working for non-utf8 filenames while I investigate further. Strangely the sample project that I provide doesn't have this issue: https://github.com/jmcnamara/MSVCLibXlsxWriter Note, however that that project isn't up to date with the latest release.
Anyway, I'll dig further.
@jmcnamara commented on GitHub (Feb 16, 2018):
@utelle could you have look at this to see why the
_open_zipfile_win32()isn't working as expected in libxlsxwriter.@jmcnamara commented on GitHub (Feb 16, 2018):
It looks like this may be the same issue, or at least similar, to #104
@jmcnamara commented on GitHub (Feb 16, 2018):
Following the clue in #104 I was able to get to this to work, unedited, by setting the following property for each of the zlib, libxlsxwriter and exe projects:
I'll look into how this can be enabled via cmake.
@utelle commented on GitHub (Feb 16, 2018):
As you found out for yourself it is necessary to set the Unicode property for all projects. Otherwise you experience the same issue as described in #104 - the filename is passed down as a wide string, but is then interpreted as an ANSI string, usually truncating the filename to just one character.
@GBangala commented on GitHub (Feb 19, 2018):
Wow thanks for the replies ! You guys rock !
I will test it later that day as I have a few works related appointments.
I'll let you know once it's done if everything works.
@GBangala commented on GitHub (Feb 19, 2018):
It works fine now ! It was all about specifying the "Unicode character set".
Thank' you very much @jmcnamara and @utelle for your help !
@RalfKubis commented on GitHub (Mar 12, 2018):
I just ran into the same issue with VS2015, non-unicode CMake build of libxslsxwriter.
The first problem I see is that the Doxygen documentation of libxslsxwriter apparently doesn't state the expected encoding of the string arguments of its functions parameters. Does this mean that it ALWAYS has to be utf-8, especially for workbook_new(..)?
Note:
If _open_zipfile_win32() would consider the UNICODE preprocessor define and would ONLY convert to wide-string if UNICODE is defined, the later call to CreateFileA(..) would work fine.
From other issues I've reviewed, I assume that a Win32 build of libxslsxwriter ALWAYS has to be performed with the UNICODE macro being defined and is completely unverified for a non-UNICODE build.
Is that correct?
If so, then the CMAKE integration should enforce the UNICODE build.
@RalfKubis commented on GitHub (Mar 12, 2018):
for example like this:
elseif(MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd /O0 /Fd${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb /DUNICODE") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT /Ox /Zi /Fd${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb /DUNICODE") set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MT /Zi /Fd${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb /DUNICODE") set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT /Fd${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb /DUNICODE") endif()@jmcnamara commented on GitHub (Mar 12, 2018):
@RalfKubis Agreed. You should open a separate issue for this and also if you have a fix then submit a Pull Request.
@jmcnamara commented on GitHub (Apr 23, 2018):
Fixed on master without need for specifically setting UNICODE.