fix dates and props

This commit is contained in:
Thomas Fussell 2014-07-16 19:53:45 -04:00
parent 45b03c03ef
commit a87c144340
9 changed files with 451 additions and 141 deletions

View File

@ -43,7 +43,7 @@ public:
static std::string determine_document_type(const std::unordered_map<std::string, std::pair<std::string, std::string>> &root_relationships,
const std::unordered_map<std::string, std::string> &override_types);
static worksheet read_worksheet(std::istream &handle, workbook &wb, const std::string &title, const std::vector<std::string> &string_table);
static void read_worksheet(worksheet ws, const std::string &xml_string, const std::vector<std::string> &string_table);
static void read_worksheet(worksheet ws, const std::string &xml_string, const std::vector<std::string> &string_table, const std::vector<int> &number_format_ids);
static std::vector<std::string> read_shared_string(const std::string &xml_string);
static std::string read_dimension(const std::string &xml_string);
static document_properties read_properties_core(const std::string &xml_string);

View File

@ -41,7 +41,7 @@ public:
std::string last_modified_by;
datetime created;
datetime modified;
std::string title;
std::string title = "Untitled";
std::string subject;
std::string description;
std::string keywords;

View File

@ -153,7 +153,7 @@ int date::to_number(int base_year) const
if(base_year == 1904)
{
return days_since_1900 - 1461;
return days_since_1900 - 1462;
}
return days_since_1900;

View File

