some changes

This commit is contained in:
Thomas Fussell 2014-08-01 16:46:54 -04:00
parent 0bc0b9c69f
commit 5ccc345f8c
16 changed files with 363 additions and 259 deletions

View File

@ -61,6 +61,9 @@ public:
void reset();
bool has_file(const std::string &name);
bool has_file(const zip_info &name);
zip_info getinfo(const std::string &name);
std::vector<zip_info> infolist();

View File

@ -79,9 +79,9 @@ public:
}
};
static const std::unordered_map<format, std::string, format_hash> format_strings;
static const std::unordered_map<int, std::string> builtin_formats;
static const std::unordered_map<std::string, int> reversed_builtin_formats;
static const std::unordered_map<format, std::string, format_hash> &format_strings();
static const std::unordered_map<int, std::string> &builtin_formats();
static const std::unordered_map<std::string, int> &reversed_builtin_formats();
static std::string builtin_format_code(int index);
static format lookup_format(int code);

View File

@ -263,6 +263,8 @@ public:
const std::unordered_map<column_t, double> &get_column_dimensions() const;
const std::unordered_map<row_t, double> &get_row_dimensions() const;
std::string unique_sheet_name(const std::string &value) const;
// named range
void create_named_range(const std::string &name, const range_reference &reference);
bool has_named_range(const std::string &name);

View File

@ -234,6 +234,9 @@ void cell::set_value(double d)
void cell::set_value(const date &d)
{
d_->is_date_ = true;
auto date_format_code = xlnt::number_format::lookup_format(14);
auto number_format = xlnt::number_format(date_format_code);
get_style().set_number_format(number_format);
auto base_date = get_parent().get_parent().get_properties().excel_base_date;
set_value(d.to_number(base_date));
}
@ -241,6 +244,9 @@ void cell::set_value(const date &d)
void cell::set_value(const datetime &d)
{
d_->is_date_ = true;
auto date_format_code = xlnt::number_format::lookup_format(22);
auto number_format = xlnt::number_format(date_format_code);
get_style().set_number_format(number_format);
auto base_date = get_parent().get_parent().get_properties().excel_base_date;
set_value(d.to_number(base_date));
}

View File

