Hi, I apologize for taking a long time to answer - I had problems with free time. You probably need a solution something like this: #include <map> #include <string> #include <Xlsx/Workbook.h> using namespace SimpleXlsx; class CWrapper { public: // create a sheet void AddSheet( const std::string & sheetTitle ) { CWorksheet & Sheet = m_book.AddSheet( sheetTitle ); m_Sheets[ sheetTitle ] = & Sheet; } // add data to the created sheet void AddData( const std::string & sheetTitle, int data ) { std::map<...
Hi, Thank you for your offer. Can you explain in more detail what is difficult about creating your wrapper class? Now you can create a worksheet using the CWorkbook::AddSheet method and get a reference to the new CWorksheet (you can get a pointer from this reference). This reference to the CWorksheet (and the pointer obtained from it) is correct until the end of the life of the CWorkbook object or the save of the workbook. This library was originally designed to fast save large amounts of data. Because...
Ok, thanks for understanding. If you have any difficulties with modifying the library, write here, I will try to help.
Thank you for the research and its detailed description. In general, you have discovered what E.Naumovich and I wrote about earlier. I think its OK to use 999999 to avoid recalculation due to newer Excel client program version. I think it's a dirty hack. Today it can work, and tomorrow an Excel update will be released with a detailed check of this value and when opening the file, a message will appear that the xlsx file is corrupted. It is not necessary to assume that Excel does not check parameter...
"...but there are no guarantee concerning third party software. I have strange issues with some." Is this software available for free? Can you provide examples of such software and corresponding xlsx files? I'm trying to improve the compatibility of the files generated by SimpleXlsxWriter. It may be possible to improve this situation further.
Hello everyone and thanks to Alexander Arkhipov for the detailed description of the problem. E.Naumovich is right with the cause and, I think, right with the proposed solution. The fact is that Excel saves a cache with the results of formula calculations in the xlsx file. This is necessary to speed up the work. SimpleXlsxWriter does not contain a formula calculator and does not fill in the corresponding cache in the xlsx file. There are no plans to add a formula calculator to the library yet. Therefore,...
Tony, thanks for testing. E.Naumovich, thank you for solution using the ScratchTable.
Hi, Thanks for the good question! :-) I was waiting for a response from Tony and forgot to post the release. Done. Thank you for reminding!
Removed initializing parameters for CWorksheet (since version 0.40) because found other solution.
Preparing and saving of the sheet is carried out in one pass, as before. Only now, after saving the sheet to a file, this file is opened as a binary file and several bytes are replaced in it. These bytes are a string with a dimension. This method of modifying data should be fast and memory efficient.
This turned out to be a feature of Visual Studio. Please check the updated archive.
It seems I have found a solution. First, "A1" is written to the dimension attribute in the XML file, then many spaces are added. Additionally, the position in the XML file is saved. This format suits for Excel 2010. After the XML file is saved, it reopens and overwrites the value of the dimension attribute. If it's not difficult, check the work of the updated library for yourself. Excel should open files correctly. Tony, do you read XML files yourself or do you use some special library for Excel...
Yes, these mods are already official.
I apologize for not answering at all due to lack of free time. I think that E.Naumovich suggested the best solution and it should be the main one.
Initializing parameters for CWorksheet and function GetDim to scratch sheet
Thank you for your solution. It can help some people. But I will not include it in the main code, as this will contradict one of the main features of this library: "The main feature of this library is that it uses C++ standard file streams. On the one hand it results in almost unnoticeable memory and CPU resources consumption while processing (that may be very useful at saving a large data arrays), but on the other hand it makes unfeasible to edit data that were written.". Thank you again for your...
I think it's a good idea. If I understand correctly, then for this it is necessary to use the initial part of the clsScratchTable::InsertTo function to obtain the data area range? The CWorksheet::SParams structure may be extended in the future as many more parameters are hard-coded.
Hi Tony, I tried to do automatic detection of the data area. Due to the specifics of the library implementation, the "dimension" tag was added after the data itself. This is correct for XML files, but Excel 2010 gave a message about a corrupted file. Therefore, I had only one option left - through additional parameters when creating a CWorksheet (the CWorksheet::SParams structure). To do this, you need to know the size of the data area in advance. Please check if this option is suitable for you....
Hi Robert, Example "Scientific.cpp " it was created in order to show what possibilities there are for creating diagrams. I think you are right and I need to rework this example as you suggested. Thank you for your patience and the work done. Work with fonts and format can be found in "Simple.cpp ". The range of axes can be set using functions like CChart::SetXAxisMin and CChart::SetXAxisMax, CChart::SetYAxisMin and CChart::SetYAxisMax.
Hi Robert, Perhaps there is some feature of working with Xcode and nested directories. Maybe a similar problem is described here (see the most popular answer)? https://stackoverflow.com/questions/21958759/subfolders-in-xcode-linking #include "../UTF8Encoder.hpp" should work correctly. At least I tested it under Linux and Windows with the GCC compiler.
Hi, Thanks again for the detailed information. If it doesn't bother you, attach the compiler output here after building the project. Maybe I can eliminate some compiler warnings. If you are very concerned about compiler messages, then you can compile the library separately using CMAKE and use resulting object file to your project. It will also speed up the build of your project. I also want to note that Microsoft Excel is not required to use this library.
Hi, unfortunately, there is not enough time to prepare a User Guide. Excuse me. Please see the examples of using the library in the archive with the source code. If you have any questions, feel free to ask.
It looks like the cpp files from the directories "scratch", "Xlsx", "XLSXColors" and "Zip" are not compiled. Have all cpp files been added to the Xcode C++ Project?
Hi, Thanks for your kind words and detailed explanation. It looks like the linker doesn't see the library's object files. Can you see the object files "Worksheet.o" or "Workbook.o"? Are they in the same directory as "main.o" ? Maybe they are in different directories and you need to specify them explicitly to the linker.
Hi, Done :-) Thanks for your help!
Added scratch
Redesigned function CWorkbook::Save
Hi, Sorry for the long silence for various reasons. Perhaps is the problem related to antivirus software or similar security software? Just in case, I redesigned the library to call the fclose function directly. Please check if possible.
Hi, I apologize for the long silence, I had problems accessing the site. Why did you decide that zip does not close file if it was open using handle from fopen on Windows? I tried such a simple test: CWorkbook book( "Incognito" ); ... FILE * f = fopen( "Test.xlsx", "w" ); if( f == NULL ) { std::cout << "The book saving has been failed" << std::endl; return 0; } book.Save( f, true ); std::cout << "The book has been saved successfully" << std::endl; while( true ) ; When the program is in an infinite...
Добрый день! Нужно использовать NUMSTYLE_NUMERIC вместо NUMSTYLE_GENERAL.
Added scratch sheet with matrix-type access to cells (writing only)
Hi, Thanks for the clarification and addon update. A little later I will update the library and add the "scratch" directory as you mentioned. Do you mind if I add a zlib license with your authorship to the files? I can also do this for "XLSXColors". About the union. According to https://en.cppreference.com/w/cpp/language/union "The union is only as big as necessary to hold its largest data member. The other data members are allocated in the same bytes as part of that largest member." Therefore, the...
Hi, Thanks for the great work! Your add-on can help many developers. I have a question: why is "clsCell::bf[8]" needed? Isn't it better to use the "utv" and "wtv" fields directly? It will also be more transparent. I took the liberty of adding the ability to compile under Linux. To do this, I added macros wherever the "SYSTEMTIME" type is used. And also changed the type "WORD" to "uint16_t" for "clsCell::bf[8]" (this is allowed, according to https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types)....
Hello CARLOS EDUARDO PIRES DE SÁ, Thanks for the feedback. What version of the compiler and its launch options? What version of the operating system? Can you provide a minimal example of a program with such an error?
Was happy to help. I also thought it would take a lot of time :-)
Improving charts
Hi, There should be no fundamental restrictions. What is your problem? Do examples from the archive with the library work?
Hi, I must apologize for not having replied. Last time I had no free time at all and I forgot about this discussion. The attachment contains an updated version of the library. It has a function: bool CWorkbook::Save( FILE * HF, bool CloseHandleAfterSave ); The last parameter determines who should close the handle.
Hi, Please check the latest version of the library from the attachment. You need a function call: chartSheet1.Chart().SetXAxisType( CChart::EAxisType::AXIS_DATE ); You may also find this function useful: chartSheet1.Chart().SetXAxisFormatCode( "dd\\.m" ); Axis markers have also been added. Check out the new example "MixedLineAndBarChart.cpp". Thanks for waiting :-)
Hi, thanks for the detailed description of the problem. This requires a special axis category - the date axis. Unfortunately, the library does not currently support this. I can try adding such an axis. But it will take more than one day.
Thanks for your solution and an example of using it. Would you mind if I tweak your code a bit to be usable on Linux? Let me ask a few questions: 1) Perhaps in the "template <...> clsCell::Set" function need to pass the value of the "_v" by a constant reference? This can be useful when passing std::string or std::wstring. 2) Perhaps the clsCell::SetLongIntT function was not finished and the clsCell::SetLongUIntT function was also planned? 3) Perhaps the "if (Style! = 0)" checks should be removed...
Thanks for the clarification. It will be great if you can find the time for such an example. Then your example and this explanation might help many library users.
Please clarify: did you create such a scratch sheet before creating the xlsx-file via SimpleXlsxWriter , or are you filling it out from an existing xlsx-file?
Hi, No, it’s impossible. For an alternative, please see these topics: https://sourceforge.net/p/simplexlsx/discussion/general/thread/d6605d2b6c/ https://sourceforge.net/p/simplexlsx/discussion/general/thread/8e8c670b/
Hi, Thanks for your example! In a hurry, I did not find the "fileno" function, so I got different versions of the "Save" function. Shame on my head :-) I have attached an updated library. Also added an example of a mixed chart with a line and a bar serieses.
Hi, Please see the attached example.
Hi, Thank you for your desire to understand the problem. And sorry for the long silence, I had no free time at all. Thanks for the suggestion to add a new Save function, I did it. In an attachment the updated library. The only thing is that we have different functions for Windows and Unix. This is due to the internal organization of the zip archiver.
Hi, Thanks for the info. It is difficult to say what exactly could be the reason. The library uses the system temporary directory, and, prior to version 0.36, request a username in the system (if not specify it manually in the code). Also, the zip archiver calls system functions for working with files.
Hi, No, Excel create a chart after opening xlsx-file and does not save it as an image.
Fixed crash when operating system returns NULL instead of username
Thank you for such complete information! You completely solved the problem :-) In the attachment is an updated version of the library. I also moved the request username from CWorkbook class constructor to function GetSystemUserName(long been a wish). Thanks again for your help.
Hello, Unfortunately, I don't have permanent access to the Mac, so I need your help. Can you run the program under debugger and show a screenshot with the crash point (inside the SimpleXlsx::CWorkbook constructor) and values of variables? Thanks
Fixed undefined behavior with cells ranges for chart serieses
Hi Sergio, Thanks for the information about the VS2019. This information helped to find and fix the bug. Please test the updated library from the attachment and let me know the results of your testing. Thank you again.
Hi, I just pasted your code in "MultiCharts.cpp" and everything works. Please see the attachment. Most likely the problem is in "CorrelArr". Make sure that its size is at least 15 elements and all elements have a finite value (not NaN, not Inf). Also check the values of the first two rows on the first sheet of created xlsx -file. If the problem persists, please attach your minimal non-working example and the created xlsx-file. P.S. For safety, use the "DataCellCount" in the loop below it.
Full declaration for CSheet in DefinedNAme struct.
Added defined names and redisigned CellDataTime class.
Thank you again for the idea and testing! By the way, I reworked the CellCoord::ToString method and now it is up to three times faster than the old version (case with std::string).
Hi, Perhaps you made a mistake with the project site? The C++ library SimpleXlsxWriter is discussed here :-)
I modified your first proposition and left it for now. In the attachment is an updated version of the library with support for defined names. I would appreciate your testing and comments. A small example: #include <iostream> #include <Xlsx/Workbook.h> using namespace SimpleXlsx; int main() { CWorkbook Book( "Incognito" ); CWorksheet & Sheet = Book.AddSheet( "Sheet 1" ); CWorksheet & SecondSheet = Book.AddSheet( "Sheet 2" ); Book.AddDefinedName( "HalfRad", 0.5, "Half radian" ).AddDefinedName( "MySin",...
Thanks for explanation and example. I will try to add this feature soon.
Hi, Thanks for the proposal. Do I understand correctly that this modification for CChart::CellRangeString method? is it possible to assign "names" for the cells? Please clarify this idea. Do you want to write a value in a cell by its name (for example, "B3")?
Hi Meena, As far as I know, Excel recalculates the column width at the user's command. But it does not have a permanent property to recalculate the column width. Correct me if I'm wrong. Therefore, the library does not have property like a autosize/autofit column.
Thank you for your ideas and testing :-)
The attachment has an updated example. Please pay attention to the generated xlsx-file in the section "Direct date and time". If the time specified is accurate to milliseconds, and the style is selected without milliseconds, then Excel rounds the milliseconds to the nearest second. I think this can be confusing for users.
Your proposition is good, I added such functionality. I also added the ability to use the QDateTime class from the Qt framework.
I modified the library, a new version in the attachment. I will be glad to any feedback from you. Please see this example. #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <vector> #include <Xlsx/Workbook.h> using namespace SimpleXlsx; int main() { setlocale( LC_ALL, "" ); time_t CurTime = time( NULL ); CWorkbook book( "Incognito" ); std::vector<ColumnWidth> ColWidth; ColWidth.push_back( ColumnWidth( 0, 0, 25 ) ); CWorksheet & Sheet = book.AddSheet( "Date and time",...
Thanks for the info. I'll think about it. It may be sufficient to modify the CellDataTime class and there will be no need for hacking :-)
Hi Meena, I tried to repeat your example with AddCell(19007.88) in a new simple project (compiler MinGW 7.3.0 32-bit). The resulting xlsx file stores the number 19007.88. Everything is as expected. Perhaps your number 19007.88 was obtained as a result of calculations and in the fractional part contains additional numbers. In this case, you need to configure rounding options. Please see this documentation: https://en.cppreference.com/w/cpp/numeric/fenv/FE_round https://en.cppreference.com/w/cpp/numeric/fenv...
The latest examples are included in the source code archive:: https://sourceforge.net/projects/simplexlsx/files/latest/download
macOS support was added in version 0.33. Thank you for your help.
Added pie chart and macOS support
Hi Willem, Thanks again for testing. I apologize for my carelessness in preparing this example. It is surprising that this problem is no one there before. In the attachment is an updated version of the library. Please note that the CWorksheet::AddCell(time_t) method has been removed. But the CWorksheet::AddCell(CellDataTime) method remained.
Hi Willem, Thanks so much for such detailed information. I have not had time to examine your files, but I already have one thought. Please find the AddScatterChart function in the Scientific.cpp file and at the very end replace this: chart.SetXAxisName("\u03D1, sec"); chart.SetYAxisName("\u046C, \u03A9 /cm\u00B2 "); with chart.SetXAxisName(L"\u03D1, sec"); chart.SetYAxisName(L"\u046C, \u03A9 /cm\u00B2 "); And try with MSVC again.
Hi Willem, I was unable to repeat the error with broken content. I used Visual Studio Community 2017 (v15.9.17) and Microsoft Excel 2010 (v14.0.7116.5000). Can you attach your "Scientific.xlsx" file with the problem?
Hi Willem, Thanks a lot for operational testing and a detailed description of the problems. I used MinGW, so I will try to check the compilation using Visual Studio a bit later. Sorry, I made a mistake with the Multicharts.cpp, of course, it was about Scientific.cpp.
Hi, I added a pie chart. Please take the updated library from the attachment. I also updated the MultiCharts example, please see it. I will be grateful if you can check this update and report the results.
Thanks for the explanation and example. I will try to add a pie chart. It will take some time.
Hi, Please attach examples of Excel files of what you want. I will try to figure out how to do this in the library.
I apologize for my long silence, I still have a shortage of free time. I checked your solution, it works great. Thanks again for helping to develop the library! I will update the library a little later.
Hello, Unfortunately not. The structure of the sheets should be known initially. This is due to the fact that the library is optimized for low memory consumption and speed.
Hello, Yes, you found everything right. But we must remember that the library does not check the correctness of the formulas.
Many thanks for the help, you have already helped a lot! And let me congratulate you with a new job. I also ask you not to worry about your experience, all my tests are simple, only the result of their execution is needed. Also I apologize for the very long response. I'm still on a business trip and have almost no free time. If you are still ready to continue testing, then I improved a small program. You can also check the modified version of the library from the attachment. I think a modified version...
Many thanks for the help, you have already helped a lot! And let me congratulate you with a new job. I also ask you not to worry about your experience, all my tests are simple, only the result of their execution is needed. Also I apologize for the very long response. I'm still on a business trip and have almost no free time. If you are still ready to continue testing, then I improved a small program. You can also check the modified version of the library from the attachment. I think a modified version...
Hi, Sorry for the long answer, I am on a business trip now. And thanks for your help. Somewhat later, I will check everything well and report it additionally.
Sorry for the long answer, I am on a business trip now. You did everything right. This error message is correct. The fact is that the library was never tested under macOS. If you have the desire and time to help with testing the library under macOS, I will be very grateful to you. To do this, we may need to carry out several checks/iterations. If you are ready to help, please show the output of a new small program from the attachment. Thanks.
It looks like a problem with a temporary directory. Please specify your operating system and show output of small program from attachment.
Hi, Tell me please, is the size of the xlsx-file larger than 0? If the size is 0, then there may be a problem with access to the temporary folder. Under Windows this folder requested via getenv( "TEMP" ) Under Unix via getenv with one of the following parameters: "TMPDIR", "TMP", "TEMP", "TEMPDIR" Please see the constructor of CWorkbook class. Also please specify your operating system and compiler.
Answer in next topic: https://sourceforge.net/p/simplexlsx/discussion/general/thread/2b80c74f02/
Probably you have already done everything on C# and I should not bother you... But seriously: 1. Read this: https://www.ablebits.com/office-addins-blog/2015/03/11/change-date-format-excel/#excel-date-format 2. Library is support formulae recognition (without formula`s content verification, what is written on the main page). The library accepts any formulas, it doesn't care. But if the formula is not correct, then Excel will generate an error. 3. Your formula is not correct, see attached example.
I'm glad you did it. I wish you successful use of the library :-)
I read this: https://docs.microsoft.com/en-us/cpp/ide/cmake-tools-for-visual-cpp?view=vs-2017 But in my case, CMake menu item did not even appear.
Hi, It is so hard because it is C++ world. I do not use Visual Studio and I don't know how well it supports CMake. I also could not get it to work with CMake (latest VS2017). By this reason, I created a new project "Static library" and set it up. Then I created a second project "Console Application" and set it up. And I have all turned out. You can find both projects in the attachment. They are configured in "Debug/x86" mode. Please let me know your test results. P.S. It took me about 30 minutes...
Hi, thanks for testing and good news. I really appreciate your help in the development of the project. Best regards, Alexander
Hi, Hmm, a strange situation. Can you provide a minimal working project with this error? I was talking about the "NDEBUD" switch in the file "XMLWriter.hpp" which was included in "Worksheet.h". Because of this XMLWriter class could have a different internal structure in object file of the library and in the main application. I'll try to explain by example. See the source code for version 0.30 of the library. We compile the library in release with NDEBUG. The XMLWriter class will not contain m_LightTagCounter...
Hi, Sorry for the long response and thank you for research of the problem and its possible solution. I believe that the problem is due to the inclusion of the file "XMLWriter.hpp" in Worksheet.h, which is accessible from the main application. The XMLWriter has a different internal structure between "debug" and "release" modes (see definition of m_LightTagCounter). To avoid conflicts between "release" and "debug" modes I changed "Worksheet.h" and "Worksheet.cpp", please see attachment.
Hi, This assertion error should occur when the XML-file is incorrectly created. It's very strange that you do not get this assertion error with v029. Difference between v029 and v030 only in line 816 of SimpleXlsxDef.h. Is this problem stable? Can you run your debug version under the debugger and see the stack of function calls before the assertion error?
Ok. Thank you for testing. Now the library has become even better :-)
Hi, Thanks for the detailed description of the problem. This is a library error with the number format. Please check the new version of the library from the attachment.
I would be grateful to you for test and results :-)