mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
begin work on handling properties correctly
This commit is contained in:
parent
753597510d
commit
f18e9dbc09
|
@ -291,6 +291,11 @@ public:
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool has_core_property(const std::string &property_name) const;
|
bool has_core_property(const std::string &property_name) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::vector<std::string> core_properties() const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -308,6 +313,11 @@ public:
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool has_extended_property(const std::string &property_name) const;
|
bool has_extended_property(const std::string &property_name) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::vector<std::string> extended_properties() const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -325,6 +335,11 @@ public:
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool has_custom_property(const std::string &property_name) const;
|
bool has_custom_property(const std::string &property_name) const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
std::vector<std::string> custom_properties() const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -124,7 +124,8 @@ const std::unordered_map<std::string, std::string> &constants::namespaces()
|
||||||
{"encryption-password", "http://schemas.microsoft.com/office/2006/keyEncryptor/password"},
|
{"encryption-password", "http://schemas.microsoft.com/office/2006/keyEncryptor/password"},
|
||||||
{"encryption-certificate", "http://schemas.microsoft.com/office/2006/keyEncryptor/certificate"},
|
{"encryption-certificate", "http://schemas.microsoft.com/office/2006/keyEncryptor/certificate"},
|
||||||
|
|
||||||
{"dc", "http://purl.org/dc/elements/1.1/"}, {"dcterms", "http://purl.org/dc/terms/"},
|
{"dc", "http://purl.org/dc/elements/1.1/"},
|
||||||
|
{"dcterms", "http://purl.org/dc/terms/"},
|
||||||
{"dcmitype", "http://purl.org/dc/dcmitype/"},
|
{"dcmitype", "http://purl.org/dc/dcmitype/"},
|
||||||
{"mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"},
|
{"mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"},
|
||||||
{"mx", "http://schemas.microsoft.com/office/mac/excel/2008/main"},
|
{"mx", "http://schemas.microsoft.com/office/mac/excel/2008/main"},
|
||||||
|
|
|
@ -1656,24 +1656,23 @@ void xlsx_consumer::read_stylesheet()
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
//std::size_t xf_id = 0;
|
std::size_t xf_id = 0;
|
||||||
|
|
||||||
for (const auto &record : style_records)
|
for (const auto &record : style_records)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
auto style_iter = std::find_if(styles.begin(), styles.end(),
|
auto style_iter = std::find_if(styles.begin(), styles.end(),
|
||||||
[&xf_id](const std::pair<style, std::size_t> &s) { return s.second == xf_id; });
|
[&xf_id](const std::pair<style_impl, std::size_t> &s) { return s.second == xf_id; });
|
||||||
++xf_id;
|
++xf_id;
|
||||||
|
|
||||||
if (style_iter == styles.end()) continue;
|
if (style_iter == styles.end()) continue;
|
||||||
|
|
||||||
auto new_style = stylesheet.create_style(style_iter->first.name);
|
auto new_style = stylesheet.create_style(style_iter->first.name);
|
||||||
*new_style.d_ = style_iter->first;
|
*new_style.d_ = style_iter->first;
|
||||||
*/
|
|
||||||
(void)record;
|
(void)record;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
std::size_t record_index = 0;
|
std::size_t record_index = 0;
|
||||||
|
|
||||||
for (const auto &record : format_records)
|
for (const auto &record : format_records)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -71,9 +71,7 @@ private:
|
||||||
// Package Parts
|
// Package Parts
|
||||||
|
|
||||||
void write_content_types();
|
void write_content_types();
|
||||||
void write_core_properties(const relationship &rel);
|
void write_properties(const relationship &rel);
|
||||||
void write_extended_properties(const relationship &rel);
|
|
||||||
void write_custom_properties(const relationship &rel);
|
|
||||||
void write_image(const path &image_path);
|
void write_image(const path &image_path);
|
||||||
|
|
||||||
// SpreadsheetML-Specific Package Parts
|
// SpreadsheetML-Specific Package Parts
|
||||||
|
@ -125,11 +123,41 @@ private:
|
||||||
void write_table_styles();
|
void write_table_styles();
|
||||||
void write_colors(const std::vector<xlnt::color> &colors);
|
void write_colors(const std::vector<xlnt::color> &colors);
|
||||||
|
|
||||||
/// <summary>
|
template<typename T>
|
||||||
/// Dereference serializer_ pointer and return a reference to the object.
|
void write_element(const std::string &ns, const std::string &name, T value)
|
||||||
/// This is called by internal methods so that we can use . instead of ->.
|
{
|
||||||
/// </summary>
|
write_start_element(ns, name);
|
||||||
xml::serializer &serializer();
|
write_characters(value);
|
||||||
|
write_end_element(ns, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_start_element(const std::string &name);
|
||||||
|
|
||||||
|
void write_start_element(const std::string &ns, const std::string &name);
|
||||||
|
|
||||||
|
void write_end_element(const std::string &name);
|
||||||
|
|
||||||
|
void write_end_element(const std::string &ns, const std::string &name);
|
||||||
|
|
||||||
|
void write_namespace(const std::string &ns, const std::string &prefix);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void write_attribute(const std::string &name, T value)
|
||||||
|
{
|
||||||
|
current_part_serializer_->attribute(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void write_attribute(const xml::qname &name, T value)
|
||||||
|
{
|
||||||
|
current_part_serializer_->attribute(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void write_characters(T characters)
|
||||||
|
{
|
||||||
|
current_part_serializer_->characters(characters);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A reference to the workbook which is the object of read/write operations.
|
/// A reference to the workbook which is the object of read/write operations.
|
||||||
|
|
|
@ -103,6 +103,20 @@ void open_stream(std::ofstream &stream, const std::string &path)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::vector<std::string> keys(const T &container)
|
||||||
|
{
|
||||||
|
auto result = std::vector<std::string>();
|
||||||
|
auto iter = container.begin();
|
||||||
|
|
||||||
|
while (iter != container.end())
|
||||||
|
{
|
||||||
|
result.push_back((iter++)->first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace xlnt {
|
namespace xlnt {
|
||||||
|
@ -112,6 +126,11 @@ bool workbook::has_core_property(const std::string &property_name) const
|
||||||
return d_->core_properties_.count(property_name) > 0;
|
return d_->core_properties_.count(property_name) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> workbook::core_properties() const
|
||||||
|
{
|
||||||
|
return keys(d_->core_properties_);
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
XLNT_API std::string workbook::core_property(const std::string &property_name) const
|
XLNT_API std::string workbook::core_property(const std::string &property_name) const
|
||||||
{
|
{
|
||||||
|
@ -141,6 +160,11 @@ bool workbook::has_extended_property(const std::string &property_name) const
|
||||||
return d_->extended_properties_.count(property_name) > 0;
|
return d_->extended_properties_.count(property_name) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> workbook::extended_properties() const
|
||||||
|
{
|
||||||
|
return keys(d_->extended_properties_);
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
XLNT_API void workbook::extended_property(const std::string &property_name, const std::string value)
|
XLNT_API void workbook::extended_property(const std::string &property_name, const std::string value)
|
||||||
{
|
{
|
||||||
|
@ -165,12 +189,16 @@ XLNT_API std::string workbook::extended_property(const std::string &property_nam
|
||||||
return d_->extended_properties_.at(property_name);
|
return d_->extended_properties_.at(property_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool workbook::has_custom_property(const std::string &property_name) const
|
bool workbook::has_custom_property(const std::string &property_name) const
|
||||||
{
|
{
|
||||||
return d_->custom_properties_.count(property_name) > 0;
|
return d_->custom_properties_.count(property_name) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> workbook::custom_properties() const
|
||||||
|
{
|
||||||
|
return keys(d_->custom_properties_);
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
XLNT_API void workbook::custom_property(const std::string &property_name, const std::string value)
|
XLNT_API void workbook::custom_property(const std::string &property_name, const std::string value)
|
||||||
{
|
{
|
||||||
|
@ -194,25 +222,27 @@ workbook workbook::empty()
|
||||||
auto impl = new detail::workbook_impl();
|
auto impl = new detail::workbook_impl();
|
||||||
workbook wb(impl);
|
workbook wb(impl);
|
||||||
|
|
||||||
wb.d_->manifest_.register_override_type(
|
wb.d_->manifest_.register_override_type(path("/xl/workbook.xml"),
|
||||||
path("/xl/workbook.xml"), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
|
||||||
wb.d_->manifest_.register_relationship(
|
wb.d_->manifest_.register_relationship(uri("/"), relationship_type::office_document,
|
||||||
uri("/"), relationship_type::office_document, uri("xl/workbook.xml"), target_mode::internal);
|
uri("xl/workbook.xml"), target_mode::internal);
|
||||||
|
|
||||||
wb.d_->manifest_.register_default_type("rels", "application/vnd.openxmlformats-package.relationships+xml");
|
wb.d_->manifest_.register_default_type("rels",
|
||||||
wb.d_->manifest_.register_default_type("xml", "application/xml");
|
"application/vnd.openxmlformats-package.relationships+xml");
|
||||||
|
wb.d_->manifest_.register_default_type("xml",
|
||||||
|
"application/xml");
|
||||||
|
|
||||||
wb.thumbnail(excel_thumbnail(), "jpeg", "image/jpeg");
|
wb.thumbnail(excel_thumbnail(), "jpeg", "image/jpeg");
|
||||||
|
|
||||||
wb.d_->manifest_.register_override_type(
|
wb.d_->manifest_.register_override_type(path("/docProps/core.xml"),
|
||||||
path("/docProps/core.xml"), "application/vnd.openxmlformats-package.core-properties+xml");
|
"application/vnd.openxmlformats-package.core-properties+xml");
|
||||||
wb.d_->manifest_.register_relationship(
|
wb.d_->manifest_.register_relationship(uri("/"), relationship_type::core_properties,
|
||||||
uri("/"), relationship_type::core_properties, uri("docProps/core.xml"), target_mode::internal);
|
uri("docProps/core.xml"), target_mode::internal);
|
||||||
|
|
||||||
wb.d_->manifest_.register_override_type(
|
wb.d_->manifest_.register_override_type(path("/docProps/app.xml"),
|
||||||
path("/docProps/app.xml"), "application/vnd.openxmlformats-officedocument.extended-properties+xml");
|
"application/vnd.openxmlformats-officedocument.extended-properties+xml");
|
||||||
wb.d_->manifest_.register_relationship(
|
wb.d_->manifest_.register_relationship(uri("/"), relationship_type::extended_properties,
|
||||||
uri("/"), relationship_type::extended_properties, uri("docProps/app.xml"), target_mode::internal);
|
uri("docProps/app.xml"), target_mode::internal);
|
||||||
|
|
||||||
wb.core_property("creator", "Microsoft Office User");
|
wb.core_property("creator", "Microsoft Office User");
|
||||||
wb.core_property("lastModifiedBy", "Microsoft Office User");
|
wb.core_property("lastModifiedBy", "Microsoft Office User");
|
||||||
|
@ -267,12 +297,19 @@ workbook workbook::empty()
|
||||||
.side(border_side::diagonal, border::border_property());
|
.side(border_side::diagonal, border::border_property());
|
||||||
wb.d_->stylesheet_.get().borders.push_back(default_border);
|
wb.d_->stylesheet_.get().borders.push_back(default_border);
|
||||||
|
|
||||||
auto default_fill = fill(pattern_fill().type(pattern_fill_type::none));
|
auto default_fill = fill(pattern_fill()
|
||||||
|
.type(pattern_fill_type::none));
|
||||||
stylesheet.fills.push_back(default_fill);
|
stylesheet.fills.push_back(default_fill);
|
||||||
auto gray125_fill = pattern_fill().type(pattern_fill_type::gray125);
|
auto gray125_fill = pattern_fill()
|
||||||
|
.type(pattern_fill_type::gray125);
|
||||||
stylesheet.fills.push_back(gray125_fill);
|
stylesheet.fills.push_back(gray125_fill);
|
||||||
|
|
||||||
auto default_font = font().name("Calibri").size(12).scheme("minor").family(2).color(theme_color(1));
|
auto default_font = font()
|
||||||
|
.name("Calibri")
|
||||||
|
.size(12)
|
||||||
|
.scheme("minor")
|
||||||
|
.family(2)
|
||||||
|
.color(theme_color(1));
|
||||||
stylesheet.fonts.push_back(default_font);
|
stylesheet.fonts.push_back(default_font);
|
||||||
|
|
||||||
wb.create_style("Normal")
|
wb.create_style("Normal")
|
||||||
|
@ -317,73 +354,85 @@ workbook::workbook(detail::workbook_impl *impl)
|
||||||
|
|
||||||
void workbook::register_app_properties_in_manifest()
|
void workbook::register_app_properties_in_manifest()
|
||||||
{
|
{
|
||||||
auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document);
|
auto wb_rel = manifest().relationship(path("/"),
|
||||||
|
relationship_type::office_document);
|
||||||
|
|
||||||
if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::extended_properties))
|
if (!manifest().has_relationship(wb_rel.target().path(),
|
||||||
|
relationship_type::extended_properties))
|
||||||
{
|
{
|
||||||
manifest().register_override_type(
|
manifest().register_override_type(path("/docProps/app.xml"),
|
||||||
path("/docProps/app.xml"), "application/vnd.openxmlformats-officedocument.extended-properties+xml");
|
"application/vnd.openxmlformats-officedocument.extended-properties+xml");
|
||||||
manifest().register_relationship(
|
manifest().register_relationship(uri("/"), relationship_type::extended_properties,
|
||||||
uri("/"), relationship_type::extended_properties, uri("docProps/app.xml"), target_mode::internal);
|
uri("docProps/app.xml"), target_mode::internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void workbook::register_core_properties_in_manifest()
|
void workbook::register_core_properties_in_manifest()
|
||||||
{
|
{
|
||||||
auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document);
|
auto wb_rel = manifest().relationship(path("/"),
|
||||||
|
relationship_type::office_document);
|
||||||
|
|
||||||
if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::core_properties))
|
if (!manifest().has_relationship(wb_rel.target().path(),
|
||||||
|
relationship_type::core_properties))
|
||||||
{
|
{
|
||||||
manifest().register_override_type(
|
manifest().register_override_type(path("/docProps/core.xml"),
|
||||||
path("/docProps/core.xml"), "application/vnd.openxmlformats-package.core-properties+xml");
|
"application/vnd.openxmlformats-package.core-properties+xml");
|
||||||
manifest().register_relationship(
|
manifest().register_relationship(uri("/"), relationship_type::core_properties,
|
||||||
uri("/"), relationship_type::core_properties, uri("docProps/core.xml"), target_mode::internal);
|
uri("docProps/core.xml"), target_mode::internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void workbook::register_shared_string_table_in_manifest()
|
void workbook::register_shared_string_table_in_manifest()
|
||||||
{
|
{
|
||||||
auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document);
|
auto wb_rel = manifest().relationship(path("/"),
|
||||||
|
relationship_type::office_document);
|
||||||
|
|
||||||
if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::shared_string_table))
|
if (!manifest().has_relationship(wb_rel.target().path(),
|
||||||
|
relationship_type::shared_string_table))
|
||||||
{
|
{
|
||||||
manifest().register_override_type(constants::part_shared_strings(),
|
manifest().register_override_type(constants::part_shared_strings(),
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml");
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml");
|
||||||
manifest().register_relationship(
|
manifest().register_relationship(wb_rel.target(), relationship_type::shared_string_table,
|
||||||
wb_rel.target(), relationship_type::shared_string_table, uri("sharedStrings.xml"), target_mode::internal);
|
uri("sharedStrings.xml"), target_mode::internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void workbook::register_stylesheet_in_manifest()
|
void workbook::register_stylesheet_in_manifest()
|
||||||
{
|
{
|
||||||
auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document);
|
auto wb_rel = manifest().relationship(path("/"),
|
||||||
|
relationship_type::office_document);
|
||||||
|
|
||||||
if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::stylesheet))
|
if (!manifest().has_relationship(wb_rel.target().path(),
|
||||||
|
relationship_type::stylesheet))
|
||||||
{
|
{
|
||||||
manifest().register_override_type(
|
manifest().register_override_type(constants::part_styles(),
|
||||||
constants::part_styles(), "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
|
||||||
manifest().register_relationship(
|
manifest().register_relationship(wb_rel.target(), relationship_type::stylesheet,
|
||||||
wb_rel.target(), relationship_type::stylesheet, uri("styles.xml"), target_mode::internal);
|
uri("styles.xml"), target_mode::internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void workbook::register_theme_in_manifest()
|
void workbook::register_theme_in_manifest()
|
||||||
{
|
{
|
||||||
auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document);
|
auto wb_rel = manifest().relationship(path("/"),
|
||||||
|
relationship_type::office_document);
|
||||||
|
|
||||||
if (!manifest().has_relationship(wb_rel.target().path(), relationship_type::theme))
|
if (!manifest().has_relationship(wb_rel.target().path(),
|
||||||
|
relationship_type::theme))
|
||||||
{
|
{
|
||||||
manifest().register_override_type(
|
manifest().register_override_type(constants::part_theme(),
|
||||||
constants::part_theme(), "application/vnd.openxmlformats-officedocument.theme+xml");
|
"application/vnd.openxmlformats-officedocument.theme+xml");
|
||||||
manifest().register_relationship(
|
manifest().register_relationship(wb_rel.target(), relationship_type::theme,
|
||||||
wb_rel.target(), relationship_type::theme, uri("theme/theme1.xml"), target_mode::internal);
|
uri("theme/theme1.xml"), target_mode::internal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void workbook::register_comments_in_manifest(worksheet ws)
|
void workbook::register_comments_in_manifest(worksheet ws)
|
||||||
{
|
{
|
||||||
auto wb_rel = manifest().relationship(path("/"), relationship_type::office_document);
|
auto wb_rel = manifest().relationship(path("/"),
|
||||||
auto ws_rel = manifest().relationship(wb_rel.target().path(), d_->sheet_title_rel_id_map_.at(ws.title()));
|
relationship_type::office_document);
|
||||||
|
auto ws_rel = manifest().relationship(wb_rel.target().path(),
|
||||||
|
d_->sheet_title_rel_id_map_.at(ws.title()));
|
||||||
path ws_path(ws_rel.source().path().parent().append(ws_rel.target().path()));
|
path ws_path(ws_rel.source().path().parent().append(ws_rel.target().path()));
|
||||||
|
|
||||||
if (!manifest().has_relationship(ws_path, relationship_type::vml_drawing))
|
if (!manifest().has_relationship(ws_path, relationship_type::vml_drawing))
|
||||||
|
@ -1113,8 +1162,8 @@ void workbook::thumbnail(
|
||||||
if (!d_->manifest_.has_relationship(path("/"), relationship_type::thumbnail))
|
if (!d_->manifest_.has_relationship(path("/"), relationship_type::thumbnail))
|
||||||
{
|
{
|
||||||
d_->manifest_.register_default_type(extension, content_type);
|
d_->manifest_.register_default_type(extension, content_type);
|
||||||
d_->manifest_.register_relationship(
|
d_->manifest_.register_relationship(uri("/"), relationship_type::thumbnail,
|
||||||
uri("/"), relationship_type::thumbnail, uri("docProps/thumbnail.jpeg"), target_mode::internal);
|
uri("docProps/thumbnail.jpeg"), target_mode::internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto thumbnail_rel = d_->manifest_.relationship(path("/"), relationship_type::thumbnail);
|
auto thumbnail_rel = d_->manifest_.relationship(path("/"), relationship_type::thumbnail);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user