unskip a few more tests and fix xml helper node comparison

This commit is contained in:
Thomas Fussell 2016-08-13 19:44:45 -04:00
parent 6acba8ee9c
commit a7067db2ba
6 changed files with 129 additions and 14 deletions

View File

@ -56,6 +56,8 @@ struct date;
namespace detail { namespace detail {
struct worksheet_impl; struct worksheet_impl;
class xlsx_consumer;
class xlsx_producer;
} }
/// <summary> /// <summary>
@ -242,6 +244,8 @@ private:
friend class cell; friend class cell;
friend class range_iterator; friend class range_iterator;
friend class const_range_iterator; friend class const_range_iterator;
friend class detail::xlsx_consumer;
friend class detail::xlsx_producer;
std::size_t next_custom_number_format_id(); std::size_t next_custom_number_format_id();

View File

@ -758,7 +758,8 @@ void xlsx_consumer::populate_workbook()
for (const auto &rel : manifest.get_relationships(workbook_rel.get_target().get_path())) for (const auto &rel : manifest.get_relationships(workbook_rel.get_target().get_path()))
{ {
pugi::xml_document document; pugi::xml_document document;
document.load_string(source_.read(path(rel.get_target().get_path())).c_str()); path part_path(rel.get_source().get_path().parent().append(rel.get_target().get_path()));
document.load_string(source_.read(part_path).c_str());
switch (rel.get_type()) switch (rel.get_type())
{ {
@ -833,10 +834,13 @@ void xlsx_consumer::read_manifest()
part = part.append(relationship_source.filename.split_extension().first); part = part.append(relationship_source.filename.split_extension().first);
uri source(part.string()); uri source(part.string());
path source_directory = part.parent();
auto part_rels = read_relationships(relationship_source.filename, source_); auto part_rels = read_relationships(relationship_source.filename, source_);
for (const auto part_rel : part_rels) for (const auto part_rel : part_rels)
{ {
path target_path(source_directory.append(part_rel.get_target().get_path()));
manifest.register_relationship(source, part_rel.get_type(), manifest.register_relationship(source, part_rel.get_type(),
part_rel.get_target(), part_rel.get_target_mode(), part_rel.get_id()); part_rel.get_target(), part_rel.get_target_mode(), part_rel.get_id());
} }
@ -887,15 +891,60 @@ void xlsx_consumer::read_custom_file_properties(const pugi::xml_node root)
void xlsx_consumer::read_workbook(const pugi::xml_node root) void xlsx_consumer::read_workbook(const pugi::xml_node root)
{ {
auto workbook_node = root.child("workbook"); auto workbook_node = root.child("workbook");
auto workbook_pr_node = workbook_node.child("workbookPr");
if (workbook_pr_node.attribute("date1904")) if (workbook_node.attribute("xmlns:x15"))
{ {
std::string value = workbook_pr_node.attribute("date1904").value(); destination_.enable_x15();
}
if (value == "1" || value == "true") if (workbook_node.child("fileVersion"))
{
auto file_version_node = workbook_node.child("fileVersion");
destination_.d_->has_file_version_ = true;
destination_.d_->file_version_.app_name = file_version_node.attribute("appName").value();
destination_.d_->file_version_.last_edited = string_to_size_t(file_version_node.attribute("lastEdited").value());
destination_.d_->file_version_.lowest_edited = string_to_size_t(file_version_node.attribute("lowestEdited").value());
destination_.d_->file_version_.rup_build = string_to_size_t(file_version_node.attribute("rupBuild").value());
}
if (workbook_node.child("mc:AlternateContent"))
{
destination_.set_absolute_path(path(workbook_node.child("mc:AlternateContent")
.child("mc:Choice").child("x15ac:absPath").attribute("url").value()));
}
if (workbook_node.child("bookViews"))
{
auto book_views_node = workbook_node.child("bookViews");
if (book_views_node.child("workbookView"))
{ {
destination_.set_base_date(xlnt::calendar::mac_1904); auto book_view_node = book_views_node.child("workbookView");
workbook_view view;
view.x_window = string_to_size_t(book_view_node.attribute("xWindow").value());
view.y_window = string_to_size_t(book_view_node.attribute("yWindow").value());
view.window_width = string_to_size_t(book_view_node.attribute("windowWidth").value());
view.window_height = string_to_size_t(book_view_node.attribute("windowHeight").value());
view.tab_ratio = string_to_size_t(book_view_node.attribute("tabRatio").value());
destination_.set_view(view);
}
}
if (workbook_node.child("workbookPr"))
{
destination_.d_->has_properties_ = true;
auto workbook_pr_node = workbook_node.child("workbookPr");
if (workbook_pr_node.attribute("date1904"))
{
std::string value = workbook_pr_node.attribute("date1904").value();
if (value == "1" || value == "true")
{
destination_.set_base_date(xlnt::calendar::mac_1904);
}
} }
} }
@ -910,6 +959,16 @@ void xlsx_consumer::read_workbook(const pugi::xml_node root)
sheet_title_index_map_[rel_id] = index++; sheet_title_index_map_[rel_id] = index++;
destination_.d_->sheet_title_rel_id_map_[title] = rel_id; destination_.d_->sheet_title_rel_id_map_[title] = rel_id;
} }
if (workbook_node.child("calcPr"))
{
destination_.d_->has_calculation_properties_ = true;
}
if (workbook_node.child("extLst"))
{
destination_.d_->has_arch_id_ = true;
}
} }
// Write Workbook Relationship Target Parts // Write Workbook Relationship Target Parts
@ -1123,12 +1182,28 @@ void xlsx_consumer::read_worksheet(const pugi::xml_node root, const std::string
auto worksheet_node = root.child("worksheet"); auto worksheet_node = root.child("worksheet");
if (worksheet_node.attribute("xmlns:x14ac"))
{
ws.enable_x14ac();
}
xlnt::range_reference full_range; xlnt::range_reference full_range;
if (worksheet_node.child("dimension")) if (worksheet_node.child("dimension"))
{ {
std::string dimension(worksheet_node.child("dimension").attribute("ref").value()); std::string dimension(worksheet_node.child("dimension").attribute("ref").value());
full_range = xlnt::range_reference(dimension); full_range = xlnt::range_reference(dimension);
ws.d_->has_dimension_ = true;
}
if (worksheet_node.child("sheetViews"))
{
ws.d_->has_view_ = true;
}
if (worksheet_node.child("sheetFormatPr"))
{
ws.d_->has_format_properties_ = true;
} }
if (worksheet_node.child("mergeCells")) if (worksheet_node.child("mergeCells"))
@ -1285,6 +1360,21 @@ void xlsx_consumer::read_worksheet(const pugi::xml_node root, const std::string
xlnt::range_reference ref(auto_filter_node.attribute("ref").value()); xlnt::range_reference ref(auto_filter_node.attribute("ref").value());
ws.auto_filter(ref); ws.auto_filter(ref);
} }
if (worksheet_node.child("pageMargins"))
{
auto page_margins_node = worksheet_node.child("pageMargins");
page_margins margins;
margins.set_top(page_margins_node.attribute("top").as_double());
margins.set_bottom(page_margins_node.attribute("bottom").as_double());
margins.set_left(page_margins_node.attribute("left").as_double());
margins.set_right(page_margins_node.attribute("right").as_double());
margins.set_header(page_margins_node.attribute("header").as_double());
margins.set_footer(page_margins_node.attribute("footer").as_double());
ws.set_page_margins(margins);
}
} }
// Sheet Relationship Target Parts // Sheet Relationship Target Parts

