mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
fix some things
This commit is contained in:
parent
12cc2ab36b
commit
93bd3d9989
|
@ -23,6 +23,10 @@
|
||||||
// @author: see AUTHORS file
|
// @author: see AUTHORS file
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace xlnt {
|
namespace xlnt {
|
||||||
|
|
||||||
class number_format
|
class number_format
|
||||||
|
@ -33,11 +37,11 @@ public:
|
||||||
general,
|
general,
|
||||||
text,
|
text,
|
||||||
number,
|
number,
|
||||||
number00,
|
number_00,
|
||||||
number_comma_separated1,
|
number_comma_separated1,
|
||||||
number_comma_separated2,
|
number_comma_separated2,
|
||||||
percentage,
|
percentage,
|
||||||
percentage00,
|
percentage_00,
|
||||||
date_yyyymmdd2,
|
date_yyyymmdd2,
|
||||||
date_yyyymmdd,
|
date_yyyymmdd,
|
||||||
date_ddmmyyyy,
|
date_ddmmyyyy,
|
||||||
|
@ -65,131 +69,19 @@ public:
|
||||||
currency_usd,
|
currency_usd,
|
||||||
currency_eur_simple
|
currency_eur_simple
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unordered_map<format, std::string> format_strings =
|
struct format_hash
|
||||||
{
|
{
|
||||||
{format::general, "General"},
|
std::size_t operator()(format f) const
|
||||||
{format::text, "@"},
|
{
|
||||||
{format::number, "0"},
|
return std::hash<int>()((int)f);
|
||||||
{format::number_00, "0.00"},
|
}
|
||||||
{format::NUMBER_COMMA_SEPARATED1, "#,##0.00"},
|
|
||||||
{format::NUMBER_COMMA_SEPARATED2, "#,##0.00_-"},
|
|
||||||
{format::PERCENTAGE, "0%"},
|
|
||||||
{format::PERCENTAGE_00, "0.00%"},
|
|
||||||
{format::DATE_YYYYMMDD2, "yyyy-mm-dd"},
|
|
||||||
{format::DATE_YYYYMMDD, "yy-mm-dd"},
|
|
||||||
{format::DATE_DDMMYYYY, "dd/mm/yy"},
|
|
||||||
{format::DATE_DMYSLASH, "d/m/y"},
|
|
||||||
{format::DATE_DMYMINUS, "d-m-y"},
|
|
||||||
{format::DATE_DMMINUS, "d-m"},
|
|
||||||
{format::DATE_MYMINUS, "m-y"},
|
|
||||||
{format::DATE_XLSX14, "mm-dd-yy"},
|
|
||||||
{format::DATE_XLSX15, "d-mmm-yy"},
|
|
||||||
{format::DATE_XLSX16, "d-mmm"},
|
|
||||||
{format::DATE_XLSX17, "mmm-yy"},
|
|
||||||
{format::DATE_XLSX22, "m/d/yy h:mm"},
|
|
||||||
{format::DATE_DATETIME, "d/m/y h:mm"},
|
|
||||||
{format::DATE_TIME1, "h:mm AM/PM"},
|
|
||||||
{format::DATE_TIME2, "h:mm:ss AM/PM"},
|
|
||||||
{format::DATE_TIME3, "h:mm"},
|
|
||||||
{format::DATE_TIME4, "h:mm:ss"},
|
|
||||||
{format::DATE_TIME5, "mm:ss"},
|
|
||||||
{format::DATE_TIME6, "h:mm:ss"},
|
|
||||||
{format::DATE_TIME7, "i:s.S"},
|
|
||||||
{format::DATE_TIME8, "h:mm:ss@"},
|
|
||||||
{format::DATE_TIMEDELTA, "[hh]:mm:ss"},
|
|
||||||
{format::DATE_YYYYMMDDSLASH, "yy/mm/dd@"},
|
|
||||||
{format::CURRENCY_USD_SIMPLE, "\"$\"#,##0.00_-"},
|
|
||||||
{format::CURRENCY_USD, "$#,##0_-"},
|
|
||||||
{format::CURRENCY_EUR_SIMPLE, "[$EUR ]#,##0.00_-"}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::unordered_map<int, std::string> builtin_formats =
|
static const std::unordered_map<format, std::string, format_hash> format_strings;
|
||||||
{
|
static const std::unordered_map<int, std::string> builtin_formats;
|
||||||
{0, "General"},
|
static const std::unordered_map<std::string, int> reversed_builtin_formats;
|
||||||
{1, "0"},
|
|
||||||
{2, "0.00"},
|
|
||||||
{3, "#,##0"},
|
|
||||||
{4, "#,##0.00"},
|
|
||||||
{5, "\"$\"#,##0_);(\"$\"#,##0)"},
|
|
||||||
{6, "\"$\"#,##0_);[Red](\"$\"#,##0)"},
|
|
||||||
{7, "\"$\"#,##0.00_);(\"$\"#,##0.00)"},
|
|
||||||
{8, "\"$\"#,##0.00_);[Red](\"$\"#,##0.00)"},
|
|
||||||
{9, "0%"},
|
|
||||||
{10, "0.00%"},
|
|
||||||
{11, "0.00E+00"},
|
|
||||||
{12, "# ?/?"},
|
|
||||||
{13, "# ??/??"},
|
|
||||||
{14, "mm-dd-yy"},
|
|
||||||
{15, "d-mmm-yy"},
|
|
||||||
{16, "d-mmm"},
|
|
||||||
{17, "mmm-yy"},
|
|
||||||
{18, "h:mm AM/PM"},
|
|
||||||
{19, "h:mm:ss AM/PM"},
|
|
||||||
{20, "h:mm"},
|
|
||||||
{21, "h:mm:ss"},
|
|
||||||
{22, "m/d/yy h:mm"},
|
|
||||||
|
|
||||||
{37, "#,##0_);(#,##0)"},
|
|
||||||
{38, "#,##0_);[Red](#,##0)"},
|
|
||||||
{39, "#,##0.00_);(#,##0.00)"},
|
|
||||||
{40, "#,##0.00_);[Red](#,##0.00)"},
|
|
||||||
|
|
||||||
{41, "_(* #,##0_);_(* \(#,##0\\);_(* \"-\"_);_(@_)"},
|
|
||||||
{42, "_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)"},
|
|
||||||
{43, "_(* #,##0.00_);_(* \(#,##0.00\\);_(* \"-\"??_);_(@_)"},
|
|
||||||
|
|
||||||
{44, "_(\"$\"* #,##0.00_)_(\"$\"* \(#,##0.00\\)_(\"$\"* \"-\"??_)_(@_)"},
|
|
||||||
{45, "mm:ss"},
|
|
||||||
{46, "[h]:mm:ss"},
|
|
||||||
{47, "mmss.0"},
|
|
||||||
{48, "##0.0E+0"},
|
|
||||||
{49, "@"}
|
|
||||||
};
|
|
||||||
|
|
||||||
static const std::unordered_map<std::string, int> reversed_builtin_formats =
|
|
||||||
{
|
|
||||||
{"General", 0},
|
|
||||||
{"0", 1},
|
|
||||||
{"0.00", 2},
|
|
||||||
{"#,##0", 3},
|
|
||||||
{"#,##0.00", 4},
|
|
||||||
{"\"$\"#,##0_);(\"$\"#,##0)", 5},
|
|
||||||
{"\"$\"#,##0_);[Red](\"$\"#,##0)", 6},
|
|
||||||
{"\"$\"#,##0.00_);(\"$\"#,##0.00)", 7},
|
|
||||||
{"\"$\"#,##0.00_);[Red](\"$\"#,##0.00)", 8},
|
|
||||||
{"0%", 9},
|
|
||||||
{"0.00%", 10},
|
|
||||||
{"0.00E+00", 11},
|
|
||||||
{"# ?/?", 12},
|
|
||||||
{"# ??/??", 13},
|
|
||||||
{"mm-dd-yy", 14},
|
|
||||||
{"d-mmm-yy", 15},
|
|
||||||
{"d-mmm", 16},
|
|
||||||
{"mmm-yy", 17},
|
|
||||||
{"h:mm AM/PM", 18},
|
|
||||||
{"h:mm:ss AM/PM", 19},
|
|
||||||
{"h:mm", 20},
|
|
||||||
{"h:mm:ss", 21},
|
|
||||||
{"m/d/yy h:mm", 22},
|
|
||||||
|
|
||||||
{"#,##0_);(#,##0)", 37},
|
|
||||||
{"#,##0_);[Red](#,##0)", 38},
|
|
||||||
{"#,##0.00_);(#,##0.00)", 39},
|
|
||||||
{"#,##0.00_);[Red](#,##0.00)", 40},
|
|
||||||
|
|
||||||
{"_(* #,##0_);_(* \(#,##0\\);_(* \"-\"_);_(@_)", 41},
|
|
||||||
{"_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)", 42},
|
|
||||||
{"_(* #,##0.00_);_(* \(#,##0.00\\);_(* \"-\"??_);_(@_)", 43},
|
|
||||||
|
|
||||||
{"_(\"$\"* #,##0.00_)_(\"$\"* \(#,##0.00\\)_(\"$\"* \"-\"??_)_(@_)", 44},
|
|
||||||
{"mm:ss", 45},
|
|
||||||
{"[h]:mm:ss", 46},
|
|
||||||
{"mmss.0", 47},
|
|
||||||
{"##0.0E+0", 48},
|
|
||||||
{"@", 49}
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::string builtin_format_code(int index);
|
static std::string builtin_format_code(int index);
|
||||||
|
|
||||||
static bool is_date_format(const std::string &format);
|
static bool is_date_format(const std::string &format);
|
||||||
|
|
|
@ -20,6 +20,12 @@ data_type_exception::data_type_exception()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
named_range_exception::named_range_exception()
|
||||||
|
: std::runtime_error("named range not found or not owned by this worksheet")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
invalid_file_exception::invalid_file_exception(const std::string &filename)
|
invalid_file_exception::invalid_file_exception(const std::string &filename)
|
||||||
: std::runtime_error(std::string("couldn't open file: (") + filename + ")")
|
: std::runtime_error(std::string("couldn't open file: (") + filename + ")")
|
||||||
{
|
{
|
||||||
|
|
129
source/number_format.cpp
Normal file
129
source/number_format.cpp
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
#include "styles/number_format.hpp"
|
||||||
|
|
||||||
|
namespace xlnt {
|
||||||
|
|
||||||
|
const std::unordered_map<number_format::format, std::string, number_format::format_hash> number_format::format_strings =
|
||||||
|
{
|
||||||
|
{format::general, "General"},
|
||||||
|
{format::text, "@"},
|
||||||
|
{format::number, "0"},
|
||||||
|
{format::number_00, "0.00"},
|
||||||
|
{format::number_comma_separated1, "#,##0.00"},
|
||||||
|
{format::number_comma_separated2, "#,##0.00_-"},
|
||||||
|
{format::percentage, "0%"},
|
||||||
|
{format::percentage_00, "0.00%"},
|
||||||
|
{format::date_yyyymmdd2, "yyyy-mm-dd"},
|
||||||
|
{format::date_yyyymmdd, "yy-mm-dd"},
|
||||||
|
{format::date_ddmmyyyy, "dd/mm/yy"},
|
||||||
|
{format::date_dmyslash, "d/m/y"},
|
||||||
|
{format::date_dmyminus, "d-m-y"},
|
||||||
|
{format::date_dmminus, "d-m"},
|
||||||
|
{format::date_myminus, "m-y"},
|
||||||
|
{format::date_xlsx14, "mm-dd-yy"},
|
||||||
|
{format::date_xlsx15, "d-mmm-yy"},
|
||||||
|
{format::date_xlsx16, "d-mmm"},
|
||||||
|
{format::date_xlsx17, "mmm-yy"},
|
||||||
|
{format::date_xlsx22, "m/d/yy h:mm"},
|
||||||
|
{format::date_datetime, "d/m/y h:mm"},
|
||||||
|
{format::date_time1, "h:mm AM/PM"},
|
||||||
|
{format::date_time2, "h:mm:ss AM/PM"},
|
||||||
|
{format::date_time3, "h:mm"},
|
||||||
|
{format::date_time4, "h:mm:ss"},
|
||||||
|
{format::date_time5, "mm:ss"},
|
||||||
|
{format::date_time6, "h:mm:ss"},
|
||||||
|
{format::date_time7, "i:s.S"},
|
||||||
|
{format::date_time8, "h:mm:ss@"},
|
||||||
|
{format::date_timedelta, "[hh]:mm:ss"},
|
||||||
|
{format::date_yyyymmddslash, "yy/mm/dd@"},
|
||||||
|
{format::currency_usd_simple, "\"$\"#,##0.00_-"},
|
||||||
|
{format::currency_usd, "$#,##0_-"},
|
||||||
|
{format::currency_eur_simple, "[$EUR ]#,##0.00_-"}
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::unordered_map<int, std::string> number_format::builtin_formats =
|
||||||
|
{
|
||||||
|
{0, "General"},
|
||||||
|
{1, "0"},
|
||||||
|
{2, "0.00"},
|
||||||
|
{3, "#,##0"},
|
||||||
|
{4, "#,##0.00"},
|
||||||
|
{5, "\"$\"#,##0_);(\"$\"#,##0)"},
|
||||||
|
{6, "\"$\"#,##0_);[Red](\"$\"#,##0)"},
|
||||||
|
{7, "\"$\"#,##0.00_);(\"$\"#,##0.00)"},
|
||||||
|
{8, "\"$\"#,##0.00_);[Red](\"$\"#,##0.00)"},
|
||||||
|
{9, "0%"},
|
||||||
|
{10, "0.00%"},
|
||||||
|
{11, "0.00E+00"},
|
||||||
|
{12, "# ?/?"},
|
||||||
|
{13, "# \?\?/??"}, //escape trigraph
|
||||||
|
{14, "mm-dd-yy"},
|
||||||
|
{15, "d-mmm-yy"},
|
||||||
|
{16, "d-mmm"},
|
||||||
|
{17, "mmm-yy"},
|
||||||
|
{18, "h:mm AM/PM"},
|
||||||
|
{19, "h:mm:ss AM/PM"},
|
||||||
|
{20, "h:mm"},
|
||||||
|
{21, "h:mm:ss"},
|
||||||
|
{22, "m/d/yy h:mm"},
|
||||||
|
|
||||||
|
{37, "#,##0_);(#,##0)"},
|
||||||
|
{38, "#,##0_);[Red](#,##0)"},
|
||||||
|
{39, "#,##0.00_);(#,##0.00)"},
|
||||||
|
{40, "#,##0.00_);[Red](#,##0.00)"},
|
||||||
|
|
||||||
|
{41, "_(* #,##0_);_(* \(#,##0\\);_(* \"-\"_);_(@_)"},
|
||||||
|
{42, "_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)"},
|
||||||
|
{43, "_(* #,##0.00_);_(* \(#,##0.00\\);_(* \"-\"??_);_(@_)"},
|
||||||
|
|
||||||
|
{44, "_(\"$\"* #,##0.00_)_(\"$\"* \(#,##0.00\\)_(\"$\"* \"-\"??_)_(@_)"},
|
||||||
|
{45, "mm:ss"},
|
||||||
|
{46, "[h]:mm:ss"},
|
||||||
|
{47, "mmss.0"},
|
||||||
|
{48, "##0.0E+0"},
|
||||||
|
{49, "@"}
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::unordered_map<std::string, int> number_format::reversed_builtin_formats =
|
||||||
|
{
|
||||||
|
{"General", 0},
|
||||||
|
{"0", 1},
|
||||||
|
{"0.00", 2},
|
||||||
|
{"#,##0", 3},
|
||||||
|
{"#,##0.00", 4},
|
||||||
|
{"\"$\"#,##0_);(\"$\"#,##0)", 5},
|
||||||
|
{"\"$\"#,##0_);[Red](\"$\"#,##0)", 6},
|
||||||
|
{"\"$\"#,##0.00_);(\"$\"#,##0.00)", 7},
|
||||||
|
{"\"$\"#,##0.00_);[Red](\"$\"#,##0.00)", 8},
|
||||||
|
{"0%", 9},
|
||||||
|
{"0.00%", 10},
|
||||||
|
{"0.00E+00", 11},
|
||||||
|
{"# ?/?", 12},
|
||||||
|
{"# \?\?/??", 13}, //escape trigraph
|
||||||
|
{"mm-dd-yy", 14},
|
||||||
|
{"d-mmm-yy", 15},
|
||||||
|
{"d-mmm", 16},
|
||||||
|
{"mmm-yy", 17},
|
||||||
|
{"h:mm AM/PM", 18},
|
||||||
|
{"h:mm:ss AM/PM", 19},
|
||||||
|
{"h:mm", 20},
|
||||||
|
{"h:mm:ss", 21},
|
||||||
|
{"m/d/yy h:mm", 22},
|
||||||
|
|
||||||
|
{"#,##0_);(#,##0)", 37},
|
||||||
|
{"#,##0_);[Red](#,##0)", 38},
|
||||||
|
{"#,##0.00_);(#,##0.00)", 39},
|
||||||
|
{"#,##0.00_);[Red](#,##0.00)", 40},
|
||||||
|
|
||||||
|
{"_(* #,##0_);_(* \(#,##0\\);_(* \"-\"_);_(@_)", 41},
|
||||||
|
{"_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)", 42},
|
||||||
|
{"_(* #,##0.00_);_(* \(#,##0.00\\);_(* \"-\"??_);_(@_)", 43},
|
||||||
|
|
||||||
|
{"_(\"$\"* #,##0.00_)_(\"$\"* \(#,##0.00\\)_(\"$\"* \"-\"??_)_(@_)", 44},
|
||||||
|
{"mm:ss", 45},
|
||||||
|
{"[h]:mm:ss", 46},
|
||||||
|
{"mmss.0", 47},
|
||||||
|
{"##0.0E+0", 48},
|
||||||
|
{"@", 49}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace xlnt
|
218
source/range.cpp
218
source/range.cpp
|
@ -78,7 +78,15 @@ cell_vector::const_iterator cell_vector::const_iterator::operator++(int)
|
||||||
|
|
||||||
cell_vector::const_iterator &cell_vector::const_iterator::operator++()
|
cell_vector::const_iterator &cell_vector::const_iterator::operator++()
|
||||||
{
|
{
|
||||||
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
if(order_ == major_order::row)
|
||||||
|
{
|
||||||
|
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
current_cell_.set_row_index(current_cell_.get_row_index() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,36 +98,55 @@ const cell cell_vector::const_iterator::operator*()
|
||||||
|
|
||||||
cell_vector::iterator cell_vector::begin()
|
cell_vector::iterator cell_vector::begin()
|
||||||
{
|
{
|
||||||
return iterator(ws_, ref_.get_top_left());
|
return iterator(ws_, ref_.get_top_left(), order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_vector::iterator cell_vector::end()
|
cell_vector::iterator cell_vector::end()
|
||||||
{
|
{
|
||||||
|
if(order_ == major_order::row)
|
||||||
|
{
|
||||||
|
auto past_end = ref_.get_bottom_right();
|
||||||
|
past_end.set_column_index(past_end.get_column_index() + 1);
|
||||||
|
return iterator(ws_, past_end, order_);
|
||||||
|
}
|
||||||
|
|
||||||
auto past_end = ref_.get_bottom_right();
|
auto past_end = ref_.get_bottom_right();
|
||||||
past_end.set_column_index(past_end.get_column_index() + 1);
|
past_end.set_row_index(past_end.get_row_index() + 1);
|
||||||
return iterator(ws_, past_end);
|
return iterator(ws_, past_end, order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_vector::const_iterator cell_vector::cbegin() const
|
cell_vector::const_iterator cell_vector::cbegin() const
|
||||||
{
|
{
|
||||||
return const_iterator(ws_, ref_.get_top_left());
|
return const_iterator(ws_, ref_.get_top_left(), order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_vector::const_iterator cell_vector::cend() const
|
cell_vector::const_iterator cell_vector::cend() const
|
||||||
{
|
{
|
||||||
auto past_end = ref_.get_top_left();
|
if(order_ == major_order::row)
|
||||||
past_end.set_column_index(past_end.get_column_index() + 1);
|
{
|
||||||
return const_iterator(ws_, past_end);
|
auto past_end = ref_.get_bottom_right();
|
||||||
|
past_end.set_column_index(past_end.get_column_index() + 1);
|
||||||
|
return const_iterator(ws_, past_end, order_);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto past_end = ref_.get_bottom_right();
|
||||||
|
past_end.set_row_index(past_end.get_row_index() + 1);
|
||||||
|
return const_iterator(ws_, past_end, order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell cell_vector::operator[](std::size_t column_index)
|
cell cell_vector::operator[](std::size_t cell_index)
|
||||||
{
|
{
|
||||||
return get_cell(column_index);
|
return get_cell(cell_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t cell_vector::num_cells() const
|
std::size_t cell_vector::num_cells() const
|
||||||
{
|
{
|
||||||
return ref_.get_width() + 1;
|
if(order_ == major_order::row)
|
||||||
|
{
|
||||||
|
return ref_.get_width() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ref_.get_height() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_vector::cell_vector(worksheet ws, const range_reference &reference, major_order order)
|
cell_vector::cell_vector(worksheet ws, const range_reference &reference, major_order order)
|
||||||
|
@ -131,18 +158,33 @@ cell_vector::cell_vector(worksheet ws, const range_reference &reference, major_o
|
||||||
|
|
||||||
cell cell_vector::front()
|
cell cell_vector::front()
|
||||||
{
|
{
|
||||||
return get_cell(ref_.get_top_left().get_column_index());
|
if(order_ == major_order::row)
|
||||||
|
{
|
||||||
|
return get_cell(ref_.get_top_left().get_column_index());
|
||||||
|
}
|
||||||
|
|
||||||
|
return get_cell(ref_.get_top_left().get_row_index());
|
||||||
}
|
}
|
||||||
|
|
||||||
cell cell_vector::back()
|
cell cell_vector::back()
|
||||||
{
|
{
|
||||||
return get_cell(ref_.get_bottom_right().get_column_index());
|
if(order_ == major_order::row)
|
||||||
|
{
|
||||||
|
return get_cell(ref_.get_bottom_right().get_column_index());
|
||||||
|
}
|
||||||
|
|
||||||
|
return get_cell(ref_.get_top_left().get_row_index());
|
||||||
}
|
}
|
||||||
|
|
||||||
cell cell_vector::get_cell(std::size_t column_index)
|
cell cell_vector::get_cell(std::size_t index)
|
||||||
{
|
{
|
||||||
return ws_.get_cell(ref_.get_top_left().make_offset((int)column_index, 0));
|
if(order_ == major_order::row)
|
||||||
}
|
{
|
||||||
|
return ws_.get_cell(ref_.get_top_left().make_offset((int)index, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ws_.get_cell(ref_.get_top_left().make_offset(0, index));
|
||||||
|
}
|
||||||
|
|
||||||
range::range(worksheet ws, const range_reference &reference, major_order order)
|
range::range(worksheet ws, const range_reference &reference, major_order order)
|
||||||
: ws_(ws),
|
: ws_(ws),
|
||||||
|
@ -179,14 +221,26 @@ std::size_t range::length() const
|
||||||
bool range::operator==(const range &comparand) const
|
bool range::operator==(const range &comparand) const
|
||||||
{
|
{
|
||||||
return ref_ == comparand.ref_
|
return ref_ == comparand.ref_
|
||||||
&& ws_ == comparand.ws_;
|
&& ws_ == comparand.ws_
|
||||||
|
&& order_ == comparand.order_;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_vector range::get_vector(std::size_t vector_index)
|
cell_vector range::get_vector(std::size_t vector_index)
|
||||||
{
|
{
|
||||||
range_reference reference(ref_.get_top_left().get_column_index(), ref_.get_top_left().get_row_index() + (int)vector_index,
|
if(order_ == major_order::row)
|
||||||
ref_.get_bottom_right().get_column_index(), ref_.get_top_left().get_row_index() + (int)vector_index);
|
{
|
||||||
return cell_vector(ws_, reference);
|
range_reference reference(ref_.get_top_left().get_column_index(),
|
||||||
|
ref_.get_top_left().get_row_index() + (int)vector_index,
|
||||||
|
ref_.get_bottom_right().get_column_index(),
|
||||||
|
ref_.get_top_left().get_row_index() + (int)vector_index);
|
||||||
|
return cell_vector(ws_, reference, order_);
|
||||||
|
}
|
||||||
|
|
||||||
|
range_reference reference(ref_.get_top_left().get_column_index() + (int)vector_index,
|
||||||
|
ref_.get_top_left().get_row_index(),
|
||||||
|
ref_.get_top_left().get_column_index() + (int)vector_index,
|
||||||
|
ref_.get_bottom_right().get_row_index());
|
||||||
|
return cell_vector(ws_, reference, order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell range::get_cell(const cell_reference &ref)
|
cell range::get_cell(const cell_reference &ref)
|
||||||
|
@ -196,34 +250,66 @@ cell range::get_cell(const cell_reference &ref)
|
||||||
|
|
||||||
range::iterator range::begin()
|
range::iterator range::begin()
|
||||||
{
|
{
|
||||||
cell_reference top_right(ref_.get_bottom_right().get_column_index(),
|
if(order_ == major_order::row)
|
||||||
ref_.get_top_left().get_row_index());
|
{
|
||||||
range_reference row_range(ref_.get_top_left(), top_right);
|
cell_reference top_right(ref_.get_bottom_right().get_column_index(),
|
||||||
|
ref_.get_top_left().get_row_index());
|
||||||
|
range_reference row_range(ref_.get_top_left(), top_right);
|
||||||
|
return iterator(ws_, row_range, order_);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell_reference bottom_left(ref_.get_top_left().get_column_index(),
|
||||||
|
ref_.get_bottom_right().get_row_index());
|
||||||
|
range_reference row_range(ref_.get_top_left(), bottom_left);
|
||||||
return iterator(ws_, row_range, order_);
|
return iterator(ws_, row_range, order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
range::iterator range::end()
|
range::iterator range::end()
|
||||||
{
|
{
|
||||||
auto past_end_row_index = ref_.get_bottom_right().get_row_index() + 1;
|
if(order_ == major_order::row)
|
||||||
cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index);
|
{
|
||||||
cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index);
|
auto past_end_row_index = ref_.get_bottom_right().get_row_index() + 1;
|
||||||
return iterator(ws_, range_reference(bottom_left, bottom_right), order_);
|
cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index);
|
||||||
|
cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index);
|
||||||
|
return iterator(ws_, range_reference(bottom_left, bottom_right), order_);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto past_end_column_index = ref_.get_bottom_right().get_column_index() + 1;
|
||||||
|
cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row_index());
|
||||||
|
cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row_index());
|
||||||
|
return iterator(ws_, range_reference(top_right, bottom_right), order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
range::const_iterator range::cbegin() const
|
range::const_iterator range::cbegin() const
|
||||||
{
|
{
|
||||||
cell_reference top_right(ref_.get_bottom_right().get_column_index(),
|
if(order_ == major_order::row)
|
||||||
ref_.get_top_left().get_row_index());
|
{
|
||||||
range_reference row_range(ref_.get_top_left(), top_right);
|
cell_reference top_right(ref_.get_bottom_right().get_column_index(),
|
||||||
|
ref_.get_top_left().get_row_index());
|
||||||
|
range_reference row_range(ref_.get_top_left(), top_right);
|
||||||
|
return const_iterator(ws_, row_range, order_);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell_reference bottom_left(ref_.get_top_left().get_column_index(),
|
||||||
|
ref_.get_bottom_right().get_row_index());
|
||||||
|
range_reference row_range(ref_.get_top_left(), bottom_left);
|
||||||
return const_iterator(ws_, row_range, order_);
|
return const_iterator(ws_, row_range, order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
range::const_iterator range::cend() const
|
range::const_iterator range::cend() const
|
||||||
{
|
{
|
||||||
auto past_end_row_index = ref_.get_bottom_right().get_row_index() + 1;
|
if(order_ == major_order::row)
|
||||||
cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index);
|
{
|
||||||
cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index);
|
auto past_end_row_index = ref_.get_bottom_right().get_row_index() + 1;
|
||||||
return const_iterator(ws_, range_reference(bottom_left, bottom_right), order_);
|
cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index);
|
||||||
|
cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index);
|
||||||
|
return const_iterator(ws_, range_reference(bottom_left, bottom_right), order_);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto past_end_column_index = ref_.get_bottom_right().get_column_index() + 1;
|
||||||
|
cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row_index());
|
||||||
|
cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row_index());
|
||||||
|
return const_iterator(ws_, range_reference(top_right, bottom_right), order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
range::iterator::iterator(worksheet ws, const range_reference &start_cell, major_order order = major_order::row)
|
range::iterator::iterator(worksheet ws, const range_reference &start_cell, major_order order = major_order::row)
|
||||||
|
@ -241,7 +327,8 @@ range::iterator::~iterator()
|
||||||
bool range::iterator::operator==(const iterator &rhs)
|
bool range::iterator::operator==(const iterator &rhs)
|
||||||
{
|
{
|
||||||
return ws_ == rhs.ws_
|
return ws_ == rhs.ws_
|
||||||
&& current_cell_ == rhs.current_cell_;
|
&& current_cell_ == rhs.current_cell_
|
||||||
|
&& order_ == rhs.order_;
|
||||||
}
|
}
|
||||||
|
|
||||||
range::iterator range::iterator::operator++(int)
|
range::iterator range::iterator::operator++(int)
|
||||||
|
@ -253,17 +340,34 @@ range::iterator range::iterator::operator++(int)
|
||||||
|
|
||||||
range::iterator &range::iterator::operator++()
|
range::iterator &range::iterator::operator++()
|
||||||
{
|
{
|
||||||
current_cell_.set_row_index(current_cell_.get_row_index() + 1);
|
if(order_ == major_order::row)
|
||||||
|
{
|
||||||
|
current_cell_.set_row_index(current_cell_.get_row_index() + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_vector range::iterator::operator*()
|
cell_vector range::iterator::operator*()
|
||||||
{
|
{
|
||||||
range_reference reference(range_.get_top_left().get_column_index(),
|
if(order_ == major_order::row)
|
||||||
current_cell_.get_row_index(),
|
{
|
||||||
range_.get_bottom_right().get_column_index(),
|
range_reference reference(range_.get_top_left().get_column_index(),
|
||||||
current_cell_.get_row_index());
|
current_cell_.get_row_index(),
|
||||||
return cell_vector(ws_, reference);
|
range_.get_bottom_right().get_column_index(),
|
||||||
|
current_cell_.get_row_index());
|
||||||
|
return cell_vector(ws_, reference, order_);
|
||||||
|
}
|
||||||
|
|
||||||
|
range_reference reference(current_cell_.get_column_index(),
|
||||||
|
range_.get_top_left().get_row_index(),
|
||||||
|
current_cell_.get_column_index(),
|
||||||
|
range_.get_bottom_right().get_row_index());
|
||||||
|
return cell_vector(ws_, reference, order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
range::const_iterator::const_iterator(worksheet ws, const range_reference &start_cell, major_order order = major_order::row)
|
range::const_iterator::const_iterator(worksheet ws, const range_reference &start_cell, major_order order = major_order::row)
|
||||||
|
@ -281,7 +385,8 @@ range::const_iterator::~const_iterator()
|
||||||
bool range::const_iterator::operator==(const const_iterator &rhs)
|
bool range::const_iterator::operator==(const const_iterator &rhs)
|
||||||
{
|
{
|
||||||
return ws_ == rhs.ws_
|
return ws_ == rhs.ws_
|
||||||
&& rhs.current_cell_ == current_cell_;
|
&& rhs.current_cell_ == current_cell_
|
||||||
|
&& order_ == rhs.order_;
|
||||||
}
|
}
|
||||||
|
|
||||||
range::const_iterator range::const_iterator::operator++(int)
|
range::const_iterator range::const_iterator::operator++(int)
|
||||||
|
@ -293,17 +398,34 @@ range::const_iterator range::const_iterator::operator++(int)
|
||||||
|
|
||||||
range::const_iterator &range::const_iterator::operator++()
|
range::const_iterator &range::const_iterator::operator++()
|
||||||
{
|
{
|
||||||
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
if(order_ == major_order::row)
|
||||||
|
{
|
||||||
|
current_cell_.set_row_index(current_cell_.get_row_index() + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cell_vector range::const_iterator::operator*()
|
const cell_vector range::const_iterator::operator*()
|
||||||
{
|
{
|
||||||
range_reference reference(range_.get_top_left().get_column_index(),
|
if(order_ == major_order::row)
|
||||||
current_cell_.get_row_index(),
|
{
|
||||||
range_.get_bottom_right().get_column_index(),
|
range_reference reference(range_.get_top_left().get_column_index(),
|
||||||
current_cell_.get_row_index());
|
current_cell_.get_row_index(),
|
||||||
return cell_vector(ws_, reference);
|
range_.get_bottom_right().get_column_index(),
|
||||||
|
current_cell_.get_row_index());
|
||||||
|
return cell_vector(ws_, reference, order_);
|
||||||
|
}
|
||||||
|
|
||||||
|
range_reference reference(current_cell_.get_column_index(),
|
||||||
|
range_.get_top_left().get_row_index(),
|
||||||
|
current_cell_.get_column_index(),
|
||||||
|
range_.get_bottom_right().get_row_index());
|
||||||
|
return cell_vector(ws_, reference, order_);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
|
|
@ -183,7 +183,7 @@ void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const
|
||||||
throw std::runtime_error("mismatch between count and actual number of merged cells");
|
throw std::runtime_error("mismatch between count and actual number of merged cells");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto row_node : sheet_data_node.children("row"))
|
for(auto row_node : sheet_data_node.children("row"))
|
||||||
{
|
{
|
||||||
int row_index = row_node.attribute("r").as_int();
|
int row_index = row_node.attribute("r").as_int();
|
||||||
|
@ -199,55 +199,78 @@ void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const
|
||||||
|
|
||||||
if(cell_node != nullptr)
|
if(cell_node != nullptr)
|
||||||
{
|
{
|
||||||
if(cell_node.attribute("t") != nullptr && std::string(cell_node.attribute("t").as_string()) == "inlineStr") // inline string
|
bool has_value = cell_node.child("v").text() != nullptr;
|
||||||
|
std::string value = cell_node.child("v").text().as_string();
|
||||||
|
|
||||||
|
bool has_type = cell_node.attribute("t") != nullptr;
|
||||||
|
std::string type = cell_node.attribute("t").as_string();
|
||||||
|
|
||||||
|
bool has_style = cell_node.attribute("s") != nullptr;
|
||||||
|
std::string style = cell_node.attribute("s").as_string();
|
||||||
|
|
||||||
|
if(has_type && type == "inlineStr") // inline string
|
||||||
{
|
{
|
||||||
ws.get_cell(address) = cell_node.child("is").child("t").text().as_string();
|
ws.get_cell(address) = cell_node.child("is").child("t").text().as_string();
|
||||||
}
|
}
|
||||||
else if(cell_node.attribute("t") != nullptr && std::string(cell_node.attribute("t").as_string()) == "s") // shared string
|
else if(has_type && type == "s") // shared string
|
||||||
{
|
{
|
||||||
ws.get_cell(address) = string_table.at(cell_node.child("v").text().as_int());
|
ws.get_cell(address) = string_table.at(cell_node.child("v").text().as_int());
|
||||||
}
|
}
|
||||||
else if(cell_node.attribute("s") != nullptr)
|
else if(has_type && type == "b") // boolean
|
||||||
{
|
{
|
||||||
auto style_index = cell_node.attribute("s").as_int();
|
ws.get_cell(address) = value != "0";
|
||||||
auto number_format_id = number_format_ids.at(style_index);
|
}
|
||||||
|
else if(has_style)
|
||||||
|
{
|
||||||
|
auto number_format_id = number_format_ids.at(std::stoi(style));
|
||||||
|
|
||||||
if(number_format_id == 0) // integer
|
if(number_format_id == 0) // integer
|
||||||
{
|
{
|
||||||
ws.get_cell(address) = cell_node.child("v").text().as_int();
|
ws.get_cell(address) = std::stoi(value);
|
||||||
}
|
}
|
||||||
else if(number_format_id == 14) // date
|
else if(number_format_id == 14) // date
|
||||||
{
|
{
|
||||||
ws.get_cell(address) = datetime::from_number(cell_node.child("v").text().as_double(), ws.get_parent().get_properties().excel_base_date);
|
auto base_date = ws.get_parent().get_properties().excel_base_date;
|
||||||
|
ws.get_cell(address) = datetime::from_number(std::stod(value), base_date);
|
||||||
|
ws.get_cell(address).get_style().get_number_format().set_format_code(number_format::format::date_xlsx14);
|
||||||
}
|
}
|
||||||
else if(number_format_id == 18) // time
|
else if(number_format_id == 18) // time
|
||||||
{
|
{
|
||||||
ws.get_cell(address) = time::from_number(cell_node.child("v").text().as_double());
|
ws.get_cell(address) = time::from_number(std::stod(value));
|
||||||
}
|
}
|
||||||
else if(number_format_id == 22) // datetime
|
else if(number_format_id == 22) // datetime
|
||||||
{
|
{
|
||||||
ws.get_cell(address) = datetime::from_number(cell_node.child("v").text().as_double(), ws.get_parent().get_properties().excel_base_date);
|
auto base_date = ws.get_parent().get_properties().excel_base_date;
|
||||||
|
ws.get_cell(address) = datetime::from_number(std::stod(value), base_date);
|
||||||
}
|
}
|
||||||
else if(number_format_id == 14) // decimal
|
else if(number_format_id == 14) // decimal
|
||||||
{
|
{
|
||||||
ws.get_cell(address) = cell_node.child("v").text().as_double();
|
ws.get_cell(address) = std::stod(value);
|
||||||
}
|
}
|
||||||
else if(number_format_id == 9) // percent
|
else if(number_format_id == 9) // percent
|
||||||
{
|
{
|
||||||
ws.get_cell(address) = cell_node.child("v").text().as_double();
|
ws.get_cell(address) = std::stod(value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw number_format_id;
|
throw number_format_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(cell_node.child("v") != nullptr)
|
else if(has_value)
|
||||||
{
|
{
|
||||||
ws.get_cell(address) = cell_node.child("v").text().as_string();
|
ws.get_cell(address) = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto auto_filter_node = root_node.child("autoFilter");
|
||||||
|
|
||||||
|
if(auto_filter_node != nullptr)
|
||||||
|
{
|
||||||
|
range_reference ref(auto_filter_node.attribute("ref").as_string());
|
||||||
|
ws.auto_filter(ref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::read_worksheet(worksheet ws, const std::string &xml_string, const std::vector<std::string> &string_table, const std::vector<int> &number_format_ids)
|
void reader::read_worksheet(worksheet ws, const std::string &xml_string, const std::vector<std::string> &string_table, const std::vector<int> &number_format_ids)
|
||||||
|
@ -289,7 +312,7 @@ std::vector<std::string> reader::read_shared_string(const std::string &xml_strin
|
||||||
return shared_strings;
|
return shared_strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
workbook reader::load_workbook(const std::string &filename, bool guess_types)
|
workbook reader::load_workbook(const std::string &filename, bool /*guess_types*/)
|
||||||
{
|
{
|
||||||
workbook wb;
|
workbook wb;
|
||||||
wb.load(filename);
|
wb.load(filename);
|
||||||
|
|
|
@ -203,7 +203,7 @@ range worksheet::get_named_range(const std::string &name)
|
||||||
{
|
{
|
||||||
if(!has_named_range(name))
|
if(!has_named_range(name))
|
||||||
{
|
{
|
||||||
throw std::runtime_error("named range not found for this worksheet");
|
throw named_range_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
return get_range(d_->named_ranges_[name]);
|
return get_range(d_->named_ranges_[name]);
|
||||||
|
@ -413,7 +413,7 @@ void worksheet::append(const std::unordered_map<std::string, std::string> &cells
|
||||||
|
|
||||||
void worksheet::append(const std::unordered_map<int, std::string> &cells)
|
void worksheet::append(const std::unordered_map<int, std::string> &cells)
|
||||||
{
|
{
|
||||||
int row = get_highest_row() - 1;
|
int row = get_highest_row() - 1;
|
||||||
|
|
||||||
if(d_->cell_map_.size() != 0)
|
if(d_->cell_map_.size() != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@ int main( int argc, char *argv[] ) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
bool suite_test_cell_init = false;
|
bool suite_test_cell_init = false;
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_cell.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_cell.hpp"
|
||||||
|
|
||||||
static test_cell suite_test_cell;
|
static test_cell suite_test_cell;
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ public:
|
||||||
void runTest() { suite_test_cell.test_cell_offset(); }
|
void runTest() { suite_test_cell.test_cell_offset(); }
|
||||||
} testDescription_suite_test_cell_test_cell_offset;
|
} testDescription_suite_test_cell_test_cell_offset;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_chart.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_chart.hpp"
|
||||||
|
|
||||||
static test_chart suite_test_chart;
|
static test_chart suite_test_chart;
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ public:
|
||||||
void runTest() { suite_test_chart.test_write_chart_scatter(); }
|
void runTest() { suite_test_chart.test_write_chart_scatter(); }
|
||||||
} testDescription_suite_test_chart_test_write_chart_scatter;
|
} testDescription_suite_test_chart_test_write_chart_scatter;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_named_range.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_named_range.hpp"
|
||||||
|
|
||||||
static test_named_range suite_test_named_range;
|
static test_named_range suite_test_named_range;
|
||||||
|
|
||||||
|
@ -444,7 +444,7 @@ public:
|
||||||
void runTest() { suite_test_named_range.test_can_be_saved(); }
|
void runTest() { suite_test_named_range.test_can_be_saved(); }
|
||||||
} testDescription_suite_test_named_range_test_can_be_saved;
|
} testDescription_suite_test_named_range_test_can_be_saved;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_number_format.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_number_format.hpp"
|
||||||
|
|
||||||
static test_number_format suite_test_number_format;
|
static test_number_format suite_test_number_format;
|
||||||
|
|
||||||
|
@ -547,7 +547,7 @@ public:
|
||||||
void runTest() { suite_test_number_format.test_mac_date(); }
|
void runTest() { suite_test_number_format.test_mac_date(); }
|
||||||
} testDescription_suite_test_number_format_test_mac_date;
|
} testDescription_suite_test_number_format_test_mac_date;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_props.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_props.hpp"
|
||||||
|
|
||||||
static test_props suite_test_props;
|
static test_props suite_test_props;
|
||||||
|
|
||||||
|
@ -590,7 +590,7 @@ public:
|
||||||
void runTest() { suite_test_props.test_write_properties_app(); }
|
void runTest() { suite_test_props.test_write_properties_app(); }
|
||||||
} testDescription_suite_test_props_test_write_properties_app;
|
} testDescription_suite_test_props_test_write_properties_app;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_read.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_read.hpp"
|
||||||
|
|
||||||
static test_read suite_test_read;
|
static test_read suite_test_read;
|
||||||
|
|
||||||
|
@ -755,41 +755,41 @@ public:
|
||||||
|
|
||||||
static class TestDescription_suite_test_read_test_read_sheets : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_read_test_read_sheets : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_read_test_read_sheets() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 269, "test_read_sheets" ) {}
|
TestDescription_suite_test_read_test_read_sheets() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 275, "test_read_sheets" ) {}
|
||||||
void runTest() { suite_test_read.test_read_sheets(); }
|
void runTest() { suite_test_read.test_read_sheets(); }
|
||||||
} testDescription_suite_test_read_test_read_sheets;
|
} testDescription_suite_test_read_test_read_sheets;
|
||||||
|
|
||||||
static class TestDescription_suite_test_read_test_guess_types : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_read_test_guess_types : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_read_test_guess_types() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 290, "test_guess_types" ) {}
|
TestDescription_suite_test_read_test_guess_types() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 296, "test_guess_types" ) {}
|
||||||
void runTest() { suite_test_read.test_guess_types(); }
|
void runTest() { suite_test_read.test_guess_types(); }
|
||||||
} testDescription_suite_test_read_test_guess_types;
|
} testDescription_suite_test_read_test_guess_types;
|
||||||
|
|
||||||
static class TestDescription_suite_test_read_test_read_autofilter : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_read_test_read_autofilter : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_read_test_read_autofilter() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 306, "test_read_autofilter" ) {}
|
TestDescription_suite_test_read_test_read_autofilter() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 313, "test_read_autofilter" ) {}
|
||||||
void runTest() { suite_test_read.test_read_autofilter(); }
|
void runTest() { suite_test_read.test_read_autofilter(); }
|
||||||
} testDescription_suite_test_read_test_read_autofilter;
|
} testDescription_suite_test_read_test_read_autofilter;
|
||||||
|
|
||||||
static class TestDescription_suite_test_read_test_bad_formats_xlsb : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_read_test_bad_formats_xlsb : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_read_test_bad_formats_xlsb() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 314, "test_bad_formats_xlsb" ) {}
|
TestDescription_suite_test_read_test_bad_formats_xlsb() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 321, "test_bad_formats_xlsb" ) {}
|
||||||
void runTest() { suite_test_read.test_bad_formats_xlsb(); }
|
void runTest() { suite_test_read.test_bad_formats_xlsb(); }
|
||||||
} testDescription_suite_test_read_test_bad_formats_xlsb;
|
} testDescription_suite_test_read_test_bad_formats_xlsb;
|
||||||
|
|
||||||
static class TestDescription_suite_test_read_test_bad_formats_xls : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_read_test_bad_formats_xls : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_read_test_bad_formats_xls() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 320, "test_bad_formats_xls" ) {}
|
TestDescription_suite_test_read_test_bad_formats_xls() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 327, "test_bad_formats_xls" ) {}
|
||||||
void runTest() { suite_test_read.test_bad_formats_xls(); }
|
void runTest() { suite_test_read.test_bad_formats_xls(); }
|
||||||
} testDescription_suite_test_read_test_bad_formats_xls;
|
} testDescription_suite_test_read_test_bad_formats_xls;
|
||||||
|
|
||||||
static class TestDescription_suite_test_read_test_bad_formats_no : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_read_test_bad_formats_no : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_read_test_bad_formats_no() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 326, "test_bad_formats_no" ) {}
|
TestDescription_suite_test_read_test_bad_formats_no() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 333, "test_bad_formats_no" ) {}
|
||||||
void runTest() { suite_test_read.test_bad_formats_no(); }
|
void runTest() { suite_test_read.test_bad_formats_no(); }
|
||||||
} testDescription_suite_test_read_test_bad_formats_no;
|
} testDescription_suite_test_read_test_bad_formats_no;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_strings.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_strings.hpp"
|
||||||
|
|
||||||
static test_strings suite_test_strings;
|
static test_strings suite_test_strings;
|
||||||
|
|
||||||
|
@ -820,7 +820,7 @@ public:
|
||||||
void runTest() { suite_test_strings.test_formatted_string_table(); }
|
void runTest() { suite_test_strings.test_formatted_string_table(); }
|
||||||
} testDescription_suite_test_strings_test_formatted_string_table;
|
} testDescription_suite_test_strings_test_formatted_string_table;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_style.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_style.hpp"
|
||||||
|
|
||||||
static test_style suite_test_style;
|
static test_style suite_test_style;
|
||||||
|
|
||||||
|
@ -917,7 +917,7 @@ public:
|
||||||
void runTest() { suite_test_style.test_read_cell_style(); }
|
void runTest() { suite_test_style.test_read_cell_style(); }
|
||||||
} testDescription_suite_test_style_test_read_cell_style;
|
} testDescription_suite_test_style_test_read_cell_style;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_theme.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_theme.hpp"
|
||||||
|
|
||||||
static test_theme suite_test_theme;
|
static test_theme suite_test_theme;
|
||||||
|
|
||||||
|
@ -930,7 +930,7 @@ public:
|
||||||
void runTest() { suite_test_theme.test_write_theme(); }
|
void runTest() { suite_test_theme.test_write_theme(); }
|
||||||
} testDescription_suite_test_theme_test_write_theme;
|
} testDescription_suite_test_theme_test_write_theme;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_workbook.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_workbook.hpp"
|
||||||
|
|
||||||
static test_workbook suite_test_workbook;
|
static test_workbook suite_test_workbook;
|
||||||
|
|
||||||
|
@ -1051,7 +1051,7 @@ public:
|
||||||
void runTest() { suite_test_workbook.test_write_regular_float(); }
|
void runTest() { suite_test_workbook.test_write_regular_float(); }
|
||||||
} testDescription_suite_test_workbook_test_write_regular_float;
|
} testDescription_suite_test_workbook_test_write_regular_float;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_worksheet.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_worksheet.hpp"
|
||||||
|
|
||||||
static test_worksheet suite_test_worksheet;
|
static test_worksheet suite_test_worksheet;
|
||||||
|
|
||||||
|
@ -1268,7 +1268,7 @@ public:
|
||||||
void runTest() { suite_test_worksheet.test_page_options(); }
|
void runTest() { suite_test_worksheet.test_page_options(); }
|
||||||
} testDescription_suite_test_worksheet_test_page_options;
|
} testDescription_suite_test_worksheet_test_page_options;
|
||||||
|
|
||||||
#include "/Users/thomas/Development/xlnt/tests/test_write.hpp"
|
#include "/home/thomas/Development/xlnt/tests/test_write.hpp"
|
||||||
|
|
||||||
static test_write suite_test_write;
|
static test_write suite_test_write;
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ public:
|
||||||
{
|
{
|
||||||
auto wb = workbook_with_styles();
|
auto wb = workbook_with_styles();
|
||||||
auto ws = wb["Sheet1"];
|
auto ws = wb["Sheet1"];
|
||||||
TS_ASSERT_EQUALS(ws.get_cell("A3").get_style().get_number_format().get_format_code(), xlnt::number_format::format::number00);
|
TS_ASSERT_EQUALS(ws.get_cell("A3").get_style().get_number_format().get_format_code(), xlnt::number_format::format::number_00);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_read_workbook_with_styles_time()
|
void test_read_workbook_with_styles_time()
|
||||||
|
@ -121,7 +121,7 @@ public:
|
||||||
{
|
{
|
||||||
auto wb = workbook_with_styles();
|
auto wb = workbook_with_styles();
|
||||||
auto ws = wb["Sheet1"];
|
auto ws = wb["Sheet1"];
|
||||||
TS_ASSERT_EQUALS(ws.get_cell("A5").get_style().get_number_format().get_format_code(), xlnt::number_format::format::percentage00);
|
TS_ASSERT_EQUALS(ws.get_cell("A5").get_style().get_number_format().get_format_code(), xlnt::number_format::format::percentage_00);
|
||||||
}
|
}
|
||||||
|
|
||||||
xlnt::workbook date_mac_1904()
|
xlnt::workbook date_mac_1904()
|
||||||
|
@ -176,7 +176,7 @@ public:
|
||||||
|
|
||||||
void test_repair_central_directory()
|
void test_repair_central_directory()
|
||||||
{
|
{
|
||||||
TS_ASSERT(false);
|
TS_SKIP("repair not yet implemented");
|
||||||
/*
|
/*
|
||||||
std::string data_a = "foobarbaz" + xlnt::CentralDirectorySignature;
|
std::string data_a = "foobarbaz" + xlnt::CentralDirectorySignature;
|
||||||
std::string data_b = "bazbarfoo12345678901234567890";
|
std::string data_b = "bazbarfoo12345678901234567890";
|
||||||
|
@ -198,7 +198,7 @@ public:
|
||||||
|
|
||||||
void test_read_cell_formulae()
|
void test_read_cell_formulae()
|
||||||
{
|
{
|
||||||
TS_ASSERT(false);
|
TS_SKIP("fast parse not yet implemented");
|
||||||
/*
|
/*
|
||||||
xlnt::workbook wb;
|
xlnt::workbook wb;
|
||||||
auto ws = wb.get_active_sheet();
|
auto ws = wb.get_active_sheet();
|
||||||
|
@ -218,22 +218,22 @@ public:
|
||||||
|
|
||||||
void test_read_complex_formulae()
|
void test_read_complex_formulae()
|
||||||
{
|
{
|
||||||
TS_ASSERT(false);
|
TS_SKIP("complex formulae not yet implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_data_only()
|
void test_data_only()
|
||||||
{
|
{
|
||||||
TS_ASSERT(false);
|
TS_SKIP("data only not yet implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_detect_worksheets()
|
void test_detect_worksheets()
|
||||||
{
|
{
|
||||||
TS_ASSERT(false);
|
TS_SKIP("detect worksheets not yet implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_read_rels()
|
void test_read_rels()
|
||||||
{
|
{
|
||||||
TS_ASSERT(false);
|
TS_SKIP("not yet implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_read_content_types()
|
void test_read_content_types()
|
||||||
|
@ -256,10 +256,16 @@ public:
|
||||||
{"/docProps/app.xml", "application/vnd.openxmlformats-officedocument.extended-properties+xml"}
|
{"/docProps/app.xml", "application/vnd.openxmlformats-officedocument.extended-properties+xml"}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto path = PathHelper::GetDataDirectory("/reader/bug137.xlsx");
|
auto path = PathHelper::GetDataDirectory("/reader/contains_chartsheets.xlsx");
|
||||||
xlnt::zip_file f(path, xlnt::file_mode::open);
|
xlnt::zip_file f(path, xlnt::file_mode::open);
|
||||||
auto result = xlnt::reader::read_content_types(f);
|
auto result = xlnt::reader::read_content_types(f);
|
||||||
|
|
||||||
|
if(result.size() != expected.size())
|
||||||
|
{
|
||||||
|
TS_ASSERT_EQUALS(result.size(), expected.size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for(std::size_t i = 0; i < expected.size(); i++)
|
for(std::size_t i = 0; i < expected.size(); i++)
|
||||||
{
|
{
|
||||||
TS_ASSERT_EQUALS(result[i], expected[i]);
|
TS_ASSERT_EQUALS(result[i], expected[i]);
|
||||||
|
@ -289,6 +295,7 @@ public:
|
||||||
|
|
||||||
void test_guess_types()
|
void test_guess_types()
|
||||||
{
|
{
|
||||||
|
TS_SKIP("type guessing not yet implemented");
|
||||||
bool guess;
|
bool guess;
|
||||||
xlnt::cell::type dtype;
|
xlnt::cell::type dtype;
|
||||||
std::vector<std::pair<bool, xlnt::cell::type>> test_cases = {{true, xlnt::cell::type::numeric}, {false, xlnt::cell::type::string}};
|
std::vector<std::pair<bool, xlnt::cell::type>> test_cases = {{true, xlnt::cell::type::numeric}, {false, xlnt::cell::type::string}};
|
||||||
|
|
|
@ -83,7 +83,7 @@ public:
|
||||||
void test_bad_named_range()
|
void test_bad_named_range()
|
||||||
{
|
{
|
||||||
xlnt::worksheet ws(wb_);
|
xlnt::worksheet ws(wb_);
|
||||||
TS_ASSERT_THROWS_ANYTHING(ws.get_range("bad_range"));
|
TS_ASSERT_THROWS(ws.get_named_range("bad_range"), xlnt::named_range_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_named_range_wrong_sheet()
|
void test_named_range_wrong_sheet()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user