From 990c2a926f691acb13a65ef944c5827fa553ae07 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Tue, 10 Nov 2015 19:47:31 -0500 Subject: [PATCH] fix minor issues and configure script --- cmake/CMakeLists.txt | 3 +- cmake/xlnt.cmake | 2 +- configure | 10 ++++-- include/xlnt/workbook/workbook.hpp | 1 + include/xlnt/worksheet/range_reference.hpp | 6 ++-- include/xlnt/worksheet/worksheet.hpp | 6 ++++ .../tests/test_write_workbook.hpp | 2 +- source/serialization/worksheet_serializer.cpp | 2 +- source/workbook/workbook.cpp | 5 +++ source/worksheet/worksheet.cpp | 32 ++++++++++++++++++- 10 files changed, 59 insertions(+), 10 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 952e40a0..1b6beb8e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -6,10 +6,11 @@ endif() project(xlnt) -option(SHARED "Set to OFF to build static libraries" ON) +option(SHARED "Set to ON to build shared libraries" OFF) option(BUILD_EXAMPLES "Build examples" OFF) option(BUILD_TESTS "Build tests runner" OFF) option(AUTORUN_TESTS "Automatically run tests after building" OFF) +option(COVERAGE "Create coverage files" OFF) if(APPLE) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10) diff --git a/cmake/xlnt.cmake b/cmake/xlnt.cmake index d1f8b0f9..7a6d50be 100644 --- a/cmake/xlnt.cmake +++ b/cmake/xlnt.cmake @@ -63,7 +63,7 @@ if(SHARED) target_compile_definitions(xlnt PRIVATE XLNT_EXPORT=1) add_definitions(-DXLNT_SHARED) if(MSVC) - set_target_properties(xlnt PROPERTIES COMPILE_FLAGS "/wd\"4251\"") + set_target_properties(xlnt PROPERTIES COMPILE_FLAGS "/wd\"4251\" /MD") endif() else() add_library(xlnt STATIC ${HEADERS} ${SOURCES} ${MINIZ} ${PUGIXML}) diff --git a/configure b/configure index 43b1fb1c..5776ea55 100755 --- a/configure +++ b/configure @@ -73,6 +73,8 @@ def parse_args(args): if option == '--shared': options['SHARED'] = 1 + elif option == '--static': + options['SHARED'] = 0 elif option == '--build-tests': options['BUILD_TESTS'] = 1 elif option == '--autotest': @@ -81,8 +83,10 @@ def parse_args(args): options['COVERAGE'] = 1 elif option == '--build-examples': options['BUILD_EXAMPLES'] = 1 - if option == '--prefix': - options['CMAKE_INSTALL_PREFIX'] = args.pop(len(args) - 1) + elif option.startswith('--prefix='): + options['CMAKE_INSTALL_PREFIX'] = option.split('=')[1] + else: + print('skipping unknown option: {}'.format(option)) return options, generator @@ -112,6 +116,8 @@ def main(): cmake_scripts_dir = '../cmake' # relative to build_dir command.append(cmake_scripts_dir) + print(' '.join(command)) + subprocess.call(command, cwd=build_dir) if __name__ == '__main__': diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index f636604b..890c0499 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -174,6 +174,7 @@ class XLNT_CLASS workbook // named ranges std::vector get_named_ranges() const; void create_named_range(const std::string &name, worksheet worksheet, const range_reference &reference); + void create_named_range(const std::string &name, worksheet worksheet, const std::string &reference_string); bool has_named_range(const std::string &name) const; range get_named_range(const std::string &name); void remove_named_range(const std::string &name); diff --git a/include/xlnt/worksheet/range_reference.hpp b/include/xlnt/worksheet/range_reference.hpp index 0c0acd4b..cf92ecb4 100644 --- a/include/xlnt/worksheet/range_reference.hpp +++ b/include/xlnt/worksheet/range_reference.hpp @@ -37,9 +37,9 @@ class XLNT_CLASS range_reference static range_reference make_absolute(const range_reference &relative_reference); range_reference(); - range_reference(const std::string &range_string); - range_reference(const char *range_string); - range_reference(const std::pair &reference_pair); + explicit range_reference(const std::string &range_string); + explicit range_reference(const char *range_string); + explicit range_reference(const std::pair &reference_pair); range_reference(const cell_reference &start, const cell_reference &end); range_reference(column_t column_index_start, row_t row_index_start, column_t column_index_end, row_t row_index_end); diff --git a/include/xlnt/worksheet/worksheet.hpp b/include/xlnt/worksheet/worksheet.hpp index d7ab7556..c0cfae3e 100644 --- a/include/xlnt/worksheet/worksheet.hpp +++ b/include/xlnt/worksheet/worksheet.hpp @@ -290,7 +290,9 @@ class XLNT_CLASS worksheet // container cell get_cell(const cell_reference &reference); const cell get_cell(const cell_reference &reference) const; + range get_range(const std::string &reference_string); range get_range(const range_reference &reference); + const range get_range(const std::string &reference_string) const; const range get_range(const range_reference &reference) const; range get_squared_range(column_t min_col, row_t min_row, column_t max_col, row_t max_row); const range get_squared_range(column_t min_col, row_t min_row, column_t max_col, row_t max_row) const; @@ -319,6 +321,7 @@ class XLNT_CLASS worksheet std::string unique_sheet_name(const std::string &value) const; // named range + void create_named_range(const std::string &name, const std::string &reference_string); void create_named_range(const std::string &name, const range_reference &reference); bool has_named_range(const std::string &name); range get_named_range(const std::string &name); @@ -340,8 +343,10 @@ class XLNT_CLASS worksheet // void add_chart(chart chart); // cell merge + void merge_cells(const std::string &reference_string); void merge_cells(const range_reference &reference); void merge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row); + void unmerge_cells(const std::string &reference_string); void unmerge_cells(const range_reference &reference); void unmerge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row); std::vector get_merged_ranges() const; @@ -380,6 +385,7 @@ class XLNT_CLASS worksheet // auto filter range_reference get_auto_filter() const; + void auto_filter(const std::string &range_string); void auto_filter(const xlnt::range &range); void auto_filter(const range_reference &reference); void unset_auto_filter(); diff --git a/source/serialization/tests/test_write_workbook.hpp b/source/serialization/tests/test_write_workbook.hpp index 8d44f124..ecb7d73f 100644 --- a/source/serialization/tests/test_write_workbook.hpp +++ b/source/serialization/tests/test_write_workbook.hpp @@ -16,7 +16,7 @@ public: xlnt::workbook wb; auto ws = wb.create_sheet(); ws.get_cell("F42").set_value("hello"); - ws.get_auto_filter() = "A1:F1"; + ws.auto_filter("A1:F1"); xlnt::workbook_serializer serializer(wb); auto observed = serializer.write_workbook(); diff --git a/source/serialization/worksheet_serializer.cpp b/source/serialization/worksheet_serializer.cpp index a1a34ba9..bb5d5a16 100644 --- a/source/serialization/worksheet_serializer.cpp +++ b/source/serialization/worksheet_serializer.cpp @@ -51,7 +51,7 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml) continue; } - sheet_.merge_cells(merge_cell_node.get_attribute("ref")); + sheet_.merge_cells(range_reference(merge_cell_node.get_attribute("ref"))); count--; } diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index dc5a8929..5a9c353f 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -217,6 +217,11 @@ int workbook::get_index(xlnt::worksheet worksheet) throw std::runtime_error("worksheet isn't owned by this workbook"); } +void workbook::create_named_range(const std::string &name, worksheet range_owner, const std::string &reference_string) +{ + create_named_range(name, range_owner, range_reference(reference_string)); +} + void workbook::create_named_range(const std::string &name, worksheet range_owner, const range_reference &reference) { auto match = get_sheet_by_name(range_owner.get_title()); diff --git a/source/worksheet/worksheet.cpp b/source/worksheet/worksheet.cpp index 0ef082c2..f9c794ab 100644 --- a/source/worksheet/worksheet.cpp +++ b/source/worksheet/worksheet.cpp @@ -54,6 +54,11 @@ std::string worksheet::unique_sheet_name(const std::string &value) const return append == 0 ? value : value + std::to_string(append); } +void worksheet::create_named_range(const std::string &name, const std::string &reference_string) +{ + create_named_range(name, range_reference(reference_string)); +} + void worksheet::create_named_range(const std::string &name, const range_reference &reference) { std::vector targets; @@ -63,7 +68,7 @@ void worksheet::create_named_range(const std::string &name, const range_referenc range worksheet::operator()(const xlnt::cell_reference &top_left, const xlnt::cell_reference &bottom_right) { - return get_range({ top_left, bottom_right }); + return get_range(range_reference(top_left, bottom_right)); } cell worksheet::operator[](const cell_reference &ref) @@ -86,6 +91,11 @@ const margins &worksheet::get_page_margins() const return d_->page_margins_; } +void worksheet::auto_filter(const std::string &reference_string) +{ + auto_filter(range_reference(reference_string)); +} + void worksheet::auto_filter(const range_reference &reference) { d_->auto_filter_ = reference; @@ -321,11 +331,21 @@ range_reference worksheet::calculate_dimension() const return range_reference(lowest_column, lowest_row, highest_column, highest_row); } +range worksheet::get_range(const std::string &reference_string) +{ + return get_range(range_reference(reference_string)); +} + range worksheet::get_range(const range_reference &reference) { return range(*this, reference); } +const range worksheet::get_range(const std::string &reference_string) const +{ + return get_range(range_reference(reference_string)); +} + const range worksheet::get_range(const range_reference &reference) const { return range(*this, reference); @@ -355,6 +375,16 @@ relationship worksheet::create_relationship(relationship::type type, const std:: return d_->relationships_.back(); } +void worksheet::merge_cells(const std::string &reference_string) +{ + merge_cells(range_reference(reference_string)); +} + +void worksheet::unmerge_cells(const std::string &reference_string) +{ + unmerge_cells(range_reference(reference_string)); +} + void worksheet::merge_cells(const range_reference &reference) { d_->merged_cells_.push_back(reference);