fix worksheet reordering on save

This commit is contained in:
Thomas Fussell 2015-10-26 23:06:00 -04:00
parent ea46558d2c
commit 0efb3d2f97
8 changed files with 100 additions and 8 deletions

View File

@ -7,5 +7,5 @@ fi
mkdir build mkdir build
cd build cd build
cmake .. cmake -G "Unix Makefiles" ..
make make

View File

@ -5,7 +5,7 @@ include_directories(../../../source)
include_directories(../../../third-party/miniz) include_directories(../../../third-party/miniz)
include_directories(../../../third-party/pugixml/src) include_directories(../../../third-party/pugixml/src)
FILE(GLOB SOURCES ../../../source/*/*.cpp) FILE(GLOB SOURCES ../../../source/*/* ../../../include/xlnt/*/*.hpp ../../../include/xlnt/*.hpp)
FILE(GLOB DETAIL_SOURCES ../../../source/detail/*.cpp) FILE(GLOB DETAIL_SOURCES ../../../source/detail/*.cpp)
add_library(xlnt STATIC ${SOURCES} ${DETAIL_SOURCES} ../../../third-party/pugixml/src/pugixml.cpp ../../../third-party/miniz/miniz.c) add_library(xlnt STATIC ${SOURCES} ${DETAIL_SOURCES} ../../../third-party/pugixml/src/pugixml.cpp ../../../third-party/miniz/miniz.c)

View File

@ -201,6 +201,65 @@ public:
if(type_ == type::pattern) if(type_ == type::pattern)
{ {
hash_combine(seed, static_cast<std::size_t>(pattern_type_)); hash_combine(seed, static_cast<std::size_t>(pattern_type_));
hash_combine(seed, foreground_color_assigned_);
if(foreground_color_assigned_)
{
hash_combine(seed, static_cast<std::size_t>(foreground_color_.get_type()));
switch(foreground_color_.get_type())
{
case color::type::auto_:
hash_combine(seed, static_cast<std::size_t>(foreground_color_.get_auto()));
break;
case color::type::indexed:
hash_combine(seed, static_cast<std::size_t>(foreground_color_.get_index()));
break;
case color::type::theme:
hash_combine(seed, static_cast<std::size_t>(foreground_color_.get_theme()));
break;
}
}
hash_combine(seed, background_color_assigned_);
if(background_color_assigned_)
{
hash_combine(seed, static_cast<std::size_t>(background_color_.get_type()));
switch(foreground_color_.get_type())
{
case color::type::auto_:
hash_combine(seed, static_cast<std::size_t>(background_color_.get_auto()));
break;
case color::type::indexed:
hash_combine(seed, static_cast<std::size_t>(background_color_.get_index()));
break;
case color::type::theme:
hash_combine(seed, static_cast<std::size_t>(background_color_.get_theme()));
break;
}
}
}
else if(type_ == type::gradient)
{
hash_combine(seed, static_cast<std::size_t>(gradient_type_));
if(gradient_type_ == gradient_type::path)
{
hash_combine(seed, gradient_path_left_);
hash_combine(seed, gradient_path_right_);
hash_combine(seed, gradient_path_top_);
hash_combine(seed, gradient_path_bottom_);
}
else if(gradient_type_ == gradient_type::linear)
{
hash_combine(seed, rotation_);
}
}
else if(type_ == type::solid)
{
// hash_combine(seed, static_cast<std::size_t>());
} }
return seed; return seed;

Binary file not shown.

View File

@ -280,6 +280,14 @@ void style_reader::read_fills(pugi::xml_node fills_node)
{ {
new_fill.set_background_color(color(color::type::indexed, bg_color_node.attribute("indexed").as_ullong())); new_fill.set_background_color(color(color::type::indexed, bg_color_node.attribute("indexed").as_ullong()));
} }
else if(bg_color_node.attribute("auto") != nullptr)
{
new_fill.set_background_color(color(color::type::auto_, bg_color_node.attribute("auto").as_ullong()));
}
else if(bg_color_node.attribute("theme") != nullptr)
{
new_fill.set_background_color(color(color::type::theme, bg_color_node.attribute("theme").as_ullong()));
}
} }
auto fg_color_node = pattern_fill_node.child("fgColor"); auto fg_color_node = pattern_fill_node.child("fgColor");
@ -290,6 +298,14 @@ void style_reader::read_fills(pugi::xml_node fills_node)
{ {
new_fill.set_foreground_color(color(color::type::indexed, fg_color_node.attribute("indexed").as_ullong())); new_fill.set_foreground_color(color(color::type::indexed, fg_color_node.attribute("indexed").as_ullong()));
} }
else if(fg_color_node.attribute("auto") != nullptr)
{
new_fill.set_foreground_color(color(color::type::auto_, fg_color_node.attribute("auto").as_ullong()));
}
else if(fg_color_node.attribute("theme") != nullptr)
{
new_fill.set_foreground_color(color(color::type::theme, fg_color_node.attribute("theme").as_ullong()));
}
} }
} }

View File

@ -298,8 +298,16 @@ void workbook::remove_sheet(worksheet ws)
{ {
throw std::runtime_error("worksheet not owned by this workbook"); throw std::runtime_error("worksheet not owned by this workbook");
} }
auto sheet_filename = "xl/worksheets/sheet" + std::to_string(d_->worksheets_.size()) + ".xml";
auto rel_iter = std::find_if(d_->relationships_.begin(), d_->relationships_.end(), [=](relationship &r) { return r.get_target_uri() == sheet_filename; });
if(rel_iter == d_->relationships_.end())
{
throw std::runtime_error("no matching rel found");
}
d_->relationships_.erase(rel_iter);
d_->worksheets_.erase(match_iter); d_->worksheets_.erase(match_iter);
} }

View File

@ -108,14 +108,21 @@ void excel_writer::write_chartsheets(zip_file &/*archive*/)
void excel_writer::write_worksheets(zip_file &archive, const std::vector<std::string> &shared_strings) void excel_writer::write_worksheets(zip_file &archive, const std::vector<std::string> &shared_strings)
{ {
for(auto relationship : wb_.get_relationships()) std::size_t index = 0;
for(auto ws : wb_)
{ {
if(relationship.get_type() == relationship::type::worksheet) for(auto relationship : wb_.get_relationships())
{ {
auto sheet_index = workbook::index_from_ws_filename(relationship.get_target_uri()); if(relationship.get_type() == relationship::type::worksheet &&
auto ws = wb_.get_sheet_by_index(sheet_index); workbook::index_from_ws_filename(relationship.get_target_uri()) == index)
archive.writestr(relationship.get_target_uri(), write_worksheet(ws, shared_strings)); {
archive.writestr(relationship.get_target_uri(), write_worksheet(ws, shared_strings));
break;
}
} }
index++;
} }
} }

View File

@ -356,6 +356,8 @@ std::string style_writer::write_table() const
"ff000000", "ff000000",
"ffaaaaaa", "ffaaaaaa",
"ffbdc0bf", "ffbdc0bf",
"ffdbdbdb",
"ffbdc0bf",
"ffdbdbdb" "ffdbdbdb"
}; };