@ -4,7 +4,9 @@
namespace xlnt {
const std::unordered_map<number_format::format, std::string, number_format::format_hash> number_format::format_strings =
const std::unordered_map<number_format::format, std::string, number_format::format_hash> &number_format::format_strings()
{
static const std::unordered_map<number_format::format, std::string, number_format::format_hash> strings =
{
{format::general, "General"},
{format::text, "@"},
@ -42,7 +44,12 @@ const std::unordered_map<number_format::format, std::string, number_format::form
{format::currency_eur_simple, "[$EUR ]#,##0.00_-"}
};
const std::unordered_map<int, std::string> number_format::builtin_formats =
return strings;
}
const std::unordered_map<int, std::string> &number_format::builtin_formats()
{
static const std::unordered_map<int, std::string> formats =
{
{0, "General"},
{1, "0"},
@ -95,7 +102,12 @@ const std::unordered_map<int, std::string> number_format::builtin_formats =
//{55, "yyyy/mm/dd"}
};
const std::unordered_map<std::string, int> number_format::reversed_builtin_formats =
return formats;
}
const std::unordered_map<std::string, int> &number_format::reversed_builtin_formats()
{
static const std::unordered_map<std::string, int> formats =
{
{"General", 0},
{"0", 1},
@ -138,17 +150,20 @@ const std::unordered_map<std::string, int> number_format::reversed_builtin_forma
{"@", 49}
};
return formats;
}
number_format::format number_format::lookup_format(int code)
{
if(builtin_formats.find(code) == builtin_formats.end())
if(builtin_formats().find(code) == builtin_formats().end())
{
return format::unknown;
}
auto format_string = builtin_formats.at(code);
auto match = std::find_if(format_strings.begin(), format_strings.end(), [&](const std::pair<format, std::string> &p) { return p.second == format_string; });
auto format_string = builtin_formats().at(code);
auto match = std::find_if(format_strings().begin(), format_strings().end(), [&](const std::pair<format, std::string> &p) { return p.second == format_string; });
if(match == format_strings.end())
if(match == format_strings().end())
{
return format::unknown;
}

View File

@ -187,9 +187,10 @@ std::vector<std::pair<std::string, std::string>> reader::read_content_types(zip_
try
{
doc.load(archive.read("[Content_Types].xml").c_str());
auto content_types_string = archive.read("[Content_Types].xml");
doc.load(content_types_string.c_str());
}
catch(std::out_of_range)
catch(std::exception e)
{
throw invalid_file_exception(archive.get_filename());
}

View File

@ -63,6 +63,14 @@ std::string style_writer::write_table() const
style_sheet_node.append_attribute("mc:Ignorable").set_value("x14ac");
style_sheet_node.append_attribute("xmlns:x14ac").set_value("http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
for(auto style : get_styles())
{
if((int)style.get_number_format().get_format_code() > 163)
{
}
}
auto fonts_node = style_sheet_node.append_child("fonts");
fonts_node.append_attribute("count").set_value(1);
fonts_node.append_attribute("x14ac:knownFonts").set_value(1);

View File

@ -285,16 +285,23 @@ bool workbook::load(const std::vector<unsigned char> &data)
bool workbook::load(const std::string &filename)
{
zip_file f(filename);
//auto core_properties = read_core_properties();
//auto app_properties = read_app_properties();
auto content_types = reader::read_content_types(f);
zip_file f;
try
{
f.load(filename);
}
catch(std::exception e)
{
throw invalid_file_exception(filename);
}
auto content_types = reader::read_content_types(f);
auto type = reader::determine_document_type(content_types);
if(type != "excel")
{
throw std::runtime_error("unsupported document type: " + filename);
throw invalid_file_exception(filename);
}
clear();
@ -317,20 +324,16 @@ bool workbook::load(const std::string &filename)
auto sheets_node = root_node.child("sheets");
std::vector<std::string> shared_strings;
auto infolist = f.infolist();
auto shared_strings_info = std::find_if(infolist.begin(), infolist.end(), [](const zip_info &info) { return info.filename == "xl/sharedStrings.xml"; });
if(shared_strings_info != infolist.end())
if(f.has_file("xl/sharedStrings.xml"))
{
shared_strings = xlnt::reader::read_shared_string(f.read(*shared_strings_info));
shared_strings = xlnt::reader::read_shared_string(f.read("xl/sharedStrings.xml"));
}
std::vector<int> number_format_ids;
auto styles_info = std::find_if(infolist.begin(), infolist.end(), [](const zip_info &info) { return info.filename == "xl/styles.xml"; });
if(shared_strings_info != infolist.end())
if(f.has_file("xl/styles.xml"))
{
pugi::xml_document styles_doc;
styles_doc.load(f.read(*styles_info).c_str());
styles_doc.load(f.read("xl/styles.xml").c_str());
auto stylesheet_node = styles_doc.child("styleSheet");
auto cell_xfs_node = stylesheet_node.child("cellXfs");
@ -558,6 +561,8 @@ bool workbook::save(const std::string &filename)
}
}
f.save(filename);
return true;
}

View File

@ -37,6 +37,19 @@ bool worksheet::has_frozen_panes() const
return get_frozen_panes() != cell_reference("A1");
}
std::string worksheet::unique_sheet_name(const std::string &value) const
{
auto names = get_parent().get_sheet_names();
auto match = std::find(names.begin(), names.end(), value);
std::size_t append = 0;
while(match != names.end())
{
append++;
match = std::find(names.begin(), names.end(), value + std::to_string(append));
}
return append == 0 ? value : value + std::to_string(append);
}
void worksheet::create_named_range(const std::string &name, const range_reference &reference)
{
d_->named_ranges_[name] = reference;

View File

@ -210,6 +210,11 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
root_node.append_attribute("xmlns:r").set_value(constants::Namespaces.at("r").c_str());
auto sheet_pr_node = root_node.append_child("sheetPr");
auto outline_pr_node = sheet_pr_node.append_child("outlinePr");
if(!ws.get_page_setup().is_default())
{
auto page_set_up_pr_node = sheet_pr_node.append_child("pageSetUpPr");
page_set_up_pr_node.append_attribute("fitToPage").set_value(ws.get_page_setup().fit_to_page() ? 1 : 0);
}
outline_pr_node.append_attribute("summaryBelow").set_value(1);
outline_pr_node.append_attribute("summaryRight").set_value(1);
auto dimension_node = root_node.append_child("dimension");
@ -474,6 +479,13 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
}
}
if(!ws.get_page_setup().is_default())
{
auto print_options_node = root_node.append_child("printOptions");
print_options_node.append_attribute("horizontalCentered").set_value(ws.get_page_setup().get_horizontal_centered() ? 1 : 0);
print_options_node.append_attribute("verticalCentered").set_value(ws.get_page_setup().get_vertical_centered() ? 1 : 0);
}
auto page_margins_node = root_node.append_child("pageMargins");
page_margins_node.append_attribute("left").set_value(ws.get_page_margins().get_left());
@ -492,9 +504,6 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
page_setup_node.append_attribute("paperSize").set_value((int)ws.get_page_setup().get_paper_size());
page_setup_node.append_attribute("fitToHeight").set_value(ws.get_page_setup().fit_to_height() ? 1 : 0);
page_setup_node.append_attribute("fitToWidth").set_value(ws.get_page_setup().fit_to_width() ? 1 : 0);
auto page_set_up_pr_node = root_node.append_child("pageSetUpPr");
page_set_up_pr_node.append_attribute("fitToPage").set_value(ws.get_page_setup().fit_to_page() ? 1 : 0);
}
if(!ws.get_header_footer().is_default())

View File

