2015-10-24 02:42:36 +08:00
|
|
|
#include <xlnt/common/zip_file.hpp>
|
2015-10-21 11:30:10 +08:00
|
|
|
#include <xlnt/reader/shared_strings_reader.hpp>
|
|
|
|
|
|
|
|
#include "detail/include_pugixml.hpp"
|
|
|
|
|
|
|
|
namespace xlnt {
|
|
|
|
|
2015-10-24 02:42:36 +08:00
|
|
|
std::vector<std::string> shared_strings_reader::read_strings(zip_file &archive)
|
2015-10-21 11:30:10 +08:00
|
|
|
{
|
2015-10-24 02:42:36 +08:00
|
|
|
static const std::string shared_strings_filename = "xl/sharedStrings.xml";
|
|
|
|
|
|
|
|
if(!archive.has_file(shared_strings_filename))
|
|
|
|
{
|
|
|
|
return { };
|
|
|
|
}
|
|
|
|
|
2015-10-21 11:30:10 +08:00
|
|
|
pugi::xml_document doc;
|
2015-10-24 02:42:36 +08:00
|
|
|
doc.load(archive.read(shared_strings_filename).c_str());
|
|
|
|
|
2015-10-21 11:30:10 +08:00
|
|
|
auto root_node = doc.child("sst");
|
|
|
|
int unique_count = root_node.attribute("uniqueCount").as_int();
|
2015-10-24 02:42:36 +08:00
|
|
|
|
|
|
|
std::vector<std::string> shared_strings;
|
2015-10-21 11:30:10 +08:00
|
|
|
|
|
|
|
for(auto si_node : root_node)
|
|
|
|
{
|
|
|
|
shared_strings.push_back(si_node.child("t").text().as_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(unique_count != (int)shared_strings.size())
|
|
|
|
{
|
|
|
|
throw std::runtime_error("counts don't match");
|
|
|
|
}
|
|
|
|
|
|
|
|
return shared_strings;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace xlnt
|