mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
write missing property attribute for dcterms:created and dcterms:modified, update headingpairs and titlesofparts when sheet titles change
This commit is contained in:
parent
0db50a7b15
commit
d7b0e252fd
|
@ -827,6 +827,11 @@ private:
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void garbage_collect_formulae();
|
void garbage_collect_formulae();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update extended workbook properties titlesOfParts and headingPairs when sheets change.
|
||||||
|
/// </summary>
|
||||||
|
void update_sheet_properties();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An opaque pointer to a structure that holds all of the data relating to this workbook.
|
/// An opaque pointer to a structure that holds all of the data relating to this workbook.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -252,6 +252,11 @@ void xlsx_producer::write_property(const std::string &name, const variant &value
|
||||||
write_start_element(constants::ns("vt"), "lpwstr");
|
write_start_element(constants::ns("vt"), "lpwstr");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!custom && ns == constants::ns("dcterms") && (name == "created" || name == "modified"))
|
||||||
|
{
|
||||||
|
write_attribute(xml::qname(constants::ns("xsi"), "type"), "dcterms:W3CDTF");
|
||||||
|
}
|
||||||
|
|
||||||
write_characters(value.get<std::string>());
|
write_characters(value.get<std::string>());
|
||||||
|
|
||||||
if (custom)
|
if (custom)
|
||||||
|
|
|
@ -24,6 +24,7 @@ public:
|
||||||
|
|
||||||
std::vector<std::uint8_t> destination;
|
std::vector<std::uint8_t> destination;
|
||||||
source_workbook.save(destination);
|
source_workbook.save(destination);
|
||||||
|
source_workbook.save("temp.xlsx");
|
||||||
|
|
||||||
std::ifstream source_stream(source.string(), std::ios::binary);
|
std::ifstream source_stream(source.string(), std::ios::binary);
|
||||||
|
|
||||||
|
|
|
@ -759,6 +759,8 @@ worksheet workbook::create_sheet()
|
||||||
workbook_rel.target(), relationship_type::worksheet, relative_sheet_uri, target_mode::internal);
|
workbook_rel.target(), relationship_type::worksheet, relative_sheet_uri, target_mode::internal);
|
||||||
d_->sheet_title_rel_id_map_[title] = ws_rel;
|
d_->sheet_title_rel_id_map_[title] = ws_rel;
|
||||||
|
|
||||||
|
update_sheet_properties();
|
||||||
|
|
||||||
return worksheet(&d_->worksheets_.back());
|
return worksheet(&d_->worksheets_.back());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1007,9 +1009,10 @@ void workbook::remove_sheet(worksheet ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ws_rel_id = d_->sheet_title_rel_id_map_.at(ws.title());
|
auto ws_rel_id = d_->sheet_title_rel_id_map_.at(ws.title());
|
||||||
auto wb_rel = d_->manifest_.relationship(xlnt::path("/"), xlnt::relationship_type::office_document);
|
auto wb_rel = d_->manifest_.relationship(path("/"), xlnt::relationship_type::office_document);
|
||||||
auto ws_rel = d_->manifest_.relationship(wb_rel.target().path(), ws_rel_id);
|
auto ws_rel = d_->manifest_.relationship(wb_rel.target().path(), ws_rel_id);
|
||||||
d_->manifest_.unregister_override_type(ws_rel.target().path());
|
auto ws_part = d_->manifest_.canonicalize({wb_rel, ws_rel}).resolve(path("/"));
|
||||||
|
d_->manifest_.unregister_override_type(ws_part);
|
||||||
auto rel_id_map = d_->manifest_.unregister_relationship(wb_rel.target(), ws_rel_id);
|
auto rel_id_map = d_->manifest_.unregister_relationship(wb_rel.target(), ws_rel_id);
|
||||||
d_->sheet_title_rel_id_map_.erase(ws.title());
|
d_->sheet_title_rel_id_map_.erase(ws.title());
|
||||||
d_->worksheets_.erase(match_iter);
|
d_->worksheets_.erase(match_iter);
|
||||||
|
@ -1020,6 +1023,8 @@ void workbook::remove_sheet(worksheet ws)
|
||||||
title_rel_id_pair.second = rel_id_map.count(title_rel_id_pair.second) > 0
|
title_rel_id_pair.second = rel_id_map.count(title_rel_id_pair.second) > 0
|
||||||
? rel_id_map[title_rel_id_pair.second] : title_rel_id_pair.second;
|
? rel_id_map[title_rel_id_pair.second] : title_rel_id_pair.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_sheet_properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
worksheet workbook::create_sheet(std::size_t index)
|
worksheet workbook::create_sheet(std::size_t index)
|
||||||
|
@ -1054,6 +1059,8 @@ worksheet workbook::create_sheet_with_rel(const std::string &title, const relati
|
||||||
workbook_rel.target(), relationship_type::worksheet, rel.target(), target_mode::internal);
|
workbook_rel.target(), relationship_type::worksheet, rel.target(), target_mode::internal);
|
||||||
d_->sheet_title_rel_id_map_[title] = ws_rel;
|
d_->sheet_title_rel_id_map_[title] = ws_rel;
|
||||||
|
|
||||||
|
update_sheet_properties();
|
||||||
|
|
||||||
return worksheet(&d_->worksheets_.back());
|
return worksheet(&d_->worksheets_.back());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1499,4 +1506,18 @@ void workbook::garbage_collect_formulae()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void workbook::update_sheet_properties()
|
||||||
|
{
|
||||||
|
if (has_extended_property(extended_property::titles_of_parts))
|
||||||
|
{
|
||||||
|
extended_property(extended_property::titles_of_parts, sheet_titles());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_extended_property(extended_property::heading_pairs))
|
||||||
|
{
|
||||||
|
extended_property(extended_property::heading_pairs,
|
||||||
|
std::vector<variant>{variant("Worksheets"), variant(static_cast<int>(sheet_count()))});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
|
|
@ -275,8 +275,8 @@ void worksheet::title(const std::string &title)
|
||||||
throw invalid_sheet_title(title);
|
throw invalid_sheet_title(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto same_title =
|
auto same_title = std::find_if(workbook().begin(), workbook().end(),
|
||||||
std::find_if(workbook().begin(), workbook().end(), [&](worksheet ws) { return ws.title() == title; });
|
[&](worksheet ws) { return ws.title() == title; });
|
||||||
|
|
||||||
if (same_title != workbook().end() && *same_title != *this)
|
if (same_title != workbook().end() && *same_title != *this)
|
||||||
{
|
{
|
||||||
|
@ -286,6 +286,8 @@ void worksheet::title(const std::string &title)
|
||||||
workbook().d_->sheet_title_rel_id_map_[title] = workbook().d_->sheet_title_rel_id_map_[d_->title_];
|
workbook().d_->sheet_title_rel_id_map_[title] = workbook().d_->sheet_title_rel_id_map_[d_->title_];
|
||||||
workbook().d_->sheet_title_rel_id_map_.erase(d_->title_);
|
workbook().d_->sheet_title_rel_id_map_.erase(d_->title_);
|
||||||
d_->title_ = title;
|
d_->title_ = title;
|
||||||
|
|
||||||
|
workbook().update_sheet_properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_reference worksheet::frozen_panes() const
|
cell_reference worksheet::frozen_panes() const
|
||||||
|
|
Loading…
Reference in New Issue
Block a user