@ -27,13 +27,51 @@ std::vector<std::pair<std::string, std::string>> reader::read_sheets(const zip_f
return sheets;
}
datetime w3cdtf_to_datetime(const std::string &string)
{
datetime result(1900, 1, 1);
auto separator_index = string.find('-');
result.year = std::stoi(string.substr(0, separator_index));
result.month = std::stoi(string.substr(separator_index + 1, string.find('-', separator_index + 1)));
separator_index = string.find('-', separator_index + 1);
result.day = std::stoi(string.substr(separator_index + 1, string.find('T', separator_index + 1)));
separator_index = string.find('T', separator_index + 1);
result.hour = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1)));
separator_index = string.find(':', separator_index + 1);
result.minute = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1)));
separator_index = string.find(':', separator_index + 1);
result.second = std::stoi(string.substr(separator_index + 1, string.find('Z', separator_index + 1)));
return result;
}
document_properties reader::read_properties_core(const std::string &xml_string)
{
document_properties props;
pugi::xml_document doc;
doc.load(xml_string.c_str());
auto root_node = doc.child("cp:coreProperties");
props.creator = root_node.child("dc:creator").text().as_string();
props.excel_base_date = calendar::windows_1900;
if(root_node.child("dc:creator") != nullptr)
{
props.creator = root_node.child("dc:creator").text().as_string();
}
if(root_node.child("cp:lastModifiedBy") != nullptr)
{
props.last_modified_by = root_node.child("cp:lastModifiedBy").text().as_string();
}
if(root_node.child("dcterms:created") != nullptr)
{
std::string created_string = root_node.child("dcterms:created").text().as_string();
props.created = w3cdtf_to_datetime(created_string);
}
if(root_node.child("dcterms:modified") != nullptr)
{
std::string modified_string = root_node.child("dcterms:modified").text().as_string();
props.modified = w3cdtf_to_datetime(modified_string);
}
return props;
}
@ -127,7 +165,7 @@ std::string reader::determine_document_type(const std::unordered_map<std::string
return "unsupported";
}
void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const std::vector<std::string> &string_table)
void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const std::vector<std::string> &string_table, const std::vector<int> &number_format_ids)
{
auto dimension_node = root_node.child("dimension");
std::string dimension = dimension_node.attribute("ref").as_string();
@ -173,58 +211,44 @@ void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const
{
ws.get_cell(address) = string_table.at(cell_node.child("v").text().as_int());
}
else if(cell_node.attribute("s") != nullptr && std::string(cell_node.attribute("s").as_string()) == "2") // date
else if(cell_node.attribute("s") != nullptr)
{
date date(1900, 1, 1);
int days = cell_node.child("v").text().as_int();
while(days > 365)
auto style_index = cell_node.attribute("s").as_int();
auto number_format_id = number_format_ids[style_index];
if(style_index < 0 || style_index >= number_format_ids.size())
{
date.year += 1;
days -= 365;
throw std::out_of_range(std::to_string(style_index));
}
while(days > 30)
if(number_format_id == 0) // integer
{
date.month += 1;
days -= 30;
ws.get_cell(address) = cell_node.child("v").text().as_int();
}
date.day = days;
ws.get_cell(address) = date;
}
else if(cell_node.attribute("s") != nullptr && std::string(cell_node.attribute("s").as_string()) == "3") // time
{
time time;
double remaining = cell_node.child("v").text().as_double() * 24;
time.hour = (int)(remaining);
remaining -= time.hour;
remaining *= 60;
time.minute = (int)(remaining);
remaining -= time.minute;
remaining *= 60;
time.second = (int)(remaining);
remaining -= time.second;
if(remaining > 0.5)
else if(number_format_id == 14) // date
{
time.second++;
if(time.second > 59)
{
time.second = 0;
time.minute++;
if(time.minute > 59)
{
time.minute = 0;
time.hour++;
}
}
ws.get_cell(address) = datetime::from_number(cell_node.child("v").text().as_double(), ws.get_parent().get_base_year());
}
else if(number_format_id == 18) // time
{
ws.get_cell(address) = time::from_number(cell_node.child("v").text().as_double());
}
else if(number_format_id == 22) // datetime
{
ws.get_cell(address) = datetime::from_number(cell_node.child("v").text().as_double(), 1900);
}
else if(number_format_id == 14) // decimal
{
ws.get_cell(address) = cell_node.child("v").text().as_double();
}
else if(number_format_id == 9) // percent
{
ws.get_cell(address) = cell_node.child("v").text().as_double();
}
else
{
throw number_format_id;
}
ws.get_cell(address) = time;
}
else if(cell_node.attribute("s") != nullptr && std::string(cell_node.attribute("s").as_string()) == "4") // decimal
{
ws.get_cell(address) = cell_node.child("v").text().as_double();
}
else if(cell_node.attribute("s") != nullptr && std::string(cell_node.attribute("s").as_string()) == "1") // percent
{
ws.get_cell(address) = cell_node.child("v").text().as_double();
}
else if(cell_node.child("v") != nullptr)
{
@ -235,11 +259,11 @@ void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const
}
}
void reader::read_worksheet(worksheet ws, const std::string &xml_string, const std::vector<std::string> &string_table)
void reader::read_worksheet(worksheet ws, const std::string &xml_string, const std::vector<std::string> &string_table, const std::vector<int> &number_format_ids)
{
pugi::xml_document doc;
doc.load(xml_string.c_str());
read_worksheet_common(ws, doc.child("worksheet"), string_table);
read_worksheet_common(ws, doc.child("worksheet"), string_table, number_format_ids);
}
worksheet xlnt::reader::read_worksheet(std::istream &handle, xlnt::workbook &wb, const std::string &title, const std::vector<std::string> &string_table)
@ -248,7 +272,7 @@ worksheet xlnt::reader::read_worksheet(std::istream &handle, xlnt::workbook &wb,
ws.set_title(title);
pugi::xml_document doc;
doc.load(handle);
read_worksheet_common(ws, doc.child("worksheet"), string_table);
read_worksheet_common(ws, doc.child("worksheet"), string_table, {});
return ws;
}

View File

@ -318,6 +318,18 @@ bool workbook::load(const std::string &filename)
{
shared_strings = xlnt::reader::read_shared_string(f.get_file_contents("xl/sharedStrings.xml"));
}
pugi::xml_document styles_doc;
styles_doc.load(f.get_file_contents("xl/styles.xml").c_str());
auto stylesheet_node = styles_doc.child("styleSheet");
auto cell_xfs_node = stylesheet_node.child("cellXfs");
std::vector<int> number_format_ids;
for(auto xf_node : cell_xfs_node.children("xf"))
{
number_format_ids.push_back(xf_node.attribute("numFmtId").as_int());
}
for(auto sheet_node : sheets_node.children("sheet"))
{
@ -325,7 +337,7 @@ bool workbook::load(const std::string &filename)
auto ws = create_sheet(sheet_node.attribute("name").as_string());
std::string sheet_filename("xl/");
sheet_filename += get_relationship(relation_id).get_target_uri();
xlnt::reader::read_worksheet(ws, f.get_file_contents(sheet_filename).c_str(), shared_strings);
xlnt::reader::read_worksheet(ws, f.get_file_contents(sheet_filename).c_str(), shared_strings, number_format_ids);
}
return true;

View File

