diff --git a/include/xlnt/cell/cell.hpp b/include/xlnt/cell/cell.hpp
index 30f5f63e..82ddf70d 100644
--- a/include/xlnt/cell/cell.hpp
+++ b/include/xlnt/cell/cell.hpp
@@ -115,7 +115,7 @@ public:
// style shortcuts
std::string get_number_format();
std::string get_number_format() const;
- void set_number_format(const std::string &format_code);
+ void set_number_format(const std::string &format_code, int index = -1);
font &get_font();
const font &get_font() const;
fill &get_fill();
@@ -144,6 +144,16 @@ public:
bool has_formula() const;
// printing
+
+ ///
+ /// Returns a string describing this cell like .
+ /// |
+ std::string to_repr() const;
+
+ ///
+ /// Returns a string representing the value of this cell. If the data type is not a string,
+ /// it will be converted according to the number format.
+ ///
std::string to_string() const;
// merging
@@ -161,8 +171,6 @@ public:
// operators
cell &operator=(const cell &rhs);
- std::ostream &print(std::ostream &stream, bool convert) const;
-
bool operator==(const cell &comparand) const;
bool operator==(std::nullptr_t) const;
@@ -178,7 +186,7 @@ private:
inline std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell)
{
- return cell.print(stream, true);
+ return stream << cell.to_string();
}
} // namespace xlnt
diff --git a/include/xlnt/reader/reader.hpp b/include/xlnt/reader/reader.hpp
index a94d527c..001dd855 100644
--- a/include/xlnt/reader/reader.hpp
+++ b/include/xlnt/reader/reader.hpp
@@ -46,8 +46,8 @@ public:
static std::vector read_relationships(zip_file &content, const std::string &filename);
static std::vector> read_content_types(zip_file &archive);
static std::string determine_document_type(const std::vector> &override_types);
- static worksheet read_worksheet(std::istream &handle, workbook &wb, const std::string &title, const std::vector &string_table);
- static void read_worksheet(worksheet ws, const std::string &xml_string, const std::vector &string_table, const std::vector &number_format_ids);
+ static worksheet read_worksheet(std::istream &handle, workbook &wb, const std::string &title, const std::vector &string_table, const std::unordered_map &custom_number_formats);
+ static void read_worksheet(worksheet ws, const std::string &xml_string, const std::vector &string_table, const std::vector &number_format_ids, const std::unordered_map &custom_number_formats);
static std::vector read_shared_string(const std::string &xml_string);
static std::string read_dimension(const std::string &xml_string);
static document_properties read_properties_core(const std::string &xml_string);
diff --git a/include/xlnt/styles/number_format.hpp b/include/xlnt/styles/number_format.hpp
index 08579886..dde0e70c 100644
--- a/include/xlnt/styles/number_format.hpp
+++ b/include/xlnt/styles/number_format.hpp
@@ -90,11 +90,45 @@ public:
static bool is_builtin(const std::string &format);
number_format() : format_code_(format::general), format_index_(0) {}
- number_format(format code) : format_code_(code) {}
+ number_format(format code) : format_code_(code), format_index_(reversed_builtin_formats().at(format_strings().at(code))) {}
format get_format_code() const { return format_code_; }
- void set_format_code(format format_code) { format_code_ = format_code; }
- void set_format_code_string(const std::string &format_code) { custom_format_code_ = format_code; format_code_ = format::unknown; }
+
+ void set_format_code(format format_code, int index = -1)
+ {
+ format_code_ = format_code;
+
+ if(format_code_ != format::unknown)
+ {
+ set_format_code_string(format_strings().at(format_code), index);
+ }
+ }
+
+ void set_format_code_string(const std::string &format_code, int index)
+ {
+ custom_format_code_ = format_code;
+ format_index_ = index;
+
+ const auto &reversed = reversed_builtin_formats();
+ auto match = reversed.find(format_code);
+
+ format_code_ = format::unknown;
+
+ if(match != reversed.end())
+ {
+ format_index_ = match->second;
+
+ for(const auto &p : format_strings())
+ {
+ if(p.second == format_code)
+ {
+ format_code_ = p.first;
+ break;
+ }
+ }
+ }
+
+ }
std::string get_format_code_string() const;
private:
diff --git a/include/xlnt/writer/style_writer.hpp b/include/xlnt/writer/style_writer.hpp
index 716093ff..abd551b4 100644
--- a/include/xlnt/writer/style_writer.hpp
+++ b/include/xlnt/writer/style_writer.hpp
@@ -43,6 +43,8 @@ public:
std::string write_table() const;
std::vector