mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
don't use worksheet id as the sheet index since it is an arbitrary value
This commit is contained in:
parent
3a9fda8bfe
commit
6707736fa8
|
@ -321,28 +321,26 @@ void excel_serializer::write_data(bool /*as_template*/)
|
||||||
|
|
||||||
void excel_serializer::write_worksheets()
|
void excel_serializer::write_worksheets()
|
||||||
{
|
{
|
||||||
std::size_t index = 0;
|
std::size_t index = 1;
|
||||||
|
|
||||||
for (auto ws : workbook_)
|
for (const auto ws : workbook_)
|
||||||
{
|
{
|
||||||
for (auto relationship : workbook_.get_relationships())
|
auto target = "worksheets/sheet" + std::to_string(index++) + ".xml";
|
||||||
|
|
||||||
|
for (const auto &rel : workbook_.get_relationships())
|
||||||
{
|
{
|
||||||
if (relationship.get_type() == relationship::type::worksheet &&
|
if (rel.get_target_uri() != target) continue;
|
||||||
workbook::index_from_ws_filename(relationship.get_target_uri()) == index)
|
|
||||||
{
|
|
||||||
worksheet_serializer serializer_(ws);
|
|
||||||
std::string ws_filename = (relationship.get_target_uri().substr(0, 3) != "xl/" ? "xl/" : "") + relationship.get_target_uri();
|
|
||||||
std::ostringstream ss;
|
|
||||||
pugi::xml_document worksheet_xml;
|
|
||||||
serializer_.write_worksheet(worksheet_xml);
|
|
||||||
worksheet_xml.save(ss);
|
|
||||||
archive_.writestr(ws_filename, ss.str());
|
|
||||||
|
|
||||||
break;
|
worksheet_serializer serializer_(ws);
|
||||||
}
|
std::string ws_filename = (rel.get_target_uri().substr(0, 3) != "xl/" ? "xl/" : "") + rel.get_target_uri();
|
||||||
|
std::ostringstream ss;
|
||||||
|
pugi::xml_document worksheet_xml;
|
||||||
|
serializer_.write_worksheet(worksheet_xml);
|
||||||
|
worksheet_xml.save(ss);
|
||||||
|
archive_.writestr(ws_filename, ss.str());
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -277,10 +277,11 @@ void workbook_serializer::write_workbook(pugi::xml_document &xml) const
|
||||||
|
|
||||||
auto sheets_node = root_node.append_child("sheets");
|
auto sheets_node = root_node.append_child("sheets");
|
||||||
auto defined_names_node = root_node.append_child("definedNames");
|
auto defined_names_node = root_node.append_child("definedNames");
|
||||||
|
std::size_t index = 1;
|
||||||
|
|
||||||
for (const auto ws : workbook_)
|
for (const auto ws : workbook_)
|
||||||
{
|
{
|
||||||
auto target = "worksheets/sheet" + std::to_string(ws.get_id()) + ".xml";
|
auto target = "worksheets/sheet" + std::to_string(index++) + ".xml";
|
||||||
|
|
||||||
for (const auto &rel : workbook_.get_relationships())
|
for (const auto &rel : workbook_.get_relationships())
|
||||||
{
|
{
|
||||||
|
@ -301,6 +302,8 @@ void workbook_serializer::write_workbook(pugi::xml_document &xml) const
|
||||||
"'" + ws.get_title() + "'!" + range_reference::make_absolute(ws.get_auto_filter()).to_string();
|
"'" + ws.get_title() + "'!" + range_reference::make_absolute(ws.get_auto_filter()).to_string();
|
||||||
defined_name_node.text().set(name.c_str());
|
defined_name_node.text().set(name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user