@ -15,6 +15,7 @@
#include "worksheet/worksheet.hpp"
#include "workbook/workbook.hpp"
#include "common/relationship.hpp"
#include "workbook/document_properties.hpp"
namespace xlnt {
@ -36,14 +37,86 @@ std::string writer::write_shared_strings(const std::vector<std::string> &string_
return ss.str();
}
std::string writer::write_properties_core(const document_properties &/*prop*/)
std::string fill(const std::string &string, std::size_t length = 2)
{
return "";
if(string.size() >= length)
{
return string;
}
return std::string(length - string.size(), '0') + string;
}
std::string writer::write_properties_app(const workbook &/*wb*/)
std::string datetime_to_w3cdtf(const datetime &dt)
{
return "";
return std::to_string(dt.year) + "-" + fill(std::to_string(dt.month)) + "-" + fill(std::to_string(dt.day)) + "T" + fill(std::to_string(dt.hour)) + ":" + fill(std::to_string(dt.minute)) + ":" + fill(std::to_string(dt.second)) + "Z";
}
std::string writer::write_properties_core(const document_properties &prop)
{
pugi::xml_document doc;
auto root_node = doc.append_child("cp:coreProperties");
root_node.append_attribute("xmlns:cp").set_value("http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
root_node.append_attribute("xmlns:dc").set_value("http://purl.org/dc/elements/1.1/");
root_node.append_attribute("xmlns:dcmitype").set_value("http://purl.org/dc/dcmitype/");
root_node.append_attribute("xmlns:dcterms").set_value("http://purl.org/dc/terms/");
root_node.append_attribute("xmlns:xsi").set_value("http://www.w3.org/2001/XMLSchema-instance");
root_node.append_child("dc:creator").text().set(prop.creator.c_str());
root_node.append_child("cp:lastModifiedBy").text().set(prop.last_modified_by.c_str());
root_node.append_child("dcterms:created").text().set(datetime_to_w3cdtf(prop.created).c_str());
root_node.child("dcterms:created").append_attribute("xsi:type").set_value("dcterms:W3CDTF");
root_node.append_child("dcterms:modified").text().set(datetime_to_w3cdtf(prop.modified).c_str());
root_node.child("dcterms:modified").append_attribute("xsi:type").set_value("dcterms:W3CDTF");
root_node.append_child("dc:title").text().set(prop.title.c_str());
root_node.append_child("dc:description");
root_node.append_child("dc:subject");
root_node.append_child("cp:keywords");
root_node.append_child("cp:category");
std::stringstream ss;
doc.save(ss);
return ss.str();
}
std::string writer::write_properties_app(const workbook &wb)
{
pugi::xml_document doc;
auto root_node = doc.append_child("Properties");
root_node.append_attribute("xmlns").set_value("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties");
root_node.append_attribute("xmlns:vt").set_value("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
root_node.append_child("Application").text().set("Microsoft Excel");
root_node.append_child("DocSecurity").text().set("0");
root_node.append_child("ScaleCrop").text().set("false");
root_node.append_child("Company");
root_node.append_child("LinksUpToDate").text().set("false");
root_node.append_child("SharedDoc").text().set("false");
root_node.append_child("HyperlinksChanged").text().set("false");
root_node.append_child("AppVersion").text().set("12.0000");
auto heading_pairs_node = root_node.append_child("HeadingPairs");
auto heading_pairs_vector_node = heading_pairs_node.append_child("vt:vector");
heading_pairs_vector_node.append_attribute("baseType").set_value("variant");
heading_pairs_vector_node.append_attribute("size").set_value("2");
heading_pairs_vector_node.append_child("vt:variant").append_child("vt:lpstr").text().set("Worksheets");
heading_pairs_vector_node.append_child("vt:variant").append_child("vt:i4").text().set(std::to_string(wb.get_sheet_names().size()).c_str());
auto titles_of_parts_node = root_node.append_child("TitlesOfParts");
auto titles_of_parts_vector_node = titles_of_parts_node.append_child("vt:vector");
titles_of_parts_vector_node.append_attribute("baseType").set_value("lpstr");
titles_of_parts_vector_node.append_attribute("size").set_value(std::to_string(wb.get_sheet_names().size()).c_str());
for(auto ws : wb)
{
titles_of_parts_vector_node.append_child("vt:lpstr").text().set(ws.get_title().c_str());
}
std::stringstream ss;
doc.save(ss);
return ss.str();
}
std::string writer::write_workbook_rels(const workbook &wb)
@ -480,7 +553,7 @@ std::string writer::write_theme()
std::vector<scheme_element> scheme_elements =
{
{"a:dk1", "a:sysClr", "windowText"},
{"a:lt1", "a:sysClr", "windowText"},
{"a:lt1", "a:sysClr", "window"},
{"a:dk2", "a:srgbClr", "1F497D"},
{"a:lt2", "a:srgbClr", "EEECE1"},
{"a:accent1", "a:srgbClr", "4F81BD"},
@ -500,11 +573,11 @@ std::string writer::write_theme()
if(element.name == "a:dk1")
{
element_node.append_attribute("lastClr").set_value("000000");
element_node.child(element.sub_element_name.c_str()).append_attribute("lastClr").set_value("000000");
}
else if(element.name == "a:lt1")
{
element_node.append_attribute("lastClr").set_value("FFFFFF");
element_node.child(element.sub_element_name.c_str()).append_attribute("lastClr").set_value("FFFFFF");
}
}
@ -521,10 +594,10 @@ std::string writer::write_theme()
{true, "a:latin", "Cambria", "Calibri"},
{true, "a:ea", "", ""},
{true, "a:cs", "", ""},
{false, "Jpan", "&#xFF2D;&#xFF33; &#xFF30;&#x30B4;&#x30B7;&#x30C3;&#x30AF;", "&#xFF2D;&#xFF33; &#xFF30;&#x30B4;&#x30B7;&#x30C3;&#x30AF;"},
{false, "Hang", "&#xB9D1;&#xC740; &#xACE0;&#xB515;", "&#xB9D1;&#xC740; &#xACE0;&#xB515;"},
{false, "Hans", "&#x5B8B;&#x4F53", "&#x5B8B;&#x4F53"},
{false, "Hant", "&#x65B0;&#x7D30;&#x660E;&#x9AD4;", "&#x65B0;&#x7D30;&#x660E;&#x9AD4;"},
{false, "Jpan", "\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf", "\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf"},
{false, "Hang", "\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95", "\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95"},
{false, "Hans", "\xe5\xae\x8b\xe4\xbd\x93", "\xe5\xae\x8b\xe4\xbd\x93"},
{false, "Hant", "\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94", "\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94"},
{false, "Arab", "Times New Roman", "Arial"},
{false, "Hebr", "Times New Roman", "Arial"},
{false, "Thai", "Tahoma", "Tahoma"},
@ -540,7 +613,7 @@ std::string writer::write_theme()
{false, "Tibt", "Microsoft Himalaya", "Microsoft Himalaya"},
{false, "Thaa", "MV Boli", "MV Boli"},
{false, "Deva", "Mangal", "Mangal"},
{false, "Telu", "Guatami", "Guatami"},
{false, "Telu", "Gautami", "Gautami"},
{false, "Taml", "Latha", "Latha"},
{false, "Syrc", "Estrangelo Edessa", "Estrangelo Edessa"},
{false, "Orya", "Kalinga", "Kalinga"},
@ -572,7 +645,7 @@ std::string writer::write_theme()
major_font_node = major_fonts_node.append_child("a:font");
major_font_node.append_attribute("script").set_value(scheme.script.c_str());
minor_font_node = minor_fonts_node.append_child("a:font");
minor_font_node.append_attribute("typeface").set_value(scheme.script.c_str());
minor_font_node.append_attribute("script").set_value(scheme.script.c_str());
}
major_font_node.append_attribute("typeface").set_value(scheme.major.c_str());
@ -582,12 +655,219 @@ std::string writer::write_theme()
auto format_scheme_node = theme_elements_node.append_child("a:fmtScheme");
format_scheme_node.append_attribute("name").set_value("Office");
auto fill_style_list_node = format_scheme_node.append_child("a:fillStyleList");
auto fill_style_list_node = format_scheme_node.append_child("a:fillStyleLst");
fill_style_list_node.append_child("a:solidFill").append_child("a:schemeClr").append_attribute("val").set_value("phClr");
/*auto line_style_list_node = */format_scheme_node.append_child("a:lnStyleList");
/*auto effect_style_list_node = */format_scheme_node.append_child("a:effectStyleList");
/*auto bg_fill_style_list_node = */format_scheme_node.append_child("a:bgFillStyleList");
auto grad_fill_node = fill_style_list_node.append_child("a:gradFill");
grad_fill_node.append_attribute("rotWithShape").set_value(1);
auto grad_fill_list = grad_fill_node.append_child("a:gsLst");
auto gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(0);
auto scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:tint").append_attribute("val").set_value(50000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(300000);
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(35000);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:tint").append_attribute("val").set_value(37000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(300000);
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(100000);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:tint").append_attribute("val").set_value(15000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(350000);
auto lin_node = grad_fill_node.append_child("a:lin");
lin_node.append_attribute("ang").set_value(16200000);
lin_node.append_attribute("scaled").set_value(1);
grad_fill_node = fill_style_list_node.append_child("a:gradFill");
grad_fill_node.append_attribute("rotWithShape").set_value(1);
grad_fill_list = grad_fill_node.append_child("a:gsLst");
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(0);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:shade").append_attribute("val").set_value(51000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(130000);
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(80000);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:shade").append_attribute("val").set_value(93000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(130000);
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(100000);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:shade").append_attribute("val").set_value(94000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(135000);
lin_node = grad_fill_node.append_child("a:lin");
lin_node.append_attribute("ang").set_value(16200000);
lin_node.append_attribute("scaled").set_value(0);
auto line_style_list_node = format_scheme_node.append_child("a:lnStyleLst");
auto ln_node = line_style_list_node.append_child("a:ln");
ln_node.append_attribute("w").set_value(9525);
ln_node.append_attribute("cap").set_value("flat");
ln_node.append_attribute("cmpd").set_value("sng");
ln_node.append_attribute("algn").set_value("ctr");
auto solid_fill_node = ln_node.append_child("a:solidFill");
scheme_color_node = solid_fill_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:shade").append_attribute("val").set_value(95000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(105000);
ln_node.append_child("a:prstDash").append_attribute("val").set_value("solid");
ln_node = line_style_list_node.append_child("a:ln");
ln_node.append_attribute("w").set_value(25400);
ln_node.append_attribute("cap").set_value("flat");
ln_node.append_attribute("cmpd").set_value("sng");
ln_node.append_attribute("algn").set_value("ctr");
solid_fill_node = ln_node.append_child("a:solidFill");
scheme_color_node = solid_fill_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
ln_node.append_child("a:prstDash").append_attribute("val").set_value("solid");
ln_node = line_style_list_node.append_child("a:ln");
ln_node.append_attribute("w").set_value(38100);
ln_node.append_attribute("cap").set_value("flat");
ln_node.append_attribute("cmpd").set_value("sng");
ln_node.append_attribute("algn").set_value("ctr");
solid_fill_node = ln_node.append_child("a:solidFill");
scheme_color_node = solid_fill_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
ln_node.append_child("a:prstDash").append_attribute("val").set_value("solid");
auto effect_style_list_node = format_scheme_node.append_child("a:effectStyleLst");
auto effect_style_node = effect_style_list_node.append_child("a:effectStyle");
auto effect_list_node = effect_style_node.append_child("a:effectLst");
auto outer_shadow_node = effect_list_node.append_child("a:outerShdw");
outer_shadow_node.append_attribute("blurRad").set_value(40000);
outer_shadow_node.append_attribute("dist").set_value(20000);
outer_shadow_node.append_attribute("dir").set_value(5400000);
outer_shadow_node.append_attribute("rotWithShape").set_value(0);
auto srgb_clr_node = outer_shadow_node.append_child("a:srgbClr");
srgb_clr_node.append_attribute("val").set_value("000000");
srgb_clr_node.append_child("a:alpha").append_attribute("val").set_value(38000);
effect_style_node = effect_style_list_node.append_child("a:effectStyle");
effect_list_node = effect_style_node.append_child("a:effectLst");
outer_shadow_node = effect_list_node.append_child("a:outerShdw");
outer_shadow_node.append_attribute("blurRad").set_value(40000);
outer_shadow_node.append_attribute("dist").set_value(23000);
outer_shadow_node.append_attribute("dir").set_value(5400000);
outer_shadow_node.append_attribute("rotWithShape").set_value(0);
srgb_clr_node = outer_shadow_node.append_child("a:srgbClr");
srgb_clr_node.append_attribute("val").set_value("000000");
srgb_clr_node.append_child("a:alpha").append_attribute("val").set_value(35000);
effect_style_node = effect_style_list_node.append_child("a:effectStyle");
effect_list_node = effect_style_node.append_child("a:effectLst");
outer_shadow_node = effect_list_node.append_child("a:outerShdw");
outer_shadow_node.append_attribute("blurRad").set_value(40000);
outer_shadow_node.append_attribute("dist").set_value(23000);
outer_shadow_node.append_attribute("dir").set_value(5400000);
outer_shadow_node.append_attribute("rotWithShape").set_value(0);
srgb_clr_node = outer_shadow_node.append_child("a:srgbClr");
srgb_clr_node.append_attribute("val").set_value("000000");
srgb_clr_node.append_child("a:alpha").append_attribute("val").set_value(35000);
auto scene3d_node = effect_style_node.append_child("a:scene3d");
auto camera_node = scene3d_node.append_child("a:camera");
camera_node.append_attribute("prst").set_value("orthographicFront");
auto rot_node = camera_node.append_child("a:rot");
rot_node.append_attribute("lat").set_value(0);
rot_node.append_attribute("lon").set_value(0);
rot_node.append_attribute("rev").set_value(0);
auto light_rig_node = scene3d_node.append_child("a:lightRig");
light_rig_node.append_attribute("rig").set_value("threePt");
light_rig_node.append_attribute("dir").set_value("t");
rot_node = light_rig_node.append_child("a:rot");
rot_node.append_attribute("lat").set_value(0);
rot_node.append_attribute("lon").set_value(0);
rot_node.append_attribute("rev").set_value(1200000);
auto bevel_node = effect_style_node.append_child("a:sp3d").append_child("a:bevelT");
bevel_node.append_attribute("w").set_value(63500);
bevel_node.append_attribute("h").set_value(25400);
auto bg_fill_style_list_node = format_scheme_node.append_child("a:bgFillStyleLst");
bg_fill_style_list_node.append_child("a:solidFill").append_child("a:schemeClr").append_attribute("val").set_value("phClr");
grad_fill_node = bg_fill_style_list_node.append_child("a:gradFill");
grad_fill_node.append_attribute("rotWithShape").set_value(1);
grad_fill_list = grad_fill_node.append_child("a:gsLst");
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(0);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:tint").append_attribute("val").set_value(40000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(350000);
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(40000);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:tint").append_attribute("val").set_value(45000);
scheme_color_node.append_child("a:shade").append_attribute("val").set_value(99000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(350000);
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(100000);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:shade").append_attribute("val").set_value(20000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(255000);
auto path_node = grad_fill_node.append_child("a:path");
path_node.append_attribute("path").set_value("circle");
auto fill_to_rect_node = path_node.append_child("a:fillToRect");
fill_to_rect_node.append_attribute("l").set_value(50000);
fill_to_rect_node.append_attribute("t").set_value(-80000);
fill_to_rect_node.append_attribute("r").set_value(50000);
fill_to_rect_node.append_attribute("b").set_value(180000);
grad_fill_node = bg_fill_style_list_node.append_child("a:gradFill");
grad_fill_node.append_attribute("rotWithShape").set_value(1);
grad_fill_list = grad_fill_node.append_child("a:gsLst");
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(0);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:tint").append_attribute("val").set_value(80000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(300000);
gs_node = grad_fill_list.append_child("a:gs");
gs_node.append_attribute("pos").set_value(100000);
scheme_color_node = gs_node.append_child("a:schemeClr");
scheme_color_node.append_attribute("val").set_value("phClr");
scheme_color_node.append_child("a:shade").append_attribute("val").set_value(30000);
scheme_color_node.append_child("a:satMod").append_attribute("val").set_value(200000);
path_node = grad_fill_node.append_child("a:path");
path_node.append_attribute("path").set_value("circle");
fill_to_rect_node = path_node.append_child("a:fillToRect");
fill_to_rect_node.append_attribute("l").set_value(50000);
fill_to_rect_node.append_attribute("t").set_value(50000);
fill_to_rect_node.append_attribute("r").set_value(50000);
fill_to_rect_node.append_attribute("b").set_value(50000);
theme_node.append_child("a:objectDefaults");
theme_node.append_child("a:extraClrSchemeLst");

View File

@ -10,52 +10,52 @@ class Helper
public:
static bool EqualsFileContent(const std::string &reference_file, const std::string &fixture)
{
std::string fixture_content;
std::string fixture_content;
if(false)//PathHelper::FileExists(fixture))
{
std::fstream fixture_file;
fixture_file.open(fixture);
std::stringstream ss;
ss << fixture_file.rdbuf();
fixture_content = ss.str();
}
else
{
fixture_content = fixture;
}
if(false)//PathHelper::FileExists(fixture))
{
std::fstream fixture_file;
fixture_file.open(fixture);
std::stringstream ss;
ss << fixture_file.rdbuf();
fixture_content = ss.str();
}
else
{
fixture_content = fixture;
}
std::string expected_content;
std::string expected_content;
if(PathHelper::FileExists(reference_file))
{
std::fstream file;
file.open(reference_file);
std::stringstream ss;
ss << file.rdbuf();
expected_content = ss.str();
}
else
{
throw std::runtime_error("file not found");
}
if(PathHelper::FileExists(reference_file))
{
std::fstream file;
file.open(reference_file);
std::stringstream ss;
ss << file.rdbuf();
expected_content = ss.str();
}
else
{
throw std::runtime_error("file not found");
}
{
pugi::xml_document doc;
doc.load(fixture_content.c_str());
std::stringstream ss;
doc.save(ss);
fixture_content = ss.str();
pugi::xml_document doc;
doc.load(fixture_content.c_str());
std::stringstream ss;
doc.save(ss);
fixture_content = ss.str();
}
{
pugi::xml_document doc;
doc.load(expected_content.c_str());
std::stringstream ss;
doc.save(ss);
expected_content = ss.str();
pugi::xml_document doc;
doc.load(expected_content.c_str());
std::stringstream ss;
doc.save(ss);
expected_content = ss.str();
}
return expected_content == fixture_content;
return expected_content == fixture_content;
}
};

View File

@ -21,7 +21,7 @@ int main( int argc, char *argv[] ) {
return status;
}
bool suite_test_cell_init = false;
#include "/home/thomas/Development/xlnt/tests/test_cell.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_cell.hpp"
static test_cell suite_test_cell;
@ -238,7 +238,7 @@ public:
void runTest() { suite_test_cell.test_is_not_date_color_format(); }
} testDescription_suite_test_cell_test_is_not_date_color_format;
#include "/home/thomas/Development/xlnt/tests/test_chart.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_chart.hpp"
static test_chart suite_test_chart;
@ -329,7 +329,7 @@ public:
void runTest() { suite_test_chart.test_write_chart_scatter(); }
} testDescription_suite_test_chart_test_write_chart_scatter;
#include "/home/thomas/Development/xlnt/tests/test_named_range.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_named_range.hpp"
static test_named_range suite_test_named_range;
@ -420,7 +420,7 @@ public:
void runTest() { suite_test_named_range.test_can_be_saved(); }
} testDescription_suite_test_named_range_test_can_be_saved;
#include "/home/thomas/Development/xlnt/tests/test_number_format.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_number_format.hpp"
static test_number_format suite_test_number_format;
@ -523,7 +523,7 @@ public:
void runTest() { suite_test_number_format.test_mac_date(); }
} testDescription_suite_test_number_format_test_mac_date;
#include "/home/thomas/Development/xlnt/tests/test_props.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_props.hpp"
static test_props suite_test_props;
@ -538,35 +538,35 @@ public:
static class TestDescription_suite_test_props_test_read_sheets_titles : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_props_test_read_sheets_titles() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 30, "test_read_sheets_titles" ) {}
TestDescription_suite_test_props_test_read_sheets_titles() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 24, "test_read_sheets_titles" ) {}
void runTest() { suite_test_props.test_read_sheets_titles(); }
} testDescription_suite_test_props_test_read_sheets_titles;
static class TestDescription_suite_test_props_test_read_properties_core2 : public CxxTest::RealTestDescription {
static class TestDescription_suite_test_props_test_read_properties_core_libre : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_props_test_read_properties_core2() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 42, "test_read_properties_core2" ) {}
void runTest() { suite_test_props.test_read_properties_core2(); }
} testDescription_suite_test_props_test_read_properties_core2;
TestDescription_suite_test_props_test_read_properties_core_libre() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 36, "test_read_properties_core_libre" ) {}
void runTest() { suite_test_props.test_read_properties_core_libre(); }
} testDescription_suite_test_props_test_read_properties_core_libre;
static class TestDescription_suite_test_props_test_read_sheets_titles2 : public CxxTest::RealTestDescription {
static class TestDescription_suite_test_props_test_read_sheets_titles_libre : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_props_test_read_sheets_titles2() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 50, "test_read_sheets_titles2" ) {}
void runTest() { suite_test_props.test_read_sheets_titles2(); }
} testDescription_suite_test_props_test_read_sheets_titles2;
TestDescription_suite_test_props_test_read_sheets_titles_libre() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 44, "test_read_sheets_titles_libre" ) {}
void runTest() { suite_test_props.test_read_sheets_titles_libre(); }
} testDescription_suite_test_props_test_read_sheets_titles_libre;
static class TestDescription_suite_test_props_test_write_properties_core : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_props_test_write_properties_core() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 62, "test_write_properties_core" ) {}
TestDescription_suite_test_props_test_write_properties_core() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 56, "test_write_properties_core" ) {}
void runTest() { suite_test_props.test_write_properties_core(); }
} testDescription_suite_test_props_test_write_properties_core;
static class TestDescription_suite_test_props_test_write_properties_app : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_props_test_write_properties_app() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 73, "test_write_properties_app" ) {}
TestDescription_suite_test_props_test_write_properties_app() : CxxTest::RealTestDescription( Tests_test_props, suiteDescription_test_props, 67, "test_write_properties_app" ) {}
void runTest() { suite_test_props.test_write_properties_app(); }
} testDescription_suite_test_props_test_write_properties_app;
#include "/home/thomas/Development/xlnt/tests/test_read.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_read.hpp"
static test_read suite_test_read;
@ -699,7 +699,7 @@ public:
void runTest() { suite_test_read.test_read_date_value(); }
} testDescription_suite_test_read_test_read_date_value;
#include "/home/thomas/Development/xlnt/tests/test_strings.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_strings.hpp"
static test_strings suite_test_strings;
@ -730,7 +730,7 @@ public:
void runTest() { suite_test_strings.test_formatted_string_table(); }
} testDescription_suite_test_strings_test_formatted_string_table;
#include "/home/thomas/Development/xlnt/tests/test_style.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_style.hpp"
static test_style suite_test_style;
@ -827,7 +827,7 @@ public:
void runTest() { suite_test_style.test_read_cell_style(); }
} testDescription_suite_test_style_test_read_cell_style;
#include "/home/thomas/Development/xlnt/tests/test_theme.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_theme.hpp"
static test_theme suite_test_theme;
@ -840,7 +840,7 @@ public:
void runTest() { suite_test_theme.test_write_theme(); }
} testDescription_suite_test_theme_test_write_theme;
#include "/home/thomas/Development/xlnt/tests/test_workbook.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_workbook.hpp"
static test_workbook suite_test_workbook;
@ -961,7 +961,7 @@ public:
void runTest() { suite_test_workbook.test_write_regular_float(); }
} testDescription_suite_test_workbook_test_write_regular_float;
#include "/home/thomas/Development/xlnt/tests/test_worksheet.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_worksheet.hpp"
static test_worksheet suite_test_worksheet;
@ -1130,7 +1130,7 @@ public:
void runTest() { suite_test_worksheet.test_printer_settings(); }
} testDescription_suite_test_worksheet_test_printer_settings;
#include "/home/thomas/Development/xlnt/tests/test_write.hpp"
#include "c:\Users\taf656\Development\xlnt\tests\test_write.hpp"
static test_write suite_test_write;

