almost finished

This commit is contained in:
Thomas Fussell 2014-05-14 18:31:48 -04:00
parent 411a735098
commit 6465bac5e4
12 changed files with 970 additions and 1274 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "third-party/pugixml"] [submodule "third-party/pugixml"]
path = third-party/pugixml path = third-party/pugixml
url = https://github.com/zeux/pugixml.git url = https://github.com/zeux/pugixml.git
[submodule "third-party/zlib"]
path = third-party/zlib
url = https://github.com/madler/zlib.git

View File

@ -70,17 +70,23 @@ project "xlnt"
"$(opc_prefix)/third_party/libxml2-2.7.7/include", "$(opc_prefix)/third_party/libxml2-2.7.7/include",
"../include/xlnt", "../include/xlnt",
"../third-party/pugixml/src", "../third-party/pugixml/src",
"../source/" "../source/",
"../third-party/zlib/",
"../third-party/zlib/contrib/minizip"
} }
files { files {
"../source/**.cpp", "../source/**.cpp",
"../source/**.h", "../source/**.h",
"../include/**.h", "../include/**.h",
"../third-party/pugixml/src/pugixml.cpp" "../third-party/pugixml/src/pugixml.cpp",
"../third-party/zlib/*.c",
"../third-party/zlib/contrib/minizip/*.c"
} }
excludes { excludes {
"../source/tests/**.cpp", "../source/tests/**.cpp",
"../source/tests/**.h" "../source/tests/**.h",
"../third-party/zlib/contrib/minizip/miniunz.c",
"../third-party/zlib/contrib/minizip/minizip.c"
} }
flags { flags {
"Unicode", "Unicode",
@ -95,3 +101,5 @@ project "xlnt"
defines { "WIN32" } defines { "WIN32" }
configuration "not windows" configuration "not windows"
includedirs { "$(opc_prefix)/build/plib/config/darwin-debug-gcc-i386/plib/include" } includedirs { "$(opc_prefix)/build/plib/config/darwin-debug-gcc-i386/plib/include" }
configuration "**.c"
flags { "NoWarnings" }

View File

@ -90,7 +90,7 @@ public:
void test_initial_value() void test_initial_value()
{ {
xlnt::workbook wb; xlnt::workbook wb;
xlnt::worksheet ws = wb.get_active_sheet(); xlnt::worksheet ws = wb.get_active_sheet();
xlnt::cell cell(ws, "A", 1, "17.5"); xlnt::cell cell(ws, "A", 1, "17.5");
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type()); TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
@ -234,7 +234,7 @@ public:
xlnt::cell cell(ws, "A", 1); xlnt::cell cell(ws, "A", 1);
cell = "03:40:16"; cell = "03:40:16";
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type()); TS_ASSERT_EQUALS(xlnt::cell::type::date, cell.get_data_type());
tm expected1; tm expected1;
expected1.tm_hour = 3; expected1.tm_hour = 3;
expected1.tm_min = 40; expected1.tm_min = 40;
@ -242,7 +242,7 @@ public:
TS_ASSERT(cell == expected1); TS_ASSERT(cell == expected1);
cell = "03:40"; cell = "03:40";
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type()); TS_ASSERT_EQUALS(xlnt::cell::type::date, cell.get_data_type());
tm expected2; tm expected2;
expected2.tm_hour = 3; expected2.tm_hour = 3;
expected2.tm_min = 40; expected2.tm_min = 40;

View File

@ -18,13 +18,16 @@ public:
void test_dump_sheet_title() void test_dump_sheet_title()
{ {
xlnt::workbook wb; xlnt::workbook wb3;
wb.optimized_write(true); wb3.load("C:/Users/taf656/Desktop/a.xlsx");
xlnt::workbook wb(xlnt::optimized::write);
auto ws = wb.create_sheet("Test1"); auto ws = wb.create_sheet("Test1");
wb.save(temp_file.GetFilename()); wb.save(temp_file.GetFilename());
xlnt::workbook wb2; xlnt::workbook wb2;
wb2.load(temp_file.GetFilename()); wb2.load(temp_file.GetFilename());
ws = wb2.get_sheet_by_name("Test1"); ws = wb2.get_sheet_by_name("Test1");
TS_ASSERT_DIFFERS(ws, nullptr);
TS_ASSERT_EQUALS("Test1", ws.get_title()); TS_ASSERT_EQUALS("Test1", ws.get_title());
} }
@ -125,7 +128,7 @@ public:
xlnt::workbook wb; xlnt::workbook wb;
wb.optimized_write(true); wb.optimized_write(true);
for(int i = 0; i < 200; i++) // over 200 worksheets should raise an OSError("too many open files") for(int i = 0; i < 2; i++) // over 200 worksheets should raise an OSError("too many open files")
{ {
wb.create_sheet(); wb.create_sheet();
wb.save(test_filename); wb.save(test_filename);

View File

@ -1,108 +0,0 @@
#pragma once
#include <cxxtest/TestSuite.h>
#include "../xlnt.h"
#include "pugixml.hpp"
class PackageTestSuite : public CxxTest::TestSuite
{
public:
PackageTestSuite()
{
template_zip = "../../source/tests/test_data/packaging/test.zip";
test_zip = "../../source/tests/test_data/packaging/a.zip";
existing_xlsx = "../../source/tests/test_data/packaging/existing.xlsx";
new_xlsx = "../../source/tests/test_data/packaging/new.xlsx";
xlnt::file::copy(template_zip, test_zip, true);
}
void test_existing_package()
{
//xlnt::package package;
//package.open(existing_xlsx, xlnt::file_mode::Open, xlnt::file_access::Read);
}
void test_new_package()
{
xlnt::package package;
package.open(new_xlsx, xlnt::file_mode::Create, xlnt::file_access::ReadWrite);
//auto part_1 = package.create_part("workbook.xml", "type");
//TS_ASSERT_DIFFERS(part_1, nullptr);
//part_1.write("test");
}
void test_read_text()
{
xlnt::package package;
package.open(test_zip, xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
auto part_1 = package.get_part("a.txt");
TS_ASSERT_DIFFERS(part_1, nullptr);
auto part_1_data = part_1.read();
TS_ASSERT_EQUALS(part_1_data, "a.txt");
}
void test_write_text()
{
{
xlnt::package package;
package.open(test_zip, xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
auto part_1 = package.get_part("a.txt");
TS_ASSERT_DIFFERS(part_1, nullptr);
part_1.write("something else");
}
{
xlnt::package package;
package.open(test_zip, xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
auto part_1 = package.get_part("a.txt");
TS_ASSERT_DIFFERS(part_1, nullptr);
auto part_1_data = part_1.read();
TS_ASSERT_EQUALS(part_1_data, "something else");
}
}
void test_read_xml()
{
xlnt::package package;
package.open(test_zip, xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
auto part_2 = package.get_part("a.xml");
TS_ASSERT_DIFFERS(part_2, nullptr);
auto part_2_data = part_2.read();
TS_ASSERT_DIFFERS(part_2_data, "");
pugi::xml_document part_2_doc;
part_2_doc.load(part_2_data.c_str());
auto root_element = part_2_doc.child("root");
TS_ASSERT_DIFFERS(root_element, nullptr)
auto child_element = root_element.child("child");
TS_ASSERT_DIFFERS(child_element, nullptr)
TS_ASSERT_EQUALS(std::string(child_element.attribute("attribute").as_string()), "attribute")
auto element_element = root_element.child("element");
TS_ASSERT_DIFFERS(element_element, nullptr)
TS_ASSERT_EQUALS(std::string(element_element.text().as_string()), "Text")
}
private:
std::string template_zip;
std::string test_zip;
std::string existing_xlsx;
std::string new_xlsx;
};

View File

@ -9,9 +9,7 @@ class TemporaryFile
public: public:
static std::string CreateTemporaryFilename() static std::string CreateTemporaryFilename()
{ {
std::array<char, L_tmpnam> buffer; return "C:/Users/taf656/Desktop/xlnt.xlsx";
tmpnam(buffer.data());
return std::string(buffer.begin(), buffer.end());
} }
TemporaryFile() : filename_(CreateTemporaryFilename()) TemporaryFile() : filename_(CreateTemporaryFilename())

View File

@ -37,7 +37,7 @@ public:
void test_set_bad_title() void test_set_bad_title()
{ {
std::string title(50, 'X'); std::string title(50, 'X');
wb.create_sheet(title); TS_ASSERT_THROWS(wb.create_sheet(title), xlnt::bad_sheet_title);
} }
void test_set_bad_title_character() void test_set_bad_title_character()
@ -143,6 +143,8 @@ public:
TS_ASSERT_DIFFERS(match, comparison_cells.end()); TS_ASSERT_DIFFERS(match, comparison_cells.end());
comparison_cells.erase(match); comparison_cells.erase(match);
} }
TS_ASSERT(comparison_cells.empty());
} }
void test_hyperlink_relationships() void test_hyperlink_relationships()
@ -156,14 +158,14 @@ public:
TS_ASSERT_EQUALS("rId1", ws.cell("A1").get_hyperlink_rel_id()); TS_ASSERT_EQUALS("rId1", ws.cell("A1").get_hyperlink_rel_id());
TS_ASSERT_EQUALS("rId1", ws.get_relationships()[0].get_id()); TS_ASSERT_EQUALS("rId1", ws.get_relationships()[0].get_id());
TS_ASSERT_EQUALS("http:test.com", ws.get_relationships()[0].get_target_uri()); TS_ASSERT_EQUALS("http:test.com", ws.get_relationships()[0].get_target_uri());
TS_ASSERT_EQUALS(xlnt::target_mode::External, ws.get_relationships()[0].get_target_mode()); TS_ASSERT_EQUALS(xlnt::target_mode::external, ws.get_relationships()[0].get_target_mode());
ws.cell("A2").set_hyperlink("http:test2.com"); ws.cell("A2").set_hyperlink("http:test2.com");
TS_ASSERT_EQUALS(ws.get_relationships().size(), 2); TS_ASSERT_EQUALS(ws.get_relationships().size(), 2);
TS_ASSERT_EQUALS("rId2", ws.cell("A2").get_hyperlink_rel_id()); TS_ASSERT_EQUALS("rId2", ws.cell("A2").get_hyperlink_rel_id());
TS_ASSERT_EQUALS("rId2", ws.get_relationships()[1].get_id()); TS_ASSERT_EQUALS("rId2", ws.get_relationships()[1].get_id());
TS_ASSERT_EQUALS("http:test2.com", ws.get_relationships()[1].get_target_uri()); TS_ASSERT_EQUALS("http:test2.com", ws.get_relationships()[1].get_target_uri());
TS_ASSERT_EQUALS(xlnt::target_mode::External, ws.get_relationships()[1].get_target_mode()); TS_ASSERT_EQUALS(xlnt::target_mode::external, ws.get_relationships()[1].get_target_mode());
} }
void test_bad_relationship_type() void test_bad_relationship_type()

View File

@ -11,13 +11,13 @@
#include <cxxtest/TestRunner.h> #include <cxxtest/TestRunner.h>
#include <cxxtest/RealDescriptions.h> #include <cxxtest/RealDescriptions.h>
#include <cxxtest/TestMain.h> #include <cxxtest/TestMain.h>
#include <cxxtest/ParenPrinter.h> #include <cxxtest/ErrorPrinter.h>
int main( int argc, char *argv[] ) { int main( int argc, char *argv[] ) {
int status; int status;
CxxTest::ParenPrinter tmp; CxxTest::ErrorPrinter tmp;
CxxTest::RealWorldDescription::_worldName = "cxxtest"; CxxTest::RealWorldDescription::_worldName = "cxxtest";
status = CxxTest::Main< CxxTest::ParenPrinter >( tmp, argc, argv ); status = CxxTest::Main< CxxTest::ErrorPrinter >( tmp, argc, argv );
return status; return status;
} }
bool suite_CellTestSuite_init = false; bool suite_CellTestSuite_init = false;
@ -290,37 +290,37 @@ public:
static class TestDescription_suite_DumpTestSuite_test_dump_sheet : public CxxTest::RealTestDescription { static class TestDescription_suite_DumpTestSuite_test_dump_sheet : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_DumpTestSuite_test_dump_sheet() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 31, "test_dump_sheet" ) {} TestDescription_suite_DumpTestSuite_test_dump_sheet() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 34, "test_dump_sheet" ) {}
void runTest() { suite_DumpTestSuite.test_dump_sheet(); } void runTest() { suite_DumpTestSuite.test_dump_sheet(); }
} testDescription_suite_DumpTestSuite_test_dump_sheet; } testDescription_suite_DumpTestSuite_test_dump_sheet;
static class TestDescription_suite_DumpTestSuite_test_table_builder : public CxxTest::RealTestDescription { static class TestDescription_suite_DumpTestSuite_test_table_builder : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_DumpTestSuite_test_table_builder() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 99, "test_table_builder" ) {} TestDescription_suite_DumpTestSuite_test_table_builder() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 102, "test_table_builder" ) {}
void runTest() { suite_DumpTestSuite.test_table_builder(); } void runTest() { suite_DumpTestSuite.test_table_builder(); }
} testDescription_suite_DumpTestSuite_test_table_builder; } testDescription_suite_DumpTestSuite_test_table_builder;
static class TestDescription_suite_DumpTestSuite_test_open_too_many_files : public CxxTest::RealTestDescription { static class TestDescription_suite_DumpTestSuite_test_open_too_many_files : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_DumpTestSuite_test_open_too_many_files() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 121, "test_open_too_many_files" ) {} TestDescription_suite_DumpTestSuite_test_open_too_many_files() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 124, "test_open_too_many_files" ) {}
void runTest() { suite_DumpTestSuite.test_open_too_many_files(); } void runTest() { suite_DumpTestSuite.test_open_too_many_files(); }
} testDescription_suite_DumpTestSuite_test_open_too_many_files; } testDescription_suite_DumpTestSuite_test_open_too_many_files;
static class TestDescription_suite_DumpTestSuite_test_create_temp_file : public CxxTest::RealTestDescription { static class TestDescription_suite_DumpTestSuite_test_create_temp_file : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_DumpTestSuite_test_create_temp_file() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 136, "test_create_temp_file" ) {} TestDescription_suite_DumpTestSuite_test_create_temp_file() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 139, "test_create_temp_file" ) {}
void runTest() { suite_DumpTestSuite.test_create_temp_file(); } void runTest() { suite_DumpTestSuite.test_create_temp_file(); }
} testDescription_suite_DumpTestSuite_test_create_temp_file; } testDescription_suite_DumpTestSuite_test_create_temp_file;
static class TestDescription_suite_DumpTestSuite_test_dump_twice : public CxxTest::RealTestDescription { static class TestDescription_suite_DumpTestSuite_test_dump_twice : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_DumpTestSuite_test_dump_twice() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 143, "test_dump_twice" ) {} TestDescription_suite_DumpTestSuite_test_dump_twice() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 146, "test_dump_twice" ) {}
void runTest() { suite_DumpTestSuite.test_dump_twice(); } void runTest() { suite_DumpTestSuite.test_dump_twice(); }
} testDescription_suite_DumpTestSuite_test_dump_twice; } testDescription_suite_DumpTestSuite_test_dump_twice;
static class TestDescription_suite_DumpTestSuite_test_append_after_save : public CxxTest::RealTestDescription { static class TestDescription_suite_DumpTestSuite_test_append_after_save : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_DumpTestSuite_test_append_after_save() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 159, "test_append_after_save" ) {} TestDescription_suite_DumpTestSuite_test_append_after_save() : CxxTest::RealTestDescription( Tests_DumpTestSuite, suiteDescription_DumpTestSuite, 162, "test_append_after_save" ) {}
void runTest() { suite_DumpTestSuite.test_append_after_save(); } void runTest() { suite_DumpTestSuite.test_append_after_save(); }
} testDescription_suite_DumpTestSuite_test_append_after_save; } testDescription_suite_DumpTestSuite_test_append_after_save;
@ -623,43 +623,6 @@ public:
void runTest() { suite_NumberFormatTestSuite.test_mac_date(); } void runTest() { suite_NumberFormatTestSuite.test_mac_date(); }
} testDescription_suite_NumberFormatTestSuite_test_mac_date; } testDescription_suite_NumberFormatTestSuite_test_mac_date;
#include "C:\Users\taf656\Development\xlnt\source\tests\PackageTestSuite.h"
static PackageTestSuite suite_PackageTestSuite;
static CxxTest::List Tests_PackageTestSuite = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_PackageTestSuite( "../../source/tests/PackageTestSuite.h", 8, "PackageTestSuite", suite_PackageTestSuite, Tests_PackageTestSuite );
static class TestDescription_suite_PackageTestSuite_test_existing_package : public CxxTest::RealTestDescription {
public:
TestDescription_suite_PackageTestSuite_test_existing_package() : CxxTest::RealTestDescription( Tests_PackageTestSuite, suiteDescription_PackageTestSuite, 21, "test_existing_package" ) {}
void runTest() { suite_PackageTestSuite.test_existing_package(); }
} testDescription_suite_PackageTestSuite_test_existing_package;
static class TestDescription_suite_PackageTestSuite_test_new_package : public CxxTest::RealTestDescription {
public:
TestDescription_suite_PackageTestSuite_test_new_package() : CxxTest::RealTestDescription( Tests_PackageTestSuite, suiteDescription_PackageTestSuite, 27, "test_new_package" ) {}
void runTest() { suite_PackageTestSuite.test_new_package(); }
} testDescription_suite_PackageTestSuite_test_new_package;
static class TestDescription_suite_PackageTestSuite_test_read_text : public CxxTest::RealTestDescription {
public:
TestDescription_suite_PackageTestSuite_test_read_text() : CxxTest::RealTestDescription( Tests_PackageTestSuite, suiteDescription_PackageTestSuite, 38, "test_read_text" ) {}
void runTest() { suite_PackageTestSuite.test_read_text(); }
} testDescription_suite_PackageTestSuite_test_read_text;
static class TestDescription_suite_PackageTestSuite_test_write_text : public CxxTest::RealTestDescription {
public:
TestDescription_suite_PackageTestSuite_test_write_text() : CxxTest::RealTestDescription( Tests_PackageTestSuite, suiteDescription_PackageTestSuite, 50, "test_write_text" ) {}
void runTest() { suite_PackageTestSuite.test_write_text(); }
} testDescription_suite_PackageTestSuite_test_write_text;
static class TestDescription_suite_PackageTestSuite_test_read_xml : public CxxTest::RealTestDescription {
public:
TestDescription_suite_PackageTestSuite_test_read_xml() : CxxTest::RealTestDescription( Tests_PackageTestSuite, suiteDescription_PackageTestSuite, 75, "test_read_xml" ) {}
void runTest() { suite_PackageTestSuite.test_read_xml(); }
} testDescription_suite_PackageTestSuite_test_read_xml;
#include "C:\Users\taf656\Development\xlnt\source\tests\PasswordHashTestSuite.h" #include "C:\Users\taf656\Development\xlnt\source\tests\PasswordHashTestSuite.h"
static PasswordHashTestSuite suite_PasswordHashTestSuite; static PasswordHashTestSuite suite_PasswordHashTestSuite;
@ -1343,79 +1306,79 @@ public:
static class TestDescription_suite_WorksheetTestSuite_test_hyperlink_relationships : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_hyperlink_relationships : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_hyperlink_relationships() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 148, "test_hyperlink_relationships" ) {} TestDescription_suite_WorksheetTestSuite_test_hyperlink_relationships() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 150, "test_hyperlink_relationships" ) {}
void runTest() { suite_WorksheetTestSuite.test_hyperlink_relationships(); } void runTest() { suite_WorksheetTestSuite.test_hyperlink_relationships(); }
} testDescription_suite_WorksheetTestSuite_test_hyperlink_relationships; } testDescription_suite_WorksheetTestSuite_test_hyperlink_relationships;
static class TestDescription_suite_WorksheetTestSuite_test_bad_relationship_type : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_bad_relationship_type : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_bad_relationship_type() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 169, "test_bad_relationship_type" ) {} TestDescription_suite_WorksheetTestSuite_test_bad_relationship_type() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 171, "test_bad_relationship_type" ) {}
void runTest() { suite_WorksheetTestSuite.test_bad_relationship_type(); } void runTest() { suite_WorksheetTestSuite.test_bad_relationship_type(); }
} testDescription_suite_WorksheetTestSuite_test_bad_relationship_type; } testDescription_suite_WorksheetTestSuite_test_bad_relationship_type;
static class TestDescription_suite_WorksheetTestSuite_test_append_list : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_append_list : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_append_list() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 174, "test_append_list" ) {} TestDescription_suite_WorksheetTestSuite_test_append_list() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 176, "test_append_list" ) {}
void runTest() { suite_WorksheetTestSuite.test_append_list(); } void runTest() { suite_WorksheetTestSuite.test_append_list(); }
} testDescription_suite_WorksheetTestSuite_test_append_list; } testDescription_suite_WorksheetTestSuite_test_append_list;
static class TestDescription_suite_WorksheetTestSuite_test_append_dict_letter : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_append_dict_letter : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_append_dict_letter() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 184, "test_append_dict_letter" ) {} TestDescription_suite_WorksheetTestSuite_test_append_dict_letter() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 186, "test_append_dict_letter" ) {}
void runTest() { suite_WorksheetTestSuite.test_append_dict_letter(); } void runTest() { suite_WorksheetTestSuite.test_append_dict_letter(); }
} testDescription_suite_WorksheetTestSuite_test_append_dict_letter; } testDescription_suite_WorksheetTestSuite_test_append_dict_letter;
static class TestDescription_suite_WorksheetTestSuite_test_append_dict_index : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_append_dict_index : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_append_dict_index() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 194, "test_append_dict_index" ) {} TestDescription_suite_WorksheetTestSuite_test_append_dict_index() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 196, "test_append_dict_index" ) {}
void runTest() { suite_WorksheetTestSuite.test_append_dict_index(); } void runTest() { suite_WorksheetTestSuite.test_append_dict_index(); }
} testDescription_suite_WorksheetTestSuite_test_append_dict_index; } testDescription_suite_WorksheetTestSuite_test_append_dict_index;
static class TestDescription_suite_WorksheetTestSuite_test_append_2d_list : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_append_2d_list : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_append_2d_list() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 204, "test_append_2d_list" ) {} TestDescription_suite_WorksheetTestSuite_test_append_2d_list() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 206, "test_append_2d_list" ) {}
void runTest() { suite_WorksheetTestSuite.test_append_2d_list(); } void runTest() { suite_WorksheetTestSuite.test_append_2d_list(); }
} testDescription_suite_WorksheetTestSuite_test_append_2d_list; } testDescription_suite_WorksheetTestSuite_test_append_2d_list;
static class TestDescription_suite_WorksheetTestSuite_test_rows : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_rows : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_rows() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 219, "test_rows" ) {} TestDescription_suite_WorksheetTestSuite_test_rows() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 221, "test_rows" ) {}
void runTest() { suite_WorksheetTestSuite.test_rows(); } void runTest() { suite_WorksheetTestSuite.test_rows(); }
} testDescription_suite_WorksheetTestSuite_test_rows; } testDescription_suite_WorksheetTestSuite_test_rows;
static class TestDescription_suite_WorksheetTestSuite_test_cols : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_cols : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_cols() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 234, "test_cols" ) {} TestDescription_suite_WorksheetTestSuite_test_cols() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 236, "test_cols" ) {}
void runTest() { suite_WorksheetTestSuite.test_cols(); } void runTest() { suite_WorksheetTestSuite.test_cols(); }
} testDescription_suite_WorksheetTestSuite_test_cols; } testDescription_suite_WorksheetTestSuite_test_cols;
static class TestDescription_suite_WorksheetTestSuite_test_auto_filter : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_auto_filter : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_auto_filter() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 249, "test_auto_filter" ) {} TestDescription_suite_WorksheetTestSuite_test_auto_filter() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 251, "test_auto_filter" ) {}
void runTest() { suite_WorksheetTestSuite.test_auto_filter(); } void runTest() { suite_WorksheetTestSuite.test_auto_filter(); }
} testDescription_suite_WorksheetTestSuite_test_auto_filter; } testDescription_suite_WorksheetTestSuite_test_auto_filter;
static class TestDescription_suite_WorksheetTestSuite_test_page_margins : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_page_margins : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_page_margins() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 263, "test_page_margins" ) {} TestDescription_suite_WorksheetTestSuite_test_page_margins() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 265, "test_page_margins" ) {}
void runTest() { suite_WorksheetTestSuite.test_page_margins(); } void runTest() { suite_WorksheetTestSuite.test_page_margins(); }
} testDescription_suite_WorksheetTestSuite_test_page_margins; } testDescription_suite_WorksheetTestSuite_test_page_margins;
static class TestDescription_suite_WorksheetTestSuite_test_merge : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_merge : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_merge() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 283, "test_merge" ) {} TestDescription_suite_WorksheetTestSuite_test_merge() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 285, "test_merge" ) {}
void runTest() { suite_WorksheetTestSuite.test_merge(); } void runTest() { suite_WorksheetTestSuite.test_merge(); }
} testDescription_suite_WorksheetTestSuite_test_merge; } testDescription_suite_WorksheetTestSuite_test_merge;
static class TestDescription_suite_WorksheetTestSuite_test_freeze : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_freeze : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_freeze() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 304, "test_freeze" ) {} TestDescription_suite_WorksheetTestSuite_test_freeze() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 306, "test_freeze" ) {}
void runTest() { suite_WorksheetTestSuite.test_freeze(); } void runTest() { suite_WorksheetTestSuite.test_freeze(); }
} testDescription_suite_WorksheetTestSuite_test_freeze; } testDescription_suite_WorksheetTestSuite_test_freeze;
static class TestDescription_suite_WorksheetTestSuite_test_printer_settings : public CxxTest::RealTestDescription { static class TestDescription_suite_WorksheetTestSuite_test_printer_settings : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_WorksheetTestSuite_test_printer_settings() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 321, "test_printer_settings" ) {} TestDescription_suite_WorksheetTestSuite_test_printer_settings() : CxxTest::RealTestDescription( Tests_WorksheetTestSuite, suiteDescription_WorksheetTestSuite, 323, "test_printer_settings" ) {}
void runTest() { suite_WorksheetTestSuite.test_printer_settings(); } void runTest() { suite_WorksheetTestSuite.test_printer_settings(); }
} testDescription_suite_WorksheetTestSuite_test_printer_settings; } testDescription_suite_WorksheetTestSuite_test_printer_settings;
@ -1552,5 +1515,42 @@ public:
void runTest() { suite_WriteTestSuite.test_short_number(); } void runTest() { suite_WriteTestSuite.test_short_number(); }
} testDescription_suite_WriteTestSuite_test_short_number; } testDescription_suite_WriteTestSuite_test_short_number;
#include "C:\Users\taf656\Development\xlnt\source\tests\ZipFileTestSuite.h"
static ZipFileTestSuite suite_ZipFileTestSuite;
static CxxTest::List Tests_ZipFileTestSuite = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_ZipFileTestSuite( "../../source/tests/ZipFileTestSuite.h", 8, "ZipFileTestSuite", suite_ZipFileTestSuite, Tests_ZipFileTestSuite );
static class TestDescription_suite_ZipFileTestSuite_test_existing_package : public CxxTest::RealTestDescription {
public:
TestDescription_suite_ZipFileTestSuite_test_existing_package() : CxxTest::RealTestDescription( Tests_ZipFileTestSuite, suiteDescription_ZipFileTestSuite, 21, "test_existing_package" ) {}
void runTest() { suite_ZipFileTestSuite.test_existing_package(); }
} testDescription_suite_ZipFileTestSuite_test_existing_package;
static class TestDescription_suite_ZipFileTestSuite_test_new_package : public CxxTest::RealTestDescription {
public:
TestDescription_suite_ZipFileTestSuite_test_new_package() : CxxTest::RealTestDescription( Tests_ZipFileTestSuite, suiteDescription_ZipFileTestSuite, 27, "test_new_package" ) {}
void runTest() { suite_ZipFileTestSuite.test_new_package(); }
} testDescription_suite_ZipFileTestSuite_test_new_package;
static class TestDescription_suite_ZipFileTestSuite_test_read_text : public CxxTest::RealTestDescription {
public:
TestDescription_suite_ZipFileTestSuite_test_read_text() : CxxTest::RealTestDescription( Tests_ZipFileTestSuite, suiteDescription_ZipFileTestSuite, 37, "test_read_text" ) {}
void runTest() { suite_ZipFileTestSuite.test_read_text(); }
} testDescription_suite_ZipFileTestSuite_test_read_text;
static class TestDescription_suite_ZipFileTestSuite_test_write_text : public CxxTest::RealTestDescription {
public:
TestDescription_suite_ZipFileTestSuite_test_write_text() : CxxTest::RealTestDescription( Tests_ZipFileTestSuite, suiteDescription_ZipFileTestSuite, 44, "test_write_text" ) {}
void runTest() { suite_ZipFileTestSuite.test_write_text(); }
} testDescription_suite_ZipFileTestSuite_test_write_text;
static class TestDescription_suite_ZipFileTestSuite_test_read_xml : public CxxTest::RealTestDescription {
public:
TestDescription_suite_ZipFileTestSuite_test_read_xml() : CxxTest::RealTestDescription( Tests_ZipFileTestSuite, suiteDescription_ZipFileTestSuite, 58, "test_read_xml" ) {}
void runTest() { suite_ZipFileTestSuite.test_read_xml(); }
} testDescription_suite_ZipFileTestSuite_test_read_xml;
#include <cxxtest/Root.cpp> #include <cxxtest/Root.cpp>
const char* CxxTest::RealWorldDescription::_worldName = "cxxtest"; const char* CxxTest::RealWorldDescription::_worldName = "cxxtest";

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,13 @@
#pragma once #pragma once
#include <list>
#include <ostream> #include <ostream>
#include <set>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <opc/opc.h>
#include <opc/container.h> #include "zip.h"
#include "unzip.h"
struct tm; struct tm;
@ -16,7 +17,6 @@ class cell;
class comment; class comment;
class drawing; class drawing;
class named_range; class named_range;
class package;
class relationship; class relationship;
class style; class style;
class workbook; class workbook;
@ -25,7 +25,6 @@ class worksheet;
struct cell_struct; struct cell_struct;
struct drawing_struct; struct drawing_struct;
struct named_range_struct; struct named_range_struct;
struct package_impl;
struct worksheet_struct; struct worksheet_struct;
const int MIN_ROW = 0; const int MIN_ROW = 0;
@ -97,19 +96,15 @@ enum class file_access
/// <summary> /// <summary>
/// Read access to the file. Data can be read from the file. Combine with Write for read/write access. /// Read access to the file. Data can be read from the file. Combine with Write for read/write access.
/// </summary> /// </summary>
Read = 0x01, read = 0x01,
/// <summary> /// <summary>
/// Read and write access to the file. Data can be written to and read from the file. /// Read and write access to the file. Data can be written to and read from the file.
/// </summary> /// </summary>
ReadWrite = 0x02, read_write = 0x02,
/// <summary> /// <summary>
/// Write access to the file. Data can be written to the file. Combine with Read for read/write access. /// Write access to the file. Data can be written to the file. Combine with Read for read/write access.
/// </summary> /// </summary>
Write = 0x04, write = 0x04
/// <summary>
/// Inherit access for part from enclosing package.
/// </summary>
FromPackage = 0x08
}; };
/// <summary> /// <summary>
@ -120,65 +115,27 @@ enum class file_mode
/// <summary> /// <summary>
/// Opens the file if it exists and seeks to the end of the file, or creates a new file.This requires FileIOPermissionAccess.Append permission.file_mode.Append can be used only in conjunction with file_access.Write.Trying to seek to a position before the end of the file throws an IOException exception, and any attempt to read fails and throws a NotSupportedException exception. /// Opens the file if it exists and seeks to the end of the file, or creates a new file.This requires FileIOPermissionAccess.Append permission.file_mode.Append can be used only in conjunction with file_access.Write.Trying to seek to a position before the end of the file throws an IOException exception, and any attempt to read fails and throws a NotSupportedException exception.
/// </summary> /// </summary>
Append, append,
/// <summary> /// <summary>
/// Specifies that the operating system should create a new file. If the file already exists, it will be overwritten. This requires FileIOPermissionAccess.Write permission. file_mode.Create is equivalent to requesting that if the file does not exist, use CreateNew; otherwise, use Truncate. If the file already exists but is a hidden file, an UnauthorizedAccessException exception is thrown. /// Specifies that the operating system should create a new file. If the file already exists, it will be overwritten. This requires FileIOPermissionAccess.Write permission. file_mode.Create is equivalent to requesting that if the file does not exist, use CreateNew; otherwise, use Truncate. If the file already exists but is a hidden file, an UnauthorizedAccessException exception is thrown.
/// </summary> /// </summary>
Create, create,
/// <summary> /// <summary>
/// Specifies that the operating system should create a new file. This requires FileIOPermissionAccess.Write permission. If the file already exists, an IOException exception is thrown. /// Specifies that the operating system should create a new file. This requires FileIOPermissionAccess.Write permission. If the file already exists, an IOException exception is thrown.
/// </summary> /// </summary>
CreateNew, create_new,
/// <summary> /// <summary>
/// Specifies that the operating system should open an existing file. The ability to open the file is dependent on the value specified by the file_access enumeration. A System.IO.FileNotFoundException exception is thrown if the file does not exist. /// Specifies that the operating system should open an existing file. The ability to open the file is dependent on the value specified by the file_access enumeration. A System.IO.FileNotFoundException exception is thrown if the file does not exist.
/// </summary> /// </summary>
Open, open,
/// <summary> /// <summary>
/// Specifies that the operating system should open a file if it exists; otherwise, a new file should be created. If the file is opened with file_access.Read, FileIOPermissionAccess.Read permission is required. If the file access is file_access.Write, FileIOPermissionAccess.Write permission is required. If the file is opened with file_access.ReadWrite, both FileIOPermissionAccess.Read and FileIOPermissionAccess.Write permissions are required. /// Specifies that the operating system should open a file if it exists; otherwise, a new file should be created. If the file is opened with file_access.Read, FileIOPermissionAccess.Read permission is required. If the file access is file_access.Write, FileIOPermissionAccess.Write permission is required. If the file is opened with file_access.ReadWrite, both FileIOPermissionAccess.Read and FileIOPermissionAccess.Write permissions are required.
/// </summary> /// </summary>
OpenOrCreate, open_or_create,
/// <summary> /// <summary>
/// Specifies that the operating system should open an existing file. When the file is opened, it should be truncated so that its size is zero bytes. This requires FileIOPermissionAccess.Write permission. Attempts to read from a file opened with file_mode.Truncate cause an ArgumentException exception. /// Specifies that the operating system should open an existing file. When the file is opened, it should be truncated so that its size is zero bytes. This requires FileIOPermissionAccess.Write permission. Attempts to read from a file opened with file_mode.Truncate cause an ArgumentException exception.
/// </summary> /// </summary>
Truncate truncate
};
/// <summary>
/// Contains constants for controlling the kind of access other FileStream objects can have to the same file.
/// </summary>
enum class file_share
{
/// <summary>
/// Allows subsequent deleting of a file.
/// </summary>
Delete,
/// <summary>
/// Makes the file handle inheritable by child processes. This is not directly supported by Win32.
/// </summary>
Inheritable,
/// <summary>
/// Declines sharing of the current file. Any request to open the file (by this process or another process) will
/// fail until the file is closed.
/// </summary>
None,
/// <summary>
/// Allows subsequent opening of the file for reading. If this flag is not specified, any request to open the file
/// for reading (by this process or another process) will fail until the file is closed. However, even if this flag
/// is specified, additional permissions might still be needed to access the file.
/// </summary>
Read,
/// <summary>
/// Allows subsequent opening of the file for reading or writing. If this flag is not specified, any request to
/// open the file for reading or writing (by this process or another process) will fail until the file is closed.
/// However, even if this flag is specified, additional permissions might still be needed to access the file.
/// </summary>
ReadWrite,
/// <summary>
/// Allows subsequent opening of the file for writing. If this flag is not specified, any request to open the file
/// for writing (by this process or another process) will fail until the file is closed. However, even if this flag
/// is specified, additional permissions might still be needed to access the file.
/// </summary>
Write
}; };
/// <summary> /// <summary>
@ -189,11 +146,11 @@ enum class target_mode
/// <summary> /// <summary>
/// The relationship references a part that is inside the package. /// The relationship references a part that is inside the package.
/// </summary> /// </summary>
External, external,
/// <summary> /// <summary>
/// The relationship references a resource that is external to the package. /// The relationship references a resource that is external to the package.
/// </summary> /// </summary>
Internal internal
}; };
enum class encoding_type enum class encoding_type
@ -222,6 +179,53 @@ public:
} }
}; };
class zip_file
{
enum class state
{
read,
write,
closed
};
public:
zip_file(const std::string &filename, file_mode mode, file_access access = file_access::read);
~zip_file();
std::string get_file_contents(const std::string &filename);
void set_file_contents(const std::string &filename, const std::string &contents);
void delete_file(const std::string &filename);
bool has_file(const std::string &filename);
void flush(bool force_write = false);
private:
void read_all();
void write_all();
std::string read_from_zip(const std::string &filename);
void write_to_zip(const std::string &filename, const std::string &content, bool append = true);
void change_state(state new_state, bool append = true);
static bool file_exists(const std::string& name);
void start_read();
void stop_read();
void start_write(bool append);
void stop_write();
zipFile zip_file_;
unzFile unzip_file_;
state current_state_;
std::string filename_;
std::unordered_map<std::string, std::string> files_;
bool modified_;
file_mode mode_;
file_access access_;
std::vector<std::string> directories_;
};
/// <summary> /// <summary>
/// Represents a value type that may or may not have an assigned value. /// Represents a value type that may or may not have an assigned value.
/// </summary> /// </summary>
@ -424,10 +428,8 @@ public:
std::string get_target_uri() const { return target_uri_; } std::string get_target_uri() const { return target_uri_; }
private: private:
friend class package; relationship(const std::string &id, const std::string &relationship_type_, const std::string &source_uri, target_mode target_mode, const std::string &target_uri);
//relationship &operator=(const relationship &rhs) = delete;
relationship(const std::string &id, package &package, const std::string &relationship_type_, const std::string &source_uri, target_mode target_mode, const std::string &target_uri);
relationship &operator=(const relationship &rhs) = delete;
type type_; type type_;
std::string id_; std::string id_;
@ -438,390 +440,6 @@ private:
typedef std::vector<relationship> relationship_collection; typedef std::vector<relationship> relationship_collection;
class opc_callback_handler
{
public:
static int read(void *context, char *buffer, int length);
static int write(void *context, const char *buffer, int length);
static int close(void *context);
static opc_ofs_t seek(void *context, opc_ofs_t ofs);
static int trim(void *context, opc_ofs_t new_size);
static int flush(void *context);
};
struct part_struct;
/// <summary>
/// Represents a part that is stored in a ZipPackage.
/// </summary>
class part
{
public:
/// <summary>
/// Initializes a new instance of the part class with a specified parent Package, part URI, MIME content type, and compression_option.
/// </summary>
part(package_impl &package, const std::string &uri_part, const std::string &mime_type = "", compression_option compression = compression_option::NotCompressed);
part &operator=(const part &) = delete;
/// <summary>
/// gets the compression option of the part content stream.
/// </summary>
compression_option get_compression_option() const;
/// <summary>
/// gets the MIME type of the content stream.
/// </summary>
std::string get_content_type() const;
/// <summary>
/// gets the parent Package of the part.
/// </summary>
package &get_package() const;
/// <summary>
/// gets the URI of the part.
/// </summary>
std::string get_uri() const;
/// <summary>
/// Creates a part-level relationship between this part to a specified target part or external resource.
/// </summary>
relationship create_relationship(const std::string &target_uri, target_mode target_mode, const std::string &relationship_type);
/// <summary>
/// Deletes a specified part-level relationship.
/// </summary>
void delete_relationship(const std::string &id);
/// <summary>
/// Returns the relationship that has a specified Id.
/// </summary>
relationship get_relationship(const std::string &id);
/// <summary>
/// Returns a collection of all the relationships that are owned by this part.
/// </summary>
relationship_collection get_relationships();
/// <summary>
/// Returns a collection of the relationships that match a specified RelationshipType.
/// </summary>
relationship_collection get_relationship_by_type(const std::string &relationship_type);
/// <summary>
/// Returns all the content of this part.
/// </summary>
std::string read();
/// <summary>
/// Writes the given data to the part stream.
/// </summary>
void write(const std::string &data);
/// <summary>
/// Returns a value that indicates whether this part owns a relationship with a specified Id.
/// </summary>
bool relationship_exists(const std::string &id) const;
bool operator==(const part &comparand) const;
bool operator==(const std::nullptr_t &) const;
private:
friend struct package_impl;
part(part_struct *root);
part_struct *root_;
};
typedef std::vector<part> part_collection;
/// <summary>
/// Implements a derived subclass of the abstract Package base class—the ZipPackage class uses a
/// ZIP archive as the container store. This class should not be inherited.
/// </summary>
class package
{
public:
enum class type
{
Excel,
Word,
Powerpoint,
Zip
};
package();
~package();
type get_type() const;
/// <summary>
/// Opens a package with a given IO stream, file mode, and file access setting.
/// </summary>
void open(std::iostream &stream, file_mode package_mode, file_access package_access);
/// <summary>
/// Opens a package at a given path using a given file mode, file access, and file share setting.
/// </summary>
void open(const std::string &path, file_mode package_mode = file_mode::OpenOrCreate,
file_access package_access = file_access::ReadWrite, file_share package_share = file_share::None);
/// <summary>
/// Saves and closes the package plus all underlying part streams.
/// </summary>
void close();
/// <summary>
/// Creates a new part with a given URI, content type, and compression option.
/// </summary>
part create_part(const std::string &part_uri, const std::string &content_type, compression_option compression = compression_option::Normal);
/// <summary>
/// Creates a package-level relationship to a part with a given URI, target mode, relationship type, and identifier (ID).
/// </summary>
relationship create_relationship(const std::string &part_uri, target_mode target_mode, const std::string &relationship_type, const std::string &id);
/// <summary>
/// Deletes a part with a given URI from the package.
/// </summary>
void delete_part(const std::string &part_uri);
/// <summary>
/// Deletes a package-level relationship.
/// </summary>
void delete_relationship(const std::string &id);
/// <summary>
/// Saves the contents of all parts and relationships that are contained in the package.
/// </summary>
void flush();
/// <summary>
/// Returns the part with a given URI.
/// </summary>
part get_part(const std::string &part_uri);
/// <summary>
/// Returns a collection of all the parts in the package.
/// </summary>
part_collection get_parts();
/// <summary>
///
/// </summary>
relationship get_relationship(const std::string &id);
/// <summary>
/// Returns the package-level relationship with a given identifier.
/// </summary>
relationship_collection get_relationships();
/// <summary>
/// Returns a collection of all the package-level relationships that match a given RelationshipType.
/// </summary>
relationship_collection get_relationships(const std::string &relationship_type);
/// <summary>
/// Indicates whether a part with a given URI is in the package.
/// </summary>
bool part_exists(const std::string &part_uri);
/// <summary>
/// Indicates whether a package-level relationship with a given ID is contained in the package.
/// </summary>
bool relationship_exists(const std::string &id);
/// <summary>
/// gets the file access setting for the package.
/// </summary>
file_access get_file_open_access() const;
bool operator==(const package &comparand) const;
bool operator==(const std::nullptr_t &) const;
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_category() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_category(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_content_status() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_content_status(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_content_type() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_content_type(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
nullable<tm> get_created() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_created(const nullable<tm> &created);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_creator() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_creator(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_description() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_description(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_identifier() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_identifier(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_keywords() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_keywords(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_language() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_language(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_last_modified_by() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_last_modified_by(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
nullable<tm> get_last_printed() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_last_printed(const nullable<tm> &created);
/// <summary>
/// gets the category of the Package.
/// </summary>
nullable<tm> get_modified() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_modified(const nullable<tm> &created);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_revision() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_revision(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string getsubject() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void setsubject(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_title() const;
/// Ssummary>
/// gets the category of the Package.
/// </summary>
void set_title(const std::string &category);
/// <summary>
/// gets the category of the Package.
/// </summary>
std::string get_version() const;
/// <summary>
/// sets the category of the Package.
/// </summary>
void set_version(const std::string &category);
private:
friend opc_callback_handler;
void open_container();
int write(char *buffer, int length);
int read(const char *buffer, int length);
std::ios::pos_type seek(std::ios::pos_type ofs);
int trim(std::ios::pos_type new_size);
package_impl *impl_;
};
struct coordinate struct coordinate
{ {
std::string column; std::string column;
@ -1077,7 +695,10 @@ public:
static std::string hash_password(const std::string &password); static std::string hash_password(const std::string &password);
void set_password(const std::string &password); void set_password(const std::string &password);
std::string get_hashed_password() const; std::string get_hashed_password() const { return hashed_password_; }
private:
std::string hashed_password_;
}; };
class style class style
@ -1118,6 +739,13 @@ private:
protection protection_; protection protection_;
}; };
enum class optimized
{
write,
read,
none
};
/// <summary> /// <summary>
/// Describes cell associated properties. /// Describes cell associated properties.
/// </summary> /// </summary>
@ -1176,9 +804,9 @@ public:
static std::string check_numeric(const std::string &value); static std::string check_numeric(const std::string &value);
static std::string check_error(const std::string &value); static std::string check_error(const std::string &value);
cell(); xlnt::cell();
cell(worksheet &ws, const std::string &column, int row); xlnt::cell(worksheet &ws, const std::string &column, int row);
cell(worksheet &ws, const std::string &column, int row, const std::string &initial_value); xlnt::cell(worksheet &ws, const std::string &column, int row, const std::string &initial_value);
int get_row() const; int get_row() const;
std::string get_column() const; std::string get_column() const;
@ -1257,12 +885,12 @@ private:
cell_struct *root_; cell_struct *root_;
}; };
inline std::ostream &operator<<(std::ostream &stream, const cell &cell) inline std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell)
{ {
return stream << cell.to_string(); return stream << cell.to_string();
} }
typedef std::vector<std::vector<cell>> range; typedef std::vector<std::vector<xlnt::cell>> range;
struct page_setup struct page_setup
{ {
@ -1354,6 +982,7 @@ public:
private: private:
friend class workbook; friend class workbook;
friend class cell;
worksheet(worksheet_struct *root); worksheet(worksheet_struct *root);
worksheet_struct *root_; worksheet_struct *root_;
}; };
@ -1385,17 +1014,27 @@ class writer
public: public:
static std::string write_content_types(workbook &wb); static std::string write_content_types(workbook &wb);
static std::string write_root_rels(workbook &wb); static std::string write_root_rels(workbook &wb);
static std::string write_worksheet(worksheet &ws); static std::string write_workbook(workbook &ws);
static std::string write_worksheet(worksheet ws);
static std::string get_document_content(const std::string &filename); static std::string get_document_content(const std::string &filename);
static std::string create_temporary_file(); static std::string create_temporary_file();
static std::string delete_temporary_file(const std::string &filename); static void delete_temporary_file(const std::string &filename);
};
class reader
{
public:
static std::pair<std::unordered_map<std::string, std::string>, std::unordered_map<std::string, std::string>> read_content_types(const std::string &content);
static std::unordered_map<std::string, std::pair<std::string, std::string>> read_relationships(const std::string &content);
static void read_workbook(workbook &ws, zip_file &file);
static void read_worksheet(worksheet ws, const std::string &content);
}; };
class workbook class workbook
{ {
public: public:
//constructors //constructors
workbook(); workbook(optimized optimized = optimized::none);
//prevent copy and assignment //prevent copy and assignment
workbook(const workbook &) = delete; workbook(const workbook &) = delete;
@ -1437,6 +1076,7 @@ public:
int get_index(worksheet worksheet); int get_index(worksheet worksheet);
worksheet operator[](const std::string &name); worksheet operator[](const std::string &name);
worksheet operator[](int index);
std::vector<worksheet>::iterator begin(); std::vector<worksheet>::iterator begin();
std::vector<worksheet>::iterator end(); std::vector<worksheet>::iterator end();

1
third-party/zlib vendored Submodule

@ -0,0 +1 @@
Subproject commit 50893291621658f355bc5b4d450a8d06a563053d