View File

@ -665,10 +665,12 @@ void xlsx_producer::write_manifest()
pugi::xml_document part_rels_document; pugi::xml_document part_rels_document;
write_relationships(part_rels, part_rels_document.root()); write_relationships(part_rels, part_rels_document.root());
path parent = part.parent(); path parent = part.parent();
if (parent.is_absolute()) if (parent.is_absolute())
{ {
parent = path(parent.string().substr(1)); parent = path(parent.string().substr(1));
} }
path rels_path(parent.append("_rels").append(part.filename() + ".rels").string()); path rels_path(parent.append("_rels").append(part.filename() + ".rels").string());
write_document_to_archive(part_rels_document, rels_path, destination_); write_document_to_archive(part_rels_document, rels_path, destination_);
} }
@ -991,7 +993,8 @@ void xlsx_producer::write_workbook(const relationship &rel, pugi::xml_node root)
break; break;
} }
write_document_to_archive(document, child_rel.get_target().get_path(), destination_); path archive_path(child_rel.get_source().get_path().parent().append(child_rel.get_target().get_path()));
write_document_to_archive(document, archive_path, destination_);
} }
} }
@ -1535,6 +1538,7 @@ void xlsx_producer::write_worksheet(const relationship &rel, pugi::xml_node root
const auto view = ws.get_view(); const auto view = ws.get_view();
sheet_view_node.append_attribute("tabSelected").set_value("1");
sheet_view_node.append_attribute("workbookViewId").set_value("0"); sheet_view_node.append_attribute("workbookViewId").set_value("0");
if (!view.get_selections().empty()) if (!view.get_selections().empty())
@ -1606,6 +1610,7 @@ void xlsx_producer::write_worksheet(const relationship &rel, pugi::xml_node root
auto sheet_format_pr_node = worksheet_node.append_child("sheetFormatPr"); auto sheet_format_pr_node = worksheet_node.append_child("sheetFormatPr");
sheet_format_pr_node.append_attribute("baseColWidth").set_value("10"); sheet_format_pr_node.append_attribute("baseColWidth").set_value("10");
sheet_format_pr_node.append_attribute("defaultRowHeight").set_value("15"); sheet_format_pr_node.append_attribute("defaultRowHeight").set_value("15");
sheet_format_pr_node.append_attribute("x14ac:dyDescent").set_value("0.2");
} }
bool has_column_properties = false; bool has_column_properties = false;

View File

