Skip to content

Commit

Permalink
Merge branch 'master' into patch-7
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultDECO authored Oct 9, 2022
2 parents 73f518c + f0801fb commit 9b752b7
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 14 deletions.
15 changes: 10 additions & 5 deletions docs/introduction/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions include/xlnt/workbook/workbook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ class XLNT_API workbook
/// </summary>
worksheet active_sheet();

/// <summary>
/// Sets the worksheet that is determined to be active. An active
/// sheet is that which is initially shown by the spreadsheet editor.
/// </summary>
void active_sheet(std::size_t index);

/// <summary>
/// Returns the worksheet with the given name. This may throw an exception
/// if the sheet isn't found. Use workbook::contains(const std::string &)
Expand Down
1 change: 1 addition & 0 deletions source/detail/serialization/xlsx_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t>("activeTab");
target_.d_->active_sheet_index_.set(view.active_tab.get());
}

target_.view(view);
Expand Down
5 changes: 5 additions & 0 deletions source/workbook/workbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Binary file added tests/data/20_active_sheet.xlsx
Binary file not shown.
10 changes: 5 additions & 5 deletions tests/detail/numeric_util_test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class numeric_test_suite : public test_suite
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));
Expand All @@ -69,7 +69,7 @@ class numeric_test_suite : public test_suite
// #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));
Expand All @@ -79,7 +79,7 @@ class numeric_test_suite : public test_suite
// This makes the epsilon range quite significantly less
xlnt_assert(!xlnt::detail::float_equals<double>(0.0, comp_val));
xlnt_assert(!xlnt::detail::float_equals<double>(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<double>(0.0, tiny_comp_val));
xlnt_assert(!xlnt::detail::float_equals<double>(0.0, tiny_comp_val + 0.1e-15));
xlnt_assert(xlnt::detail::float_equals<double>(0.0, -tiny_comp_val));
Expand All @@ -90,7 +90,7 @@ class numeric_test_suite : public test_suite
xlnt_assert(!xlnt::detail::float_equals<double>(0.0, comp_val, 1));
xlnt_assert(!xlnt::detail::float_equals<double>(0.0, closer_comp_val, 1));
xlnt_assert(!xlnt::detail::float_equals<double>(0.0, tiny_comp_val, 1));
const float really_tiny_comp_val = 2.2e-16; // the limit is +/- std::numeric_limits<double>::epsilon()
const float really_tiny_comp_val = 2.2e-16f; // the limit is +/- std::numeric_limits<double>::epsilon()
xlnt_assert(xlnt::detail::float_equals<double>(0.0, really_tiny_comp_val, 1));
xlnt_assert(!xlnt::detail::float_equals<double>(0.0, really_tiny_comp_val + 0.1e-16, 1));
xlnt_assert(xlnt::detail::float_equals<double>(0.0, -really_tiny_comp_val, 1));
Expand Down Expand Up @@ -132,7 +132,7 @@ class numeric_test_suite : public test_suite

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));
Expand Down
8 changes: 8 additions & 0 deletions tests/workbook/serialization_test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class serialization_test_suite : public test_suite
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)
Expand Down Expand Up @@ -800,6 +801,13 @@ class serialization_test_suite : public test_suite
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;
5 changes: 5 additions & 0 deletions tests/workbook/workbook_test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class workbook_test_suite : public test_suite
{
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()
Expand Down
12 changes: 8 additions & 4 deletions third-party/miniz/miniz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9b752b7

Please sign in to comment.