From 1faa8b499099d48438524b24681de340b767275f Mon Sep 17 00:00:00 2001 From: snippet Date: Wed, 24 Aug 2022 08:25:38 +1000 Subject: [PATCH 1/4] Removed zip download, they don't work with submodules. Added vcpkg command --- docs/introduction/Installation.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/introduction/Installation.md b/docs/introduction/Installation.md index 4d3ace89..8dddf3c8 100644 --- a/docs/introduction/Installation.md +++ b/docs/introduction/Installation.md @@ -9,6 +9,14 @@ xlnt can be [found](https://aur.archlinux.org/packages/xlnt/) on the AUR. ## vcpkg +`vcpkg` installs x86 by default +``` +.\vcpkg install xlnt +``` +if you need x64 use the following command +``` +.\vcpkg install xlnt:x64-windows +``` ## Compiling xlnt 1.x.x from Source on Ubuntu 16.04 LTS (Xenial Xerus) Time required: Approximately 5 minutes (depending on your internet speed) @@ -28,12 +36,9 @@ export CC=/usr/bin/gcc-6 export CXX=/usr/bin/g++-6 ``` The following steps will intall xlnt -Download the zip file from the xlnt repository -https://github.com/tfussell/xlnt/archive/master.zip ``` -cd ~ -unzip Downloads/xlnt-master.zip -cd xlnt-master +git clone https://github.com/tfussell/xlnt.git xlnt --recurse-submodules +cd xlnt cmake . make -j 2 sudo make install From c21014c0fd1f8b9d9c2eed8c468967d4e8069801 Mon Sep 17 00:00:00 2001 From: snippet Date: Mon, 29 Aug 2022 18:30:48 +1000 Subject: [PATCH 2/4] Added the ability to set the active sheet Closes #653 --- include/xlnt/workbook/workbook.hpp | 6 ++++++ source/detail/serialization/xlsx_consumer.cpp | 1 + source/workbook/workbook.cpp | 5 +++++ tests/data/20_active_sheet.xlsx | Bin 0 -> 6035 bytes tests/workbook/serialization_test_suite.cpp | 8 ++++++++ tests/workbook/workbook_test_suite.cpp | 5 +++++ 6 files changed, 25 insertions(+) create mode 100644 tests/data/20_active_sheet.xlsx diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 3afb95f8..f7aa4e3c 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -203,6 +203,12 @@ public: /// worksheet active_sheet(); + /// + /// Sets the worksheet that is determined to be active. An active + /// sheet is that which is initially shown by the spreadsheet editor. + /// + void active_sheet(std::size_t index); + /// /// Returns the worksheet with the given name. This may throw an exception /// if the sheet isn't found. Use workbook::contains(const std::string &) diff --git a/source/detail/serialization/xlsx_consumer.cpp b/source/detail/serialization/xlsx_consumer.cpp index e7dce8d1..dc50106c 100644 --- a/source/detail/serialization/xlsx_consumer.cpp +++ b/source/detail/serialization/xlsx_consumer.cpp @@ -2037,6 +2037,7 @@ void xlsx_consumer::read_office_document(const std::string &content_type) // CT_ if (parser().attribute_present("activeTab")) { view.active_tab = parser().attribute("activeTab"); + target_.d_->active_sheet_index_.set(view.active_tab.get()); } target_.view(view); diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index 5d49ddff..dce9d3bd 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -743,6 +743,11 @@ worksheet workbook::active_sheet() { return sheet_by_index(d_->active_sheet_index_.is_set() ? d_->active_sheet_index_.get() : 0); } +void workbook::active_sheet(std::size_t index) +{ + d_->active_sheet_index_.set(index); + d_->view_.get().active_tab = index; +} bool workbook::has_named_range(const std::string &name) const { diff --git a/tests/data/20_active_sheet.xlsx b/tests/data/20_active_sheet.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..d441ddccd7f3195b2ca693a47388f05651b84251 GIT binary patch literal 6035 zcmeHLcTiK?w+_9RPy_-2B{U_{k&YBe=msfLqzD8Ey-AZUReBSoihzg+0qI1ggMf4e zqzF=^iBv-qcv0US@8#X!%zg9TpEsF(&SWOvI_rFU?NvU61_2=h001Bb#H4`rVa6?# zp}1d_xJ8Rw)-F~EcNbR=!P~B`0zOWTTJc&GtwOZdPSsbYo%J`*3!i^iFx!1sRpLsb zwX#?EcYocMgh|Q$oa zR2(MwgzfjR)wkEeX7MCDPj(Kf7CH%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ests/workbook/serialization_test_suite.cpp index 10dbb4fd..ca6383a1 100644 --- a/tests/workbook/serialization_test_suite.cpp +++ b/tests/workbook/serialization_test_suite.cpp @@ -72,6 +72,7 @@ public: register_test(test_Issue492_stream_empty_row); register_test(test_Issue503_external_link_load); register_test(test_formatting); + register_test(test_active_sheet); } bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file) @@ -800,6 +801,13 @@ public: assert_run(rt.runs()[10], " first line ", "Calibri", xlnt::theme_color(1), 12, true, false, xlnt::font::underline_style::none); assert_run(rt.runs()[11], "Bold And Underline", "Calibri (Body)", xlnt::theme_color(1), 12, true, false, xlnt::font::underline_style::single); } + + void test_active_sheet() + { + xlnt::workbook wb; + wb.load(path_helper::test_file("20_active_sheet.xlsx")); + xlnt_assert_equals(wb.active_sheet(), wb[2]); + } }; static serialization_test_suite x; diff --git a/tests/workbook/workbook_test_suite.cpp b/tests/workbook/workbook_test_suite.cpp index 59eb3a69..09e37660 100644 --- a/tests/workbook/workbook_test_suite.cpp +++ b/tests/workbook/workbook_test_suite.cpp @@ -77,6 +77,11 @@ public: { xlnt::workbook wb; xlnt_assert_equals(wb.active_sheet(), wb[0]); + + wb.create_sheet(); + wb.create_sheet(); + wb.active_sheet(2); + xlnt_assert_equals(wb.active_sheet(), wb[2]); } void test_create_sheet() From 2137a7a2435145fc2f6e97ce2c901ffc91c4087a Mon Sep 17 00:00:00 2001 From: Teebonne <80053070+Teebonne@users.noreply.github.com> Date: Mon, 29 Aug 2022 22:17:42 +0100 Subject: [PATCH 3/4] Fixes float warnings Fixes warning C4305: 'initializing': truncation from 'double' to 'float' Fixes warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data --- tests/detail/numeric_util_test_suite.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/detail/numeric_util_test_suite.cpp b/tests/detail/numeric_util_test_suite.cpp index 5526dec1..cf420a4a 100644 --- a/tests/detail/numeric_util_test_suite.cpp +++ b/tests/detail/numeric_util_test_suite.cpp @@ -57,7 +57,7 @@ public: void test_float_equals_zero() { // comparing relatively small numbers (2.3e-6) with 0 will be true by default - const float comp_val = 2.3e-6; // about the largest difference allowed by default + const float comp_val = 2.3e-6f; // about the largest difference allowed by default xlnt_assert(0.f != comp_val); // fail because not exactly equal xlnt_assert(xlnt::detail::float_equals(0.0, comp_val)); xlnt_assert(xlnt::detail::float_equals(0.0, -comp_val)); @@ -69,7 +69,7 @@ public: // #1: reduce the epsilon_scale (default is 20) // This can bring the range down to FLT_EPSILON (scale factor of 1) xlnt_assert(!xlnt::detail::float_equals(0.0, comp_val, 10)); - const float closer_comp_val = 1.1e-6; + const float closer_comp_val = 1.1e-6f; xlnt_assert(xlnt::detail::float_equals(0.0, closer_comp_val, 10)); xlnt_assert(!xlnt::detail::float_equals(0.0, closer_comp_val + 0.1e-6, 10)); xlnt_assert(xlnt::detail::float_equals(0.0, -closer_comp_val, 10)); @@ -79,7 +79,7 @@ public: // This makes the epsilon range quite significantly less xlnt_assert(!xlnt::detail::float_equals(0.0, comp_val)); xlnt_assert(!xlnt::detail::float_equals(0.0, closer_comp_val)); - const float tiny_comp_val = 4.4e-15; + const float tiny_comp_val = 4.4e-15f; xlnt_assert(xlnt::detail::float_equals(0.0, tiny_comp_val)); xlnt_assert(!xlnt::detail::float_equals(0.0, tiny_comp_val + 0.1e-15)); xlnt_assert(xlnt::detail::float_equals(0.0, -tiny_comp_val)); @@ -90,7 +90,7 @@ public: xlnt_assert(!xlnt::detail::float_equals(0.0, comp_val, 1)); xlnt_assert(!xlnt::detail::float_equals(0.0, closer_comp_val, 1)); xlnt_assert(!xlnt::detail::float_equals(0.0, tiny_comp_val, 1)); - const float really_tiny_comp_val = 2.2e-16; // the limit is +/- std::numeric_limits::epsilon() + const float really_tiny_comp_val = 2.2e-16f; // the limit is +/- std::numeric_limits::epsilon() xlnt_assert(xlnt::detail::float_equals(0.0, really_tiny_comp_val, 1)); xlnt_assert(!xlnt::detail::float_equals(0.0, really_tiny_comp_val + 0.1e-16, 1)); xlnt_assert(xlnt::detail::float_equals(0.0, -really_tiny_comp_val, 1)); @@ -132,7 +132,7 @@ public: void test_float_equals_nan() { - const float nan = std::nan(""); + const float nan = std::nanf(""); // nans always compare false xlnt_assert(!xlnt::detail::float_equals(nan, 0.f)); xlnt_assert(!xlnt::detail::float_equals(nan, nan)); From 73962b8a793591f9cbf221039d7408ee91b1f29a Mon Sep 17 00:00:00 2001 From: Teebonne <80053070+Teebonne@users.noreply.github.com> Date: Mon, 29 Aug 2022 23:31:51 +0100 Subject: [PATCH 4/4] Fixes warning C4127: conditional expression is constant Fixes warning C4127: conditional expression is constant --- third-party/miniz/miniz.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/third-party/miniz/miniz.c b/third-party/miniz/miniz.c index f408fdfd..f988bb36 100644 --- a/third-party/miniz/miniz.c +++ b/third-party/miniz/miniz.c @@ -4460,7 +4460,8 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file { /* Temporarily allocate a read buffer. */ read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE); - if (((sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF)) + int constExpression1 = (((sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF)); + if (constExpression1) return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size))) @@ -4554,7 +4555,8 @@ void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, si uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS); alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size; - if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) + int constExpression2 = (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)); + if (constExpression2) { mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); return NULL; @@ -4652,7 +4654,8 @@ mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_ind /* The file is stored or the caller has requested the compressed data. */ if (pZip->m_pState->m_pMem) { - if (((sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > MZ_UINT32_MAX)) + int constExpression3 = (((sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > MZ_UINT32_MAX)); + if (constExpression3) return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)file_stat.m_comp_size) != file_stat.m_comp_size) @@ -5555,7 +5558,8 @@ static size_t mz_zip_heap_write_func(void *pOpaque, mz_uint64 file_ofs, const vo return 0; /* An allocation this big is likely to just fail on 32-bit systems, so don't even go there. */ - if ((sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF)) + int constExpression4 = ((sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF)); + if (constExpression4) { mz_zip_set_error(pZip, MZ_ZIP_FILE_TOO_LARGE); return 0;