mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
fix windows build and warnings
This commit is contained in:
parent
9c05e04f70
commit
90d8d545ed
|
@ -19,6 +19,7 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||||
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
|
||||||
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
|
||||||
|
add_definitions(-DUNICODE -D_UNICODE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)
|
||||||
|
|
|
@ -17,6 +17,10 @@ source_group(helpers FILES ${TEST_HELPERS_HEADERS} ${TEST_HELPERS_SOURCES})
|
||||||
|
|
||||||
target_link_libraries(xlnt.test xlnt)
|
target_link_libraries(xlnt.test xlnt)
|
||||||
|
|
||||||
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
|
||||||
|
target_link_libraries(xlnt.test Shlwapi)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_custom_target (generate-test-runner
|
add_custom_target (generate-test-runner
|
||||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generate-tests
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generate-tests
|
||||||
COMMENT "Generating test runner tests/runner-autogen.cpp"
|
COMMENT "Generating test runner tests/runner-autogen.cpp"
|
||||||
|
@ -24,9 +28,11 @@ add_custom_target (generate-test-runner
|
||||||
|
|
||||||
add_dependencies(xlnt.test generate-test-runner)
|
add_dependencies(xlnt.test generate-test-runner)
|
||||||
|
|
||||||
add_custom_command(
|
if(${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
|
||||||
TARGET xlnt.test
|
add_custom_command(
|
||||||
POST_BUILD
|
TARGET xlnt.test
|
||||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../bin/xlnt.test
|
POST_BUILD
|
||||||
VERBATIM
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../bin/xlnt.test
|
||||||
)
|
VERBATIM
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
2
configure
vendored
2
configure
vendored
|
@ -33,7 +33,7 @@ if len(sys.argv) > 1:
|
||||||
elif sys.platform == 'darwin':
|
elif sys.platform == 'darwin':
|
||||||
generator = 'Unix Makefiles'
|
generator = 'Unix Makefiles'
|
||||||
elif sys.platform == 'win32':
|
elif sys.platform == 'win32':
|
||||||
generator = 'Visual Studio 14 2015'
|
generator = 'Visual Studio 14 2015 Win64'
|
||||||
|
|
||||||
cmake = 'cmake'
|
cmake = 'cmake'
|
||||||
|
|
||||||
|
|
|
@ -147,29 +147,17 @@ class font
|
||||||
|
|
||||||
std::size_t hash() const
|
std::size_t hash() const
|
||||||
{
|
{
|
||||||
std::size_t seed = bold_;
|
std::size_t seed = 0;
|
||||||
seed = seed << 1 & italic_;
|
|
||||||
seed = seed << 1 & superscript_;
|
hash_combine(seed, bold_);
|
||||||
seed = seed << 1 & subscript_;
|
hash_combine(seed, italic_);
|
||||||
seed = seed << 1 & strikethrough_;
|
hash_combine(seed, superscript_);
|
||||||
|
hash_combine(seed, subscript_);
|
||||||
|
hash_combine(seed, strikethrough_);
|
||||||
hash_combine(seed, name_);
|
hash_combine(seed, name_);
|
||||||
hash_combine(seed, size_);
|
hash_combine(seed, size_);
|
||||||
hash_combine(seed, static_cast<std::size_t>(underline_));
|
hash_combine(seed, static_cast<std::size_t>(underline_));
|
||||||
hash_combine(seed, static_cast<std::size_t>(color_.get_type()));
|
hash_combine(seed, color_.hash());
|
||||||
|
|
||||||
switch (color_.get_type())
|
|
||||||
{
|
|
||||||
case color::type::indexed:
|
|
||||||
hash_combine(seed, color_.get_index());
|
|
||||||
break;
|
|
||||||
case color::type::theme:
|
|
||||||
hash_combine(seed, color_.get_theme());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
hash_combine(seed, family_);
|
hash_combine(seed, family_);
|
||||||
hash_combine(seed, scheme_);
|
hash_combine(seed, scheme_);
|
||||||
|
|
||||||
|
|
|
@ -212,16 +212,16 @@ class workbook
|
||||||
void add_number_format(const number_format &format);
|
void add_number_format(const number_format &format);
|
||||||
void add_protection(const protection &p);
|
void add_protection(const protection &p);
|
||||||
|
|
||||||
std::vector<style> get_styles() const;
|
const std::vector<style> &get_styles() const;
|
||||||
|
|
||||||
std::vector<color> get_colors() const;
|
const std::vector<color> &get_colors() const;
|
||||||
std::vector<border> get_borders() const;
|
const std::vector<border> &get_borders() const;
|
||||||
std::vector<fill> get_fills() const;
|
const std::vector<fill> &get_fills() const;
|
||||||
std::vector<font> get_fonts() const;
|
const std::vector<font> &get_fonts() const;
|
||||||
std::vector<number_format> get_number_formats() const;
|
const std::vector<number_format> &get_number_formats() const;
|
||||||
|
|
||||||
std::size_t add_indexed_color(const std::string &rgb);
|
color add_indexed_color(const color &rgb_color);
|
||||||
std::string get_indexed_color(std::size_t color_index) const;
|
color get_indexed_color(const color &indexed_color) const;
|
||||||
|
|
||||||
const number_format &get_number_format(std::size_t style_id) const;
|
const number_format &get_number_format(std::size_t style_id) const;
|
||||||
std::size_t set_number_format(const number_format &format, std::size_t style_id);
|
std::size_t set_number_format(const number_format &format, std::size_t style_id);
|
||||||
|
|
|
@ -3,6 +3,22 @@
|
||||||
|
|
||||||
#include <xlnt/common/datetime.hpp>
|
#include <xlnt/common/datetime.hpp>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
std::tm safe_localtime(std::time_t raw_time)
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
std::tm result;
|
||||||
|
localtime_s(&result, &raw_time);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
|
return *localtime(&raw_time);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
namespace xlnt {
|
namespace xlnt {
|
||||||
|
|
||||||
time time::from_number(long double raw_time)
|
time time::from_number(long double raw_time)
|
||||||
|
@ -163,15 +179,15 @@ std::string datetime::to_string(xlnt::calendar /*base_date*/) const
|
||||||
|
|
||||||
date date::today()
|
date date::today()
|
||||||
{
|
{
|
||||||
std::time_t raw_time = std::time(0);
|
std::tm now = safe_localtime(std::time(0));
|
||||||
std::tm now = *std::localtime(&raw_time);
|
|
||||||
return date(1900 + now.tm_year, now.tm_mon + 1, now.tm_mday);
|
return date(1900 + now.tm_year, now.tm_mon + 1, now.tm_mday);
|
||||||
}
|
}
|
||||||
|
|
||||||
datetime datetime::now()
|
datetime datetime::now()
|
||||||
{
|
{
|
||||||
std::time_t raw_time = std::time(0);
|
std::tm now = safe_localtime(std::time(0));
|
||||||
std::tm now = *std::localtime(&raw_time);
|
|
||||||
return datetime(1900 + now.tm_year, now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
|
return datetime(1900 + now.tm_year, now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#include <xlnt/serialization/comment_serializer.hpp>
|
#include <xlnt/serialization/comment_serializer.hpp>
|
||||||
|
|
||||||
namespace {
|
namespace xlnt {
|
||||||
|
|
||||||
|
comment_serializer::comment_serializer(worksheet sheet) : sheet_(sheet)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
|
|
@ -90,11 +90,10 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
||||||
|
|
||||||
if(archive.has_file(xlnt::constants::ArcSharedString()))
|
if(archive.has_file(xlnt::constants::ArcSharedString()))
|
||||||
{
|
{
|
||||||
xlnt::shared_strings_serializer shared_strings_serializer_;
|
|
||||||
std::vector<std::string> shared_strings;
|
std::vector<std::string> shared_strings;
|
||||||
xlnt::xml_document shared_strings_xml;
|
xlnt::xml_document shared_strings_xml;
|
||||||
shared_strings_xml.from_string(archive.read(xlnt::constants::ArcSharedString()));
|
shared_strings_xml.from_string(archive.read(xlnt::constants::ArcSharedString()));
|
||||||
shared_strings_serializer_.read_shared_strings(shared_strings_xml, shared_strings);
|
xlnt::shared_strings_serializer::read_shared_strings(shared_strings_xml, shared_strings);
|
||||||
|
|
||||||
for (auto shared_string : shared_strings)
|
for (auto shared_string : shared_strings)
|
||||||
{
|
{
|
||||||
|
@ -194,10 +193,8 @@ excel_serializer::excel_serializer(workbook &wb) : workbook_(wb)
|
||||||
|
|
||||||
void excel_serializer::write_data(bool /*as_template*/)
|
void excel_serializer::write_data(bool /*as_template*/)
|
||||||
{
|
{
|
||||||
relationship_serializer relationship_serializer_;
|
relationship_serializer::write_relationships(workbook_.get_root_relationships(), "", archive_);
|
||||||
|
relationship_serializer::write_relationships(workbook_.get_relationships(), constants::ArcWorkbook(), archive_);
|
||||||
relationship_serializer_.write_relationships(workbook_.get_root_relationships(), "", archive_);
|
|
||||||
relationship_serializer_.write_relationships(workbook_.get_relationships(), constants::ArcWorkbook(), archive_);
|
|
||||||
|
|
||||||
xml_document properties_app_xml;
|
xml_document properties_app_xml;
|
||||||
workbook_serializer workbook_serializer_(workbook_);
|
workbook_serializer workbook_serializer_(workbook_);
|
||||||
|
@ -207,10 +204,9 @@ void excel_serializer::write_data(bool /*as_template*/)
|
||||||
theme_serializer theme_serializer_;
|
theme_serializer theme_serializer_;
|
||||||
archive_.writestr(constants::ArcTheme(), theme_serializer_.write_theme(workbook_.get_loaded_theme()).to_string());
|
archive_.writestr(constants::ArcTheme(), theme_serializer_.write_theme(workbook_.get_loaded_theme()).to_string());
|
||||||
|
|
||||||
xlnt::shared_strings_serializer shared_strings_serializer_;
|
|
||||||
archive_.writestr(
|
archive_.writestr(
|
||||||
constants::ArcSharedString(),
|
constants::ArcSharedString(),
|
||||||
xml_serializer::serialize(shared_strings_serializer_.write_shared_strings(workbook_.get_shared_strings())));
|
xml_serializer::serialize(xlnt::shared_strings_serializer::write_shared_strings(workbook_.get_shared_strings())));
|
||||||
|
|
||||||
archive_.writestr(constants::ArcWorkbook(), xml_serializer::serialize(workbook_serializer_.write_workbook()));
|
archive_.writestr(constants::ArcWorkbook(), xml_serializer::serialize(workbook_serializer_.write_workbook()));
|
||||||
|
|
||||||
|
|
|
@ -626,6 +626,30 @@ std::size_t workbook::add_style(const xlnt::style &style_)
|
||||||
return d_->styles_.back().id_;
|
return d_->styles_.back().id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
color workbook::add_indexed_color(const color &rgb_color)
|
||||||
|
{
|
||||||
|
std::size_t index = 0;
|
||||||
|
|
||||||
|
for (auto &c : d_->colors_)
|
||||||
|
{
|
||||||
|
if (c.get_rgb_string() == rgb_color.get_rgb_string())
|
||||||
|
{
|
||||||
|
return color(color::type::indexed, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
d_->colors_.push_back(rgb_color);
|
||||||
|
|
||||||
|
return color(color::type::indexed, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
color workbook::get_indexed_color(const color &indexed_color) const
|
||||||
|
{
|
||||||
|
return d_->colors_.at(indexed_color.get_index());
|
||||||
|
}
|
||||||
|
|
||||||
const number_format &workbook::get_number_format(std::size_t style_id) const
|
const number_format &workbook::get_number_format(std::size_t style_id) const
|
||||||
{
|
{
|
||||||
auto number_format_id = d_->styles_[style_id].number_format_id_;
|
auto number_format_id = d_->styles_[style_id].number_format_id_;
|
||||||
|
@ -820,27 +844,27 @@ std::size_t workbook::set_number_format(const xlnt::number_format &format, std::
|
||||||
return new_style.id_;
|
return new_style.id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<style> workbook::get_styles() const
|
const std::vector<style> &workbook::get_styles() const
|
||||||
{
|
{
|
||||||
return d_->styles_;
|
return d_->styles_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<number_format> workbook::get_number_formats() const
|
const std::vector<number_format> &workbook::get_number_formats() const
|
||||||
{
|
{
|
||||||
return d_->number_formats_;
|
return d_->number_formats_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<font> workbook::get_fonts() const
|
const std::vector<font> &workbook::get_fonts() const
|
||||||
{
|
{
|
||||||
return d_->fonts_;
|
return d_->fonts_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<border> workbook::get_borders() const
|
const std::vector<border> &workbook::get_borders() const
|
||||||
{
|
{
|
||||||
return d_->borders_;
|
return d_->borders_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<fill> workbook::get_fills() const
|
const std::vector<fill> &workbook::get_fills() const
|
||||||
{
|
{
|
||||||
return d_->fills_;
|
return d_->fills_;
|
||||||
}
|
}
|
||||||
|
@ -850,12 +874,7 @@ void workbook::add_color(const color &rgb)
|
||||||
d_->colors_.push_back(rgb);
|
d_->colors_.push_back(rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string workbook::get_indexed_color(std::size_t color_index) const
|
const std::vector<color> &workbook::get_colors() const
|
||||||
{
|
|
||||||
return d_->colors_.at(color_index).get_rgb_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<color> workbook::get_colors() const
|
|
||||||
{
|
{
|
||||||
return d_->colors_;
|
return d_->colors_;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user