@ -46,7 +46,6 @@ public:
void test_round_trip_empty_excel_wr() void test_round_trip_empty_excel_wr()
{ {
TS_SKIP("");
xlnt::workbook wb = xlnt::workbook::empty_excel(); xlnt::workbook wb = xlnt::workbook::empty_excel();
TS_ASSERT(round_trip_matches_wr(wb)); TS_ASSERT(round_trip_matches_wr(wb));
} }
@ -67,7 +66,6 @@ public:
void test_round_trip_empty_excel_rw() void test_round_trip_empty_excel_rw()
{ {
TS_SKIP("");
auto path = path_helper::get_data_directory("8_default-excel.xlsx"); auto path = path_helper::get_data_directory("8_default-excel.xlsx");
TS_ASSERT(round_trip_matches_rw(path)); TS_ASSERT(round_trip_matches_rw(path));
} }

View File

@ -308,7 +308,7 @@ worksheet workbook::create_sheet()
d_->worksheets_.push_back(detail::worksheet_impl(this, sheet_id, title)); d_->worksheets_.push_back(detail::worksheet_impl(this, sheet_id, title));
auto workbook_rel = d_->manifest_.get_relationship(path("/"), relationship::type::office_document); auto workbook_rel = d_->manifest_.get_relationship(path("/"), relationship::type::office_document);
uri sheet_uri(constants::package_worksheets().append(sheet_filename).string()); uri sheet_uri(path("worksheets").append(sheet_filename).string());
d_->manifest_.register_override_type(sheet_uri.get_path(), d_->manifest_.register_override_type(sheet_uri.get_path(),
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"); "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
auto ws_rel = d_->manifest_.register_relationship(workbook_rel.get_target(), auto ws_rel = d_->manifest_.register_relationship(workbook_rel.get_target(),
@ -643,7 +643,7 @@ void workbook::set_theme(const theme &value)
d_->manifest_.register_override_type(constants::part_theme(), d_->manifest_.register_override_type(constants::part_theme(),
"application/vnd.openxmlformats-officedocument.theme+xml"); "application/vnd.openxmlformats-officedocument.theme+xml");
d_->manifest_.register_relationship(workbook_rel.get_target(), d_->manifest_.register_relationship(workbook_rel.get_target(),
relationship::type::theme, uri(constants::part_theme().string()), target_mode::internal); relationship::type::theme, uri("theme/theme1.xml"), target_mode::internal);
} }
d_->has_theme_ = true; d_->has_theme_ = true;
@ -674,7 +674,7 @@ std::size_t workbook::add_format(const format &to_add)
d_->manifest_.register_override_type(constants::part_styles(), d_->manifest_.register_override_type(constants::part_styles(),
"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"); "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
d_->manifest_.register_relationship(workbook_rel.get_target(), d_->manifest_.register_relationship(workbook_rel.get_target(),
relationship::type::styles, uri(constants::part_styles().string()), target_mode::internal); relationship::type::styles, uri("styles.xml"), target_mode::internal);
} }
return d_->stylesheet_.add_format(to_add); return d_->stylesheet_.add_format(to_add);
@ -689,7 +689,7 @@ std::size_t workbook::add_style(const style &to_add)
d_->manifest_.register_override_type(constants::part_styles(), d_->manifest_.register_override_type(constants::part_styles(),
"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"); "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
d_->manifest_.register_relationship(workbook_rel.get_target(), d_->manifest_.register_relationship(workbook_rel.get_target(),
relationship::type::styles, uri(constants::part_styles().string()), target_mode::internal); relationship::type::styles, uri("styles.xml"), target_mode::internal);
} }
return d_->stylesheet_.add_style(to_add); return d_->stylesheet_.add_style(to_add);
@ -773,7 +773,7 @@ void workbook::add_shared_string(const text &shared, bool allow_duplicates)
d_->manifest_.register_override_type(constants::part_shared_strings(), d_->manifest_.register_override_type(constants::part_shared_strings(),
"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"); "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml");
d_->manifest_.register_relationship(workbook_rel.get_target(), d_->manifest_.register_relationship(workbook_rel.get_target(),
relationship::type::shared_string_table, uri(constants::part_shared_strings().string()), target_mode::internal); relationship::type::shared_string_table, uri("styles.xml"), target_mode::internal);
} }
if (!allow_duplicates) if (!allow_duplicates)

View File

@ -220,6 +220,24 @@ public:
return {difference_type::attribute_values_differ, left_temp, right_temp}; return {difference_type::attribute_values_differ, left_temp, right_temp};
} }
} }
for (auto &right_attribute : right.attributes())
{
right_temp = right_attribute.name();
if (!left.attribute(right_attribute.name()))
{
return{ difference_type::missing_attribute, "((empty))", right_temp };
}
right_temp = right_attribute.name();
left_temp = left.attribute(right_attribute.name()).name();
if (left_temp != right_temp)
{
return{ difference_type::attribute_values_differ, left_temp, right_temp };
}
}
if(left.text()) if(left.text())
{ {