diff --git a/include/xlnt/utils/datetime.hpp b/include/xlnt/utils/datetime.hpp index 654ded09..9cbb6aef 100644 --- a/include/xlnt/utils/datetime.hpp +++ b/include/xlnt/utils/datetime.hpp @@ -54,7 +54,7 @@ struct XLNT_CLASS datetime datetime(int year_, int month_, int day_, int hour_ = 0, int minute_ = 0, int second_ = 0, int microsecond_ = 0); - std::string to_string(calendar base_date) const; + std::string to_string() const; long double to_number(calendar base_date) const; bool operator==(const datetime &comparand) const; diff --git a/include/xlnt/worksheet/page_margins.hpp b/include/xlnt/worksheet/page_margins.hpp index fddba423..b61a8248 100644 --- a/include/xlnt/worksheet/page_margins.hpp +++ b/include/xlnt/worksheet/page_margins.hpp @@ -56,13 +56,14 @@ public: void set_footer(double footer); private: - bool default_; - double top_; - double left_; - double bottom_; - double right_; - double header_; - double footer_; + bool default_ = true; + + double top_ = 1; + double left_ = 0.75; + double bottom_ = 1; + double right_ = 0.75; + double header_ = 0.5; + double footer_ = 0.5; }; } // namespace xlnt diff --git a/include/xlnt/worksheet/range.hpp b/include/xlnt/worksheet/range.hpp index f764bc48..2fb6d2a1 100644 --- a/include/xlnt/worksheet/range.hpp +++ b/include/xlnt/worksheet/range.hpp @@ -76,6 +76,12 @@ public: std::size_t length() const; bool contains(const cell_reference &ref); + + cell_vector front(); + const cell_vector front() const; + + cell_vector back(); + const cell_vector back() const; iterator begin(); iterator end(); diff --git a/source/detail/worksheet_impl.hpp b/source/detail/worksheet_impl.hpp index 35a5f3b7..6d3968cd 100644 --- a/source/detail/worksheet_impl.hpp +++ b/source/detail/worksheet_impl.hpp @@ -44,14 +44,10 @@ namespace detail { struct worksheet_impl { worksheet_impl(workbook *parent_workbook, const std::string &title) - : parent_(parent_workbook), title_(title), comment_count_(0) + : parent_(parent_workbook), + title_(title), + comment_count_(0) { - page_margins_.set_left(0.75); - page_margins_.set_right(0.75); - page_margins_.set_top(1); - page_margins_.set_bottom(1); - page_margins_.set_header(0.5); - page_margins_.set_footer(0.5); } worksheet_impl(const worksheet_impl &other) diff --git a/source/styles/tests/test_stylesheet.hpp b/source/styles/tests/test_stylesheet.hpp index 96717d93..95341916 100644 --- a/source/styles/tests/test_stylesheet.hpp +++ b/source/styles/tests/test_stylesheet.hpp @@ -41,6 +41,20 @@ public: TS_ASSERT_EQUALS(e.get_stylesheet().number_formats.size(), 0); } + void test_add_existing_style() + { + xlnt::workbook wb; + xlnt::excel_serializer e(wb); + + TS_ASSERT_EQUALS(e.get_stylesheet().styles.size(), 1); + + auto &s = wb.create_style("test"); + TS_ASSERT_EQUALS(e.get_stylesheet().styles.size(), 2); + + wb.add_style(s); + TS_ASSERT_EQUALS(e.get_stylesheet().styles.size(), 2); + } + /* void _test_unprotected_cell() { diff --git a/source/utils/datetime.cpp b/source/utils/datetime.cpp index ca0786e6..90415cde 100644 --- a/source/utils/datetime.cpp +++ b/source/utils/datetime.cpp @@ -65,7 +65,7 @@ long double datetime::to_number(calendar base_date) const return date(year, month, day).to_number(base_date) + time(hour, minute, second, microsecond).to_number(); } -std::string datetime::to_string(xlnt::calendar /*base_date*/) const +std::string datetime::to_string() const { return std::to_string(year) + "/" + std::to_string(month) + "/" + std::to_string(day) + " " + std::to_string(hour) + ":" + std::to_string(minute) + ":" + std::to_string(second) + ":" + std::to_string(microsecond); diff --git a/source/utils/tests/test_datetime.hpp b/source/utils/tests/test_datetime.hpp index 5519f391..fd7dc488 100644 --- a/source/utils/tests/test_datetime.hpp +++ b/source/utils/tests/test_datetime.hpp @@ -16,6 +16,12 @@ public: TS_ASSERT_EQUALS(t.second, 45); } + void test_to_string() + { + xlnt::datetime dt(2016, 7, 16, 9, 11, 32, 999999); + TS_ASSERT_EQUALS(dt.to_string(), "2016/7/16 9:11:32:999999"); + } + void test_carry() { // We want a time that rolls over to the next second, minute, and hour diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index 0da32e71..0ff54d0f 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -260,5 +260,14 @@ public: TS_ASSERT_EQUALS(iter, copy); } - // void test_add_invalid_worksheet_class_instance() {} not needed in c++ + void test_manifest() + { + xlnt::default_type d; + TS_ASSERT(d.get_content_type().empty()); + TS_ASSERT(d.get_extension().empty()); + + xlnt::override_type o; + TS_ASSERT(o.get_content_type().empty()); + TS_ASSERT(o.get_part_name().empty()); + } }; diff --git a/source/worksheet/page_margins.cpp b/source/worksheet/page_margins.cpp index 28cb5339..0bc9e6a4 100644 --- a/source/worksheet/page_margins.cpp +++ b/source/worksheet/page_margins.cpp @@ -25,7 +25,7 @@ namespace xlnt { -page_margins::page_margins() : default_(true), top_(0), left_(0), bottom_(0), right_(0), header_(0), footer_(0) +page_margins::page_margins() { } diff --git a/source/worksheet/range.cpp b/source/worksheet/range.cpp index 8b405b0f..d3daa415 100644 --- a/source/worksheet/range.cpp +++ b/source/worksheet/range.cpp @@ -94,7 +94,27 @@ bool range::contains(const cell_reference &ref) cell range::get_cell(const cell_reference &ref) { - return (*this)[ref.get_row()][ref.get_column().index]; + return (*this)[ref.get_row() - 1][ref.get_column().index - 1]; +} + +cell_vector range::front() +{ + return *begin(); +} + +const cell_vector range::front() const +{ + return *cbegin(); +} + +cell_vector range::back() +{ + return *(--end()); +} + +const cell_vector range::back() const +{ + return *(--cend()); } range::iterator range::begin() diff --git a/source/worksheet/tests/test_worksheet.hpp b/source/worksheet/tests/test_worksheet.hpp index 3319f5f9..1d9b2092 100644 --- a/source/worksheet/tests/test_worksheet.hpp +++ b/source/worksheet/tests/test_worksheet.hpp @@ -999,8 +999,12 @@ public: { xlnt::workbook wb; auto ws = wb.get_active_sheet(); - ws.get_page_margins(); - //TODO: uhh... this isn't a test + auto &margins = ws.get_page_margins(); + + TS_ASSERT(margins.is_default()); + + margins.set_bottom(1); + TS_ASSERT(!margins.is_default()); } void test_to_string() @@ -1090,6 +1094,9 @@ public: ws1.create_named_range("rangey", "A2:A2"); TS_ASSERT_EQUALS(ws1[std::string("rangey")], ws1.get_range("A2:A2")); TS_ASSERT_EQUALS(ws1[std::string("A2:A2")], ws1.get_range("A2:A2")); + TS_ASSERT_DIFFERS(ws1[std::string("rangey")], ws1.get_range("A2:A3")); + + TS_ASSERT_EQUALS(ws1[std::string("rangey")].get_cell("A1"), ws1.get_cell("A2")); } void test_reserve()