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 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 00000000..d441ddcc Binary files /dev/null and b/tests/data/20_active_sheet.xlsx differ 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)); diff --git a/tests/workbook/serialization_test_suite.cpp b/tests/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() 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;