@ -1,9 +1,11 @@
#include <algorithm>
#include <fstream>
#define MINIZ_HEADER_FILE_ONLY
#include "miniz.c"
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#else
@ -18,15 +20,19 @@ std::string get_working_directory()
#ifdef _WIN32
TCHAR buffer[MAX_PATH];
GetCurrentDirectory(MAX_PATH, buffer);
return buffer;
#endif
std::wstring working_directory(buffer);
return std::string(working_directory.begin(), working_directory.end());
#else
return "";
#endif
}
#ifdef _WIN32
char directory_separator = '\\';
char alt_directory_separator = '/';
#else
char directory_separator = '/';
char alt_directory_separator = '\\';
#endif
std::string join_path(const std::vector<std::string> &parts)
@ -39,27 +45,44 @@ std::string join_path(const std::vector<std::string> &parts)
if(i++ != parts.size() - 1)
{
joined.append(1, directory_separator);
joined.append(1, '/');
}
}
return joined;
}
std::vector<std::string> split_path(const std::string &path)
std::vector<std::string> split_path(const std::string &path, char delim = directory_separator)
{
std::vector<std::string> split;
std::string::size_type previous_index = 0;
auto separator_index = path.find(directory_separator);
auto separator_index = path.find(delim);
while(separator_index != std::string::npos)
{
split.push_back(path.substr(previous_index, separator_index));
auto part = path.substr(previous_index, separator_index - previous_index);
if(part != "..")
{
split.push_back(part);
}
else
{
split.pop_back();
}
previous_index = separator_index + 1;
separator_index = path.find(previous_index, directory_separator);
separator_index = path.find(delim, previous_index);
}
split.push_back(path.substr(previous_index));
if(split.size() == 1 && delim == directory_separator)
{
auto alternative = split_path(path, alt_directory_separator);
if(alternative.size() > 1)
{
return alternative;
}
}
return split;
}
@ -156,7 +179,7 @@ zip_file::~zip_file()
void zip_file::load(std::istream &stream)
{
reset();
buffer_.assign(std::istreambuf_iterator<char>(stream), {});
buffer_.assign(std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>());
remove_comment();
start_read();
}
@ -229,7 +252,7 @@ void zip_file::append_comment()
{
if(!comment.empty())
{
uint16_t comment_length = comment.length();
auto comment_length = std::min((uint16_t)comment.length(), std::numeric_limits<uint16_t>::max());
buffer_[buffer_.size() - 2] = comment_length & 0xFF;
buffer_[buffer_.size() - 1] = comment_length >> 8 & 0xFF;
std::copy(comment.begin(), comment.end(), std::back_inserter(buffer_));
@ -476,7 +499,7 @@ void zip_file::writestr(const std::string &arcname, const std::string &bytes)
start_write();
}
if(!mz_zip_writer_add_mem(archive_.get(), arcname.c_str(), bytes.data(), bytes.size(), MZ_DEFAULT_COMPRESSION))
if(!mz_zip_writer_add_mem(archive_.get(), arcname.c_str(), bytes.data(), bytes.size(), MZ_BEST_COMPRESSION))
{
throw std::runtime_error("write error");
}
@ -496,7 +519,7 @@ void zip_file::writestr(const zip_info &info, const std::string &bytes)
auto crc = crc32buf(bytes.c_str(), bytes.size());
if(!mz_zip_writer_add_mem_ex(archive_.get(), info.filename.c_str(), bytes.data(), bytes.size(), info.comment.c_str(), (mz_uint16)info.comment.size(), MZ_DEFAULT_COMPRESSION, 0, crc))
if(!mz_zip_writer_add_mem_ex(archive_.get(), info.filename.c_str(), bytes.data(), bytes.size(), info.comment.c_str(), (mz_uint16)info.comment.size(), MZ_BEST_COMPRESSION, 0, crc))
{
throw std::runtime_error("write error");
}
@ -520,6 +543,23 @@ std::string zip_file::read(const std::string &name)
return read(getinfo(name));
}
bool zip_file::has_file(const std::string &name)
{
if(archive_->m_zip_mode != MZ_ZIP_MODE_READING)
{
start_read();
}
int index = mz_zip_reader_locate_file(archive_.get(), name.c_str(), nullptr, 0);
return index != -1;
}
bool zip_file::has_file(const zip_info &name)
{
return has_file(name.filename);
}
std::vector<zip_info> zip_file::infolist()
{
if(archive_->m_zip_mode != MZ_ZIP_MODE_READING)

View File

@ -21,7 +21,7 @@ int main( int argc, char *argv[] ) {
return status;
}
bool suite_test_cell_init = false;
#include "/Users/thomas/Development/xlnt/tests/test_cell.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_cell.hpp"
static test_cell suite_test_cell;
@ -256,7 +256,7 @@ public:
void runTest() { suite_test_cell.test_cell_offset(); }
} testDescription_suite_test_cell_test_cell_offset;
#include "/Users/thomas/Development/xlnt/tests/test_chart.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_chart.hpp"
static test_chart suite_test_chart;
@ -347,7 +347,7 @@ public:
void runTest() { suite_test_chart.test_write_chart_scatter(); }
} testDescription_suite_test_chart_test_write_chart_scatter;
#include "/Users/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;
@ -438,7 +438,7 @@ public:
void runTest() { suite_test_named_range.test_can_be_saved(); }
} testDescription_suite_test_named_range_test_can_be_saved;
#include "/Users/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;
@ -541,7 +541,7 @@ public:
void runTest() { suite_test_number_format.test_mac_date(); }
} testDescription_suite_test_number_format_test_mac_date;
#include "/Users/thomas/Development/xlnt/tests/test_props.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_props.hpp"
static test_props suite_test_props;
@ -584,7 +584,7 @@ public:
void runTest() { suite_test_props.test_write_properties_app(); }
} testDescription_suite_test_props_test_write_properties_app;
#include "/Users/thomas/Development/xlnt/tests/test_read.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_read.hpp"
static test_read suite_test_read;
@ -777,7 +777,7 @@ public:
void runTest() { suite_test_read.test_bad_formats_no(); }
} testDescription_suite_test_read_test_bad_formats_no;
#include "/Users/thomas/Development/xlnt/tests/test_strings.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_strings.hpp"
static test_strings suite_test_strings;
@ -808,7 +808,7 @@ public:
void runTest() { suite_test_strings.test_formatted_string_table(); }
} testDescription_suite_test_strings_test_formatted_string_table;
#include "/Users/thomas/Development/xlnt/tests/test_style.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_style.hpp"
static test_style suite_test_style;
@ -917,7 +917,7 @@ public:
void runTest() { suite_test_style.test_protection(); }
} testDescription_suite_test_style_test_protection;
#include "/Users/thomas/Development/xlnt/tests/test_theme.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_theme.hpp"
static test_theme suite_test_theme;
@ -930,7 +930,7 @@ public:
void runTest() { suite_test_theme.test_write_theme(); }
} testDescription_suite_test_theme_test_write_theme;
#include "/Users/thomas/Development/xlnt/tests/test_workbook.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_workbook.hpp"
static test_workbook suite_test_workbook;
@ -1051,7 +1051,7 @@ public:
void runTest() { suite_test_workbook.test_write_regular_float(); }
} testDescription_suite_test_workbook_test_write_regular_float;
#include "/Users/thomas/Development/xlnt/tests/test_worksheet.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_worksheet.hpp"
static test_worksheet suite_test_worksheet;
@ -1102,197 +1102,197 @@ public:
static class TestDescription_suite_test_worksheet_test_worksheet_dimension : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_worksheet_dimension() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 61, "test_worksheet_dimension" ) {}
TestDescription_suite_test_worksheet_test_worksheet_dimension() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 62, "test_worksheet_dimension" ) {}
void runTest() { suite_test_worksheet.test_worksheet_dimension(); }
} testDescription_suite_test_worksheet_test_worksheet_dimension;
static class TestDescription_suite_test_worksheet_test_worksheet_range : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_worksheet_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 70, "test_worksheet_range" ) {}
TestDescription_suite_test_worksheet_test_worksheet_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 71, "test_worksheet_range" ) {}
void runTest() { suite_test_worksheet.test_worksheet_range(); }
} testDescription_suite_test_worksheet_test_worksheet_range;
static class TestDescription_suite_test_worksheet_test_worksheet_named_range : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_worksheet_named_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 78, "test_worksheet_named_range" ) {}
TestDescription_suite_test_worksheet_test_worksheet_named_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 79, "test_worksheet_named_range" ) {}
void runTest() { suite_test_worksheet.test_worksheet_named_range(); }
} testDescription_suite_test_worksheet_test_worksheet_named_range;
static class TestDescription_suite_test_worksheet_test_bad_named_range : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_bad_named_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 88, "test_bad_named_range" ) {}
TestDescription_suite_test_worksheet_test_bad_named_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 89, "test_bad_named_range" ) {}
void runTest() { suite_test_worksheet.test_bad_named_range(); }
} testDescription_suite_test_worksheet_test_bad_named_range;
static class TestDescription_suite_test_worksheet_test_named_range_wrong_sheet : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_named_range_wrong_sheet() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 94, "test_named_range_wrong_sheet" ) {}
TestDescription_suite_test_worksheet_test_named_range_wrong_sheet() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 95, "test_named_range_wrong_sheet" ) {}
void runTest() { suite_test_worksheet.test_named_range_wrong_sheet(); }
} testDescription_suite_test_worksheet_test_named_range_wrong_sheet;
static class TestDescription_suite_test_worksheet_test_cell_offset : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_cell_offset() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 102, "test_cell_offset" ) {}
TestDescription_suite_test_worksheet_test_cell_offset() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 103, "test_cell_offset" ) {}
void runTest() { suite_test_worksheet.test_cell_offset(); }
} testDescription_suite_test_worksheet_test_cell_offset;
static class TestDescription_suite_test_worksheet_test_range_offset : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_range_offset() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 108, "test_range_offset" ) {}
TestDescription_suite_test_worksheet_test_range_offset() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 109, "test_range_offset" ) {}
void runTest() { suite_test_worksheet.test_range_offset(); }
} testDescription_suite_test_worksheet_test_range_offset;
static class TestDescription_suite_test_worksheet_test_cell_alternate_coordinates : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_cell_alternate_coordinates() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 117, "test_cell_alternate_coordinates" ) {}
TestDescription_suite_test_worksheet_test_cell_alternate_coordinates() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 118, "test_cell_alternate_coordinates" ) {}
void runTest() { suite_test_worksheet.test_cell_alternate_coordinates(); }
} testDescription_suite_test_worksheet_test_cell_alternate_coordinates;
static class TestDescription_suite_test_worksheet_test_cell_range_name : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_cell_range_name() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 124, "test_cell_range_name" ) {}
TestDescription_suite_test_worksheet_test_cell_range_name() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 125, "test_cell_range_name" ) {}
void runTest() { suite_test_worksheet.test_cell_range_name(); }
} testDescription_suite_test_worksheet_test_cell_range_name;
static class TestDescription_suite_test_worksheet_test_garbage_collect : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_garbage_collect() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 136, "test_garbage_collect" ) {}
TestDescription_suite_test_worksheet_test_garbage_collect() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 137, "test_garbage_collect" ) {}
void runTest() { suite_test_worksheet.test_garbage_collect(); }
} testDescription_suite_test_worksheet_test_garbage_collect;
static class TestDescription_suite_test_worksheet_test_hyperlink_relationships : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_hyperlink_relationships() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 173, "test_hyperlink_relationships" ) {}
TestDescription_suite_test_worksheet_test_hyperlink_relationships() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 174, "test_hyperlink_relationships" ) {}
void runTest() { suite_test_worksheet.test_hyperlink_relationships(); }
} testDescription_suite_test_worksheet_test_hyperlink_relationships;
static class TestDescription_suite_test_worksheet_test_bad_relationship_type : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_bad_relationship_type() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 193, "test_bad_relationship_type" ) {}
TestDescription_suite_test_worksheet_test_bad_relationship_type() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 194, "test_bad_relationship_type" ) {}
void runTest() { suite_test_worksheet.test_bad_relationship_type(); }
} testDescription_suite_test_worksheet_test_bad_relationship_type;
static class TestDescription_suite_test_worksheet_test_append_list : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_append_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 198, "test_append_list" ) {}
TestDescription_suite_test_worksheet_test_append_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 199, "test_append_list" ) {}
void runTest() { suite_test_worksheet.test_append_list(); }
} testDescription_suite_test_worksheet_test_append_list;
static class TestDescription_suite_test_worksheet_test_append_dict_letter : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_append_dict_letter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 208, "test_append_dict_letter" ) {}
TestDescription_suite_test_worksheet_test_append_dict_letter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 209, "test_append_dict_letter" ) {}
void runTest() { suite_test_worksheet.test_append_dict_letter(); }
} testDescription_suite_test_worksheet_test_append_dict_letter;
static class TestDescription_suite_test_worksheet_test_append_dict_index : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_append_dict_index() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 218, "test_append_dict_index" ) {}
TestDescription_suite_test_worksheet_test_append_dict_index() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 219, "test_append_dict_index" ) {}
void runTest() { suite_test_worksheet.test_append_dict_index(); }
} testDescription_suite_test_worksheet_test_append_dict_index;
static class TestDescription_suite_test_worksheet_test_append_2d_list : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_append_2d_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 228, "test_append_2d_list" ) {}
TestDescription_suite_test_worksheet_test_append_2d_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 229, "test_append_2d_list" ) {}
void runTest() { suite_test_worksheet.test_append_2d_list(); }
} testDescription_suite_test_worksheet_test_append_2d_list;
static class TestDescription_suite_test_worksheet_test_rows : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_rows() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 243, "test_rows" ) {}
TestDescription_suite_test_worksheet_test_rows() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 244, "test_rows" ) {}
void runTest() { suite_test_worksheet.test_rows(); }
} testDescription_suite_test_worksheet_test_rows;
static class TestDescription_suite_test_worksheet_test_cols : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_cols() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 258, "test_cols" ) {}
TestDescription_suite_test_worksheet_test_cols() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 259, "test_cols" ) {}
void runTest() { suite_test_worksheet.test_cols(); }
} testDescription_suite_test_worksheet_test_cols;
static class TestDescription_suite_test_worksheet_test_auto_filter : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_auto_filter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 273, "test_auto_filter" ) {}
TestDescription_suite_test_worksheet_test_auto_filter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 274, "test_auto_filter" ) {}
void runTest() { suite_test_worksheet.test_auto_filter(); }
} testDescription_suite_test_worksheet_test_auto_filter;
static class TestDescription_suite_test_worksheet_test_getitem : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_getitem() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 287, "test_getitem" ) {}
TestDescription_suite_test_worksheet_test_getitem() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 288, "test_getitem" ) {}
void runTest() { suite_test_worksheet.test_getitem(); }
} testDescription_suite_test_worksheet_test_getitem;
static class TestDescription_suite_test_worksheet_test_setitem : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_setitem() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 294, "test_setitem" ) {}
TestDescription_suite_test_worksheet_test_setitem() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 295, "test_setitem" ) {}
void runTest() { suite_test_worksheet.test_setitem(); }
} testDescription_suite_test_worksheet_test_setitem;
static class TestDescription_suite_test_worksheet_test_getslice : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_getslice() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 301, "test_getslice" ) {}
TestDescription_suite_test_worksheet_test_getslice() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 302, "test_getslice" ) {}
void runTest() { suite_test_worksheet.test_getslice(); }
} testDescription_suite_test_worksheet_test_getslice;
static class TestDescription_suite_test_worksheet_test_freeze : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_freeze() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 311, "test_freeze" ) {}
TestDescription_suite_test_worksheet_test_freeze() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 312, "test_freeze" ) {}
void runTest() { suite_test_worksheet.test_freeze(); }
} testDescription_suite_test_worksheet_test_freeze;
static class TestDescription_suite_test_worksheet_test_write_empty : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_write_empty() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 328, "test_write_empty" ) {}
TestDescription_suite_test_worksheet_test_write_empty() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 329, "test_write_empty" ) {}
void runTest() { suite_test_worksheet.test_write_empty(); }
} testDescription_suite_test_worksheet_test_write_empty;
static class TestDescription_suite_test_worksheet_test_page_margins : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_page_margins() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 359, "test_page_margins" ) {}
TestDescription_suite_test_worksheet_test_page_margins() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 360, "test_page_margins" ) {}
void runTest() { suite_test_worksheet.test_page_margins(); }
} testDescription_suite_test_worksheet_test_page_margins;
static class TestDescription_suite_test_worksheet_test_merge : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_merge() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 397, "test_merge" ) {}
TestDescription_suite_test_worksheet_test_merge() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 398, "test_merge" ) {}
void runTest() { suite_test_worksheet.test_merge(); }
} testDescription_suite_test_worksheet_test_merge;
static class TestDescription_suite_test_worksheet_test_printer_settings : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_printer_settings() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 506, "test_printer_settings" ) {}
TestDescription_suite_test_worksheet_test_printer_settings() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 507, "test_printer_settings" ) {}
void runTest() { suite_test_worksheet.test_printer_settings(); }
} testDescription_suite_test_worksheet_test_printer_settings;
static class TestDescription_suite_test_worksheet_test_header_footer : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_header_footer() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 547, "test_header_footer" ) {}
TestDescription_suite_test_worksheet_test_header_footer() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 550, "test_header_footer" ) {}
void runTest() { suite_test_worksheet.test_header_footer(); }
} testDescription_suite_test_worksheet_test_header_footer;
static class TestDescription_suite_test_worksheet_test_positioning_point : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_positioning_point() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 624, "test_positioning_point" ) {}
TestDescription_suite_test_worksheet_test_positioning_point() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 627, "test_positioning_point" ) {}
void runTest() { suite_test_worksheet.test_positioning_point(); }
} testDescription_suite_test_worksheet_test_positioning_point;
static class TestDescription_suite_test_worksheet_test_positioning_roundtrip : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_positioning_roundtrip() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 630, "test_positioning_roundtrip" ) {}
TestDescription_suite_test_worksheet_test_positioning_roundtrip() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 633, "test_positioning_roundtrip" ) {}
void runTest() { suite_test_worksheet.test_positioning_roundtrip(); }
} testDescription_suite_test_worksheet_test_positioning_roundtrip;
static class TestDescription_suite_test_worksheet_test_page_setup : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_page_setup() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 638, "test_page_setup" ) {}
TestDescription_suite_test_worksheet_test_page_setup() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 641, "test_page_setup" ) {}
void runTest() { suite_test_worksheet.test_page_setup(); }
} testDescription_suite_test_worksheet_test_page_setup;
static class TestDescription_suite_test_worksheet_test_page_options : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_page_options() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 646, "test_page_options" ) {}
TestDescription_suite_test_worksheet_test_page_options() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 649, "test_page_options" ) {}
void runTest() { suite_test_worksheet.test_page_options(); }
} testDescription_suite_test_worksheet_test_page_options;
#include "/Users/thomas/Development/xlnt/tests/test_write.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_write.hpp"
static test_write suite_test_write;
@ -1377,12 +1377,6 @@ public:
void runTest() { suite_test_write.test_write_hyperlink_rels(); }
} testDescription_suite_test_write_test_write_hyperlink_rels;
static class TestDescription_suite_test_write_test_write_hyperlink_image_rels : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_write_test_write_hyperlink_image_rels() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 143, "test_write_hyperlink_image_rels" ) {}
void runTest() { suite_test_write.test_write_hyperlink_image_rels(); }
} testDescription_suite_test_write_test_write_hyperlink_image_rels;
static class TestDescription_suite_test_write_test_hyperlink_value : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_write_test_hyperlink_value() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 148, "test_hyperlink_value" ) {}
@ -1437,13 +1431,7 @@ public:
void runTest() { suite_test_write.test_short_number(); }
} testDescription_suite_test_write_test_short_number;
static class TestDescription_suite_test_write_test_write_images : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_write_test_write_images() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 223, "test_write_images" ) {}
void runTest() { suite_test_write.test_write_images(); }
} testDescription_suite_test_write_test_write_images;
#include "/Users/thomas/Development/xlnt/tests/test_zip_file.hpp"
#include "C:\Users\taf656\Development\xlnt\tests\test_zip_file.hpp"
static test_zip_file suite_test_zip_file;
@ -1566,13 +1554,13 @@ public:
static class TestDescription_suite_test_zip_file_test_writestr : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_zip_file_test_writestr() : CxxTest::RealTestDescription( Tests_test_zip_file, suiteDescription_test_zip_file, 234, "test_writestr" ) {}
TestDescription_suite_test_zip_file_test_writestr() : CxxTest::RealTestDescription( Tests_test_zip_file, suiteDescription_test_zip_file, 244, "test_writestr" ) {}
void runTest() { suite_test_zip_file.test_writestr(); }
} testDescription_suite_test_zip_file_test_writestr;
static class TestDescription_suite_test_zip_file_test_comment : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_zip_file_test_comment() : CxxTest::RealTestDescription( Tests_test_zip_file, suiteDescription_test_zip_file, 252, "test_comment" ) {}
TestDescription_suite_test_zip_file_test_comment() : CxxTest::RealTestDescription( Tests_test_zip_file, suiteDescription_test_zip_file, 263, "test_comment" ) {}
void runTest() { suite_test_zip_file.test_comment(); }
} testDescription_suite_test_zip_file_test_comment;