View File

@ -16,15 +16,9 @@ public:
auto content = archive.get_file_contents("docProps/core.xml");
auto prop = xlnt::reader::read_properties_core(content);
TS_ASSERT_EQUALS(prop.creator, "*.*");
unsigned char eacute = 233;
std::string modified_by = "Aur";
modified_by.append(1, eacute);
modified_by += "lien Camp";
modified_by.append(1, eacute);
modified_by += "as";
TS_ASSERT_EQUALS(prop.last_modified_by, modified_by);
TS_ASSERT_EQUALS(prop.last_modified_by, "Charlie Clark");
TS_ASSERT_EQUALS(prop.created, xlnt::datetime(2010, 4, 9, 20, 43, 12));
TS_ASSERT_EQUALS(prop.modified, xlnt::datetime(2011, 2, 9, 13, 49, 32));
TS_ASSERT_EQUALS(prop.modified, xlnt::datetime(2014, 1, 2, 14, 53, 6));
}
void test_read_sheets_titles()
@ -39,7 +33,7 @@ public:
}
}
void test_read_properties_core2()
void test_read_properties_core_libre()
{
xlnt::zip_file archive(PathHelper::GetDataDirectory() + "/genuine/empty_libre.xlsx", xlnt::file_mode::open);
auto content = archive.get_file_contents("docProps/core.xml");
@ -47,7 +41,7 @@ public:
TS_ASSERT_EQUALS(prop.excel_base_date, xlnt::calendar::windows_1900);
}
void test_read_sheets_titles2()
void test_read_sheets_titles_libre()
{
xlnt::zip_file archive(PathHelper::GetDataDirectory() + "/genuine/empty_libre.xlsx", xlnt::file_mode::open);
auto content = archive.get_file_contents("docProps/core.xml");