View File

@ -14,17 +14,17 @@ public:
auto now = xlnt::datetime::now();
auto ws = workbook_.get_active_sheet();
ws.get_cell("A1").set_value("12.34%"); // 2
ws.get_cell("B4").set_value(now); // 3
ws.get_cell("B5").set_value(now);
ws.get_cell("C14").set_value("This is a test"); // 1
ws.get_cell("D9").set_value("31.31415"); // 3
xlnt::style st;
ws.get_cell("B1").set_value(now); // 3
ws.get_cell("C1").set_value(now);
ws.get_cell("D1").set_value("This is a test"); // 1
ws.get_cell("E1").set_value("31.31415"); // 3
xlnt::style st; // 4
st.set_number_format(xlnt::number_format(xlnt::number_format::format::number_00));
st.set_protection(xlnt::protection(xlnt::protection::type::unprotected));
ws.get_cell("D9").set_style(st);
xlnt::style st2;
ws.get_cell("F1").set_style(st);
xlnt::style st2; // 5
st.set_protection(xlnt::protection(xlnt::protection::type::unprotected));
ws.get_cell("E1").set_style(st2);
ws.get_cell("G1").set_style(st2);
}
@ -35,9 +35,9 @@ public:
void test_write_style_table()
{
auto path = PathHelper::GetDataDirectory("/expected/simple-styles.xml");
auto path = PathHelper::GetDataDirectory("/writer/expected/simple-styles.xml");
pugi::xml_document expected;
expected.load(path.c_str());
expected.load_file(path.c_str());
auto content = writer_.write_table();
pugi::xml_document observed;

View File

@ -55,7 +55,8 @@ public:
void test_unique_sheet_title()
{
TS_SKIP("not implemented");
auto ws = wb_.create_sheet("AGE");
TS_ASSERT_EQUALS(ws.unique_sheet_name("GE"), "GE");
}
void test_worksheet_dimension()
@ -512,6 +513,8 @@ public:
ws.get_page_setup().set_fit_to_page(true);
ws.get_page_setup().set_fit_to_height(false);
ws.get_page_setup().set_fit_to_width(true);
ws.get_page_setup().set_horizontal_centered(true);
ws.get_page_setup().set_vertical_centered(true);
auto xml_string = xlnt::writer::write_worksheet(ws);

View File

@ -140,7 +140,7 @@ public:
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_hyperlink.xml.rels", content));
}
void test_write_hyperlink_image_rels()
void _test_write_hyperlink_image_rels()
{
TS_SKIP("not implemented");
}
@ -220,7 +220,7 @@ public:
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/short_number.xml", content));
}
void test_write_images()
void _test_write_images()
{
TS_SKIP("not implemented");
}

View File

@ -55,7 +55,7 @@ public:
remove_temp_file();
xlnt::zip_file f(existing_file);
f.save(temp_file.GetFilename());
assert(files_equal(existing_file, temp_file.GetFilename()));
TS_ASSERT(files_equal(existing_file, temp_file.GetFilename()));
remove_temp_file();
}
@ -68,7 +68,7 @@ public:
std::ofstream out_stream(temp_file.GetFilename(), std::ios::binary);
f.save(out_stream);
}
assert(files_equal(existing_file, temp_file.GetFilename()));
TS_ASSERT(files_equal(existing_file, temp_file.GetFilename()));
remove_temp_file();
}
@ -91,7 +91,7 @@ public:
result_bytes = std::vector<unsigned char>();
f2.save(result_bytes);
assert(source_bytes == result_bytes);
TS_ASSERT(source_bytes == result_bytes);
remove_temp_file();
}
@ -100,7 +100,7 @@ public:
{
xlnt::zip_file f(existing_file);
assert(!f.namelist().empty());
TS_ASSERT(!f.namelist().empty());
try
{
@ -108,17 +108,17 @@ public:
}
catch(std::exception e)
{
assert(false);
TS_ASSERT(false);
}
f.reset();
assert(f.namelist().empty());
TS_ASSERT(f.namelist().empty());
try
{
f.read("[Content_Types].xml");
assert(false);
TS_ASSERT(false);
}
catch(std::exception e)
{
@ -129,19 +129,19 @@ public:
{
xlnt::zip_file f(existing_file);
auto info = f.getinfo("[Content_Types].xml");
assert(info.filename == "[Content_Types].xml");
TS_ASSERT(info.filename == "[Content_Types].xml");
}
void test_infolist()
{
xlnt::zip_file f(existing_file);
assert(f.infolist().size() == 14);
TS_ASSERT(f.infolist().size() == 14);
}
void test_namelist()
{
xlnt::zip_file f(existing_file);
assert(f.namelist().size() == 14);
TS_ASSERT(f.namelist().size() == 14);
}
void test_open_by_name()
@ -150,7 +150,7 @@ public:
std::stringstream ss;
ss << f.open("[Content_Types].xml").rdbuf();
std::string result = ss.str();
assert(result == expected_content_types_string);
TS_ASSERT(result == expected_content_types_string);
}
void test_open_by_info()
@ -159,7 +159,7 @@ public:
std::stringstream ss;
ss << f.open("[Content_Types].xml").rdbuf();
std::string result = ss.str();
assert(result == expected_content_types_string);
TS_ASSERT(result == expected_content_types_string);
}
void test_extract_current_directory()
@ -198,20 +198,20 @@ public:
std::stringstream ss;
f.printdir(ss);
auto printed = ss.str();
assert(printed == expected_printdir_string);
TS_ASSERT(printed == expected_printdir_string);
}
void test_read()
{
xlnt::zip_file f(existing_file);
assert(f.read("[Content_Types].xml") == expected_content_types_string);
assert(f.read(f.getinfo("[Content_Types].xml")) == expected_content_types_string);
TS_ASSERT(f.read("[Content_Types].xml") == expected_content_types_string);
TS_ASSERT(f.read(f.getinfo("[Content_Types].xml")) == expected_content_types_string);
}
void test_testzip()
{
xlnt::zip_file f(existing_file);
assert(f.testzip().first);
TS_ASSERT(f.testzip().first);
}
void test_write()
@ -225,8 +225,18 @@ public:
f.save(temp_file.GetFilename());
xlnt::zip_file f2(temp_file.GetFilename());
assert(f2.read(text_file) == expected_atxt_string);
assert(f2.read("sharedStrings2.xml") == expected_atxt_string);
for(auto &info : f2.infolist())
{
if(info.filename == "sharedStrings2.xml")
{
TS_ASSERT(f2.read(info) == expected_atxt_string);
}
else if(info.filename.substr(info.filename.size() - 17) == "sharedStrings.xml")
{
TS_ASSERT(f2.read(info) == expected_atxt_string);
}
}
remove_temp_file();
}
@ -239,12 +249,13 @@ public:
f.writestr("a.txt", "a\na");
xlnt::zip_info info;
info.filename = "b.txt";
info.date_time.year = 2014;
f.writestr(info, "b\nb");
f.save(temp_file.GetFilename());
xlnt::zip_file f2(temp_file.GetFilename());
assert(f2.read("a.txt") == "a\na");
assert(f2.read(f2.getinfo("b.txt")) == "b\nb");
TS_ASSERT(f2.read("a.txt") == "a\na");
TS_ASSERT(f2.read(f2.getinfo("b.txt")) == "b\nb");
remove_temp_file();
}
@ -258,7 +269,7 @@ public:
f.save(temp_file.GetFilename());
xlnt::zip_file f2(temp_file.GetFilename());
assert(f2.comment == "comment");
TS_ASSERT(f2.comment == "comment");
remove_temp_file();
}