mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
fix windows errors
This commit is contained in:
parent
451abd1de6
commit
c9b6b9e473
2
cmake/clean → clean
Executable file → Normal file
2
cmake/clean → clean
Executable file → Normal file
|
@ -5,7 +5,7 @@ import shutil
|
|||
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
dirs = ['../bin', '../lib', '../build']
|
||||
dirs = ['./bin', './lib', './build']
|
||||
|
||||
for dir in dirs:
|
||||
if os.path.isdir(dir): shutil.rmtree(dir)
|
7
clean.bat
Normal file
7
clean.bat
Normal file
|
@ -0,0 +1,7 @@
|
|||
@echo off
|
||||
setlocal EnableDelayedExpansion
|
||||
for /f %%i in ('where python') DO (set PYTHON=%%i) & goto :done1
|
||||
:done1
|
||||
@where python3 > nul 2>&1 && for /f %%i in ('@where python3') DO (@set PYTHON=%%i) & goto :done2
|
||||
:done2
|
||||
!PYTHON! clean
|
|
@ -1,20 +1,24 @@
|
|||
cmake_minimum_required(VERSION 2.8.7)
|
||||
|
||||
if(NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
|
||||
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "No dev warnings")
|
||||
endif()
|
||||
|
||||
project(xlnt)
|
||||
|
||||
if(APPLE)
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10)
|
||||
endif(APPLE)
|
||||
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
|
||||
endif()
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
|
||||
endif()
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../lib)
|
||||
|
|
19
cmake/configure
vendored
19
cmake/configure
vendored
|
@ -1,19 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
if not os.path.isdir('../build'):
|
||||
os.mkdir('../build')
|
||||
|
||||
generator = 'Unix Makefiles'
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
generator = 'Unix Makefiles'
|
||||
elif sys.platform == 'win32':
|
||||
generator = 'Visual Studio 14 2015'
|
||||
|
||||
subprocess.call(['cmake3', '-G', generator, '../cmake'], cwd='../build')
|
0
cmake/generate-tests.sh → cmake/generate-tests
Executable file → Normal file
0
cmake/generate-tests.sh → cmake/generate-tests
Executable file → Normal file
2
cmake/generate-tests.bat
Normal file
2
cmake/generate-tests.bat
Normal file
|
@ -0,0 +1,2 @@
|
|||
cd %~dp0
|
||||
../third-party/cxxtest/bin/cxxtestgen --runner=ErrorPrinter -o ../tests/runner-autogen.cpp ../tests/*.hpp
|
|
@ -18,7 +18,7 @@ source_group(helpers FILES ${TEST_HELPERS_HEADERS} ${TEST_HELPERS_SOURCES})
|
|||
target_link_libraries(xlnt.test xlnt)
|
||||
|
||||
add_custom_target (generate-test-runner
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generate-tests.sh
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generate-tests
|
||||
COMMENT "Generating test runner tests/runner-autogen.cpp"
|
||||
)
|
||||
|
||||
|
|
41
configure
vendored
Normal file
41
configure
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def which(program):
|
||||
def is_exe(fpath):
|
||||
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
||||
|
||||
fpath, fname = os.path.split(program)
|
||||
if fpath:
|
||||
if is_exe(program):
|
||||
return program
|
||||
else:
|
||||
for path in os.environ["PATH"].split(os.pathsep):
|
||||
path = path.strip('"')
|
||||
exe_file = os.path.join(path, program)
|
||||
if is_exe(exe_file):
|
||||
return exe_file
|
||||
|
||||
return None
|
||||
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
if not os.path.isdir('./build'):
|
||||
os.mkdir('./build')
|
||||
|
||||
generator = 'Unix Makefiles'
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
generator = 'Unix Makefiles'
|
||||
elif sys.platform == 'win32':
|
||||
generator = 'Visual Studio 14 2015'
|
||||
|
||||
cmake = 'cmake'
|
||||
|
||||
if which('cmake3'):
|
||||
cmake = 'cmake3'
|
||||
|
||||
subprocess.call([cmake, '-G', generator, '../cmake'], cwd='./build')
|
7
configure.bat
Normal file
7
configure.bat
Normal file
|
@ -0,0 +1,7 @@
|
|||
@echo off
|
||||
setlocal EnableDelayedExpansion
|
||||
for /f %%i in ('where python') DO (set PYTHON=%%i) & goto :done1
|
||||
:done1
|
||||
@where python3 > nul 2>&1 && for /f %%i in ('@where python3') DO (@set PYTHON=%%i) & goto :done2
|
||||
:done2
|
||||
!PYTHON! configure
|
|
@ -83,7 +83,7 @@ class cell
|
|||
/// <summary>
|
||||
/// Return a map of error strings such as #DIV/0! and their associated indices.
|
||||
/// </summary>
|
||||
static const std::unordered_map<std::string, int> error_codes();
|
||||
static const std::unordered_map<std::string, int> &error_codes();
|
||||
|
||||
// TODO: Should it be possible to construct and use a cell without a parent worksheet?
|
||||
//(cont'd) If so, it would need to be responsible for allocating and deleting its PIMPL.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <algorithm>
|
||||
#include <locale>
|
||||
#include <cctype>
|
||||
#include <sstream>
|
||||
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
|
@ -763,7 +763,7 @@ std::string format_text(const std::string &text, const std::string &format)
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
const std::unordered_map<std::string, int> cell::error_codes()
|
||||
const std::unordered_map<std::string, int> &cell::error_codes()
|
||||
{
|
||||
static const std::unordered_map<std::string, int> codes = { { "#NULL!", 0 }, { "#DIV/0!", 1 }, { "#VALUE!", 2 },
|
||||
{ "#REF!", 3 }, { "#NAME?", 4 }, { "#NUM!", 5 },
|
||||
|
@ -910,7 +910,11 @@ template <>
|
|||
void cell::set_value(std::string s)
|
||||
{
|
||||
d_->set_string(s, get_parent().get_parent().get_guess_types());
|
||||
if(!s.empty()) get_parent().get_parent().add_shared_string(s);
|
||||
|
||||
if (get_data_type() == type::string && !s.empty())
|
||||
{
|
||||
get_parent().get_parent().add_shared_string(s);
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
|
|
|
@ -115,12 +115,14 @@ time::time(const std::string &time_string) : hour(0), minute(0), second(0), micr
|
|||
|
||||
long double time::to_number() const
|
||||
{
|
||||
std::size_t microseconds = static_cast<std::size_t>(microsecond);
|
||||
microseconds += static_cast<std::size_t>(second * 1e6);
|
||||
microseconds += static_cast<std::size_t>(minute * 1e6 * 60);
|
||||
microseconds += static_cast<std::size_t>(hour * 1e6 * 60 * 60);
|
||||
auto number = microseconds / (24.0L * 60 * 60 * 1e6L);
|
||||
number = std::floor(number * 1e11L + 0.5L) / 1e11L;
|
||||
std::uint64_t microseconds = static_cast<std::uint64_t>(microsecond);
|
||||
microseconds += static_cast<std::uint64_t>(second * 1e6);
|
||||
microseconds += static_cast<std::uint64_t>(minute * 1e6 * 60);
|
||||
auto microseconds_per_hour = static_cast<std::uint64_t>(1e6) * 60 * 60;
|
||||
microseconds += static_cast<std::uint64_t>(hour * microseconds_per_hour);
|
||||
auto number = microseconds / (24.0L * microseconds_per_hour);
|
||||
auto hundred_billion = static_cast<std::uint64_t>(1e9) * 100;
|
||||
number = std::floor(number * hundred_billion + 0.5L) / hundred_billion;
|
||||
return number;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,9 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
}
|
||||
|
||||
xlnt::manifest_serializer ms(wb.get_manifest());
|
||||
ms.read_manifest(xlnt::xml_serializer::deserialize(archive.read(xlnt::constants::ArcContentTypes)));
|
||||
xlnt::xml_document manifest_xml;
|
||||
manifest_xml.from_string(archive.read(xlnt::constants::ArcContentTypes));
|
||||
ms.read_manifest(manifest_xml);
|
||||
|
||||
if (ms.determine_document_type() != "excel")
|
||||
{
|
||||
|
@ -62,7 +64,9 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
if(archive.has_file(xlnt::constants::ArcCore))
|
||||
{
|
||||
xlnt::workbook_serializer workbook_serializer_(wb);
|
||||
workbook_serializer_.read_properties_core(xlnt::xml_serializer::deserialize(archive.read(xlnt::constants::ArcCore)));
|
||||
xlnt::xml_document core_properties_xml;
|
||||
core_properties_xml.from_string(archive.read(xlnt::constants::ArcCore));
|
||||
workbook_serializer_.read_properties_core(core_properties_xml);
|
||||
}
|
||||
|
||||
auto workbook_relationships =
|
||||
|
@ -73,7 +77,8 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
wb.create_relationship(relationship.get_id(), relationship.get_target_uri(), relationship.get_type());
|
||||
}
|
||||
|
||||
auto xml = xlnt::xml_serializer::deserialize(archive.read(xlnt::constants::ArcWorkbook));
|
||||
xlnt::xml_document xml;
|
||||
xml.from_string(archive.read(xlnt::constants::ArcWorkbook));
|
||||
|
||||
auto root_node = xml.get_child("workbook");
|
||||
|
||||
|
@ -87,8 +92,9 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
{
|
||||
xlnt::shared_strings_serializer shared_strings_serializer_;
|
||||
std::vector<std::string> shared_strings;
|
||||
shared_strings_serializer_.read_shared_strings(
|
||||
xlnt::xml_serializer::deserialize(archive.read(xlnt::constants::ArcSharedString)), shared_strings);
|
||||
xlnt::xml_document shared_strings_xml;
|
||||
shared_strings_xml.from_string(archive.read(xlnt::constants::ArcSharedString));
|
||||
shared_strings_serializer_.read_shared_strings(shared_strings_xml, shared_strings);
|
||||
|
||||
for (auto shared_string : shared_strings)
|
||||
{
|
||||
|
@ -97,7 +103,9 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
}
|
||||
|
||||
xlnt::style_serializer style_reader_(wb);
|
||||
style_reader_.read_stylesheet(xlnt::xml_serializer::deserialize(archive.read(xlnt::constants::ArcStyles)));
|
||||
xlnt::xml_document style_xml;
|
||||
style_xml.from_string(archive.read(xlnt::constants::ArcStyles));
|
||||
style_reader_.read_stylesheet(style_xml);
|
||||
|
||||
auto sheets_node = root_node.get_child("sheets");
|
||||
|
||||
|
@ -113,7 +121,9 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
if(sheet_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml") continue;
|
||||
|
||||
xlnt::worksheet_serializer worksheet_serializer(ws);
|
||||
worksheet_serializer.read_worksheet(xlnt::xml_serializer::deserialize(archive.read(ws_filename)));
|
||||
xlnt::xml_document worksheet_xml;
|
||||
worksheet_xml.from_string(archive.read(ws_filename));
|
||||
worksheet_serializer.read_worksheet(worksheet_xml);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -124,7 +125,7 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml)
|
|||
std::string type = has_type ? cell_node.get_attribute("t") : "";
|
||||
|
||||
bool has_style = cell_node.has_attribute("s");
|
||||
int style_id = has_style ? std::stoull(cell_node.get_attribute("s")) : 0;
|
||||
auto style_id = static_cast<std::size_t>(has_style ? std::stoull(cell_node.get_attribute("s")) : 0LL);
|
||||
|
||||
bool has_formula = cell_node.has_child("f");
|
||||
bool has_shared_formula = has_formula && cell_node.get_child("f").has_attribute("t") &&
|
||||
|
@ -145,7 +146,7 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml)
|
|||
}
|
||||
else if (has_type && type == "s" && !has_formula) // shared string
|
||||
{
|
||||
auto shared_string_index = std::stoull(value_string);
|
||||
auto shared_string_index = static_cast<std::size_t>(std::stoull(value_string));
|
||||
auto shared_string = shared_strings.at(shared_string_index);
|
||||
cell.set_value(shared_string);
|
||||
}
|
||||
|
@ -190,7 +191,7 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml)
|
|||
auto max = static_cast<column_t>(std::stoull(col_node.get_attribute("max")));
|
||||
auto width = std::stold(col_node.get_attribute("width"));
|
||||
bool custom = col_node.get_attribute("customWidth") == "1";
|
||||
auto column_style = col_node.has_attribute("style") ? std::stoull(col_node.get_attribute("style")) : 0;
|
||||
auto column_style = static_cast<std::size_t>(col_node.has_attribute("style") ? std::stoull(col_node.get_attribute("style")) : 0);
|
||||
|
||||
for (auto column = min; column <= max; column++)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <xlnt/serialization/xml_node.hpp>
|
||||
#include <xlnt/serialization/xml_serializer.hpp>
|
||||
|
||||
#include <detail/include_pugixml.hpp>
|
||||
#include <detail/xml_document_impl.hpp>
|
||||
#include <detail/xml_node_impl.hpp>
|
||||
|
||||
|
@ -16,6 +17,11 @@ xml_document::xml_document(const xml_document &other) : xml_document()
|
|||
d_->doc.append_copy(other.d_->doc.root());
|
||||
}
|
||||
|
||||
xml_document::xml_document(xml_document &&other)
|
||||
{
|
||||
std::swap(d_, other.d_);
|
||||
}
|
||||
|
||||
xml_document::~xml_document()
|
||||
{
|
||||
}
|
||||
|
@ -59,8 +65,7 @@ std::string xml_document::to_string() const
|
|||
|
||||
xml_document &xml_document::from_string(const std::string &xml_string)
|
||||
{
|
||||
auto doc = xml_serializer::deserialize(xml_string);
|
||||
std::swap(doc.d_, d_);
|
||||
d_->doc.load(xml_string.c_str());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -49,17 +49,21 @@ public:
|
|||
expected_contents = s.str();
|
||||
}
|
||||
|
||||
auto expected_xml = xlnt::xml_serializer::deserialize(expected_contents);
|
||||
|
||||
xlnt::xml_document expected_xml;
|
||||
expected_xml.from_string(expected_contents);
|
||||
|
||||
return compare_xml(expected_xml.get_root(), observed.get_root());
|
||||
}
|
||||
|
||||
static comparison_result compare_xml(const std::string &left_contents, const std::string &right_contents)
|
||||
{
|
||||
auto left_doc = xlnt::xml_serializer::deserialize(left_contents);
|
||||
auto right_doc = xlnt::xml_serializer::deserialize(right_contents);
|
||||
|
||||
return compare_xml(left_doc.get_root(), right_doc.get_root());
|
||||
xlnt::xml_document left_xml;
|
||||
left_xml.from_string(left_contents);
|
||||
|
||||
xlnt::xml_document right_xml;
|
||||
right_xml.from_string(right_contents);
|
||||
|
||||
return compare_xml(left_xml.get_root(), right_xml.get_root());
|
||||
}
|
||||
|
||||
static comparison_result compare_xml(const xlnt::xml_node &left, const xlnt::xml_node &right)
|
||||
|
|
|
@ -161,9 +161,7 @@ public:
|
|||
auto path = PathHelper::GetDataDirectory("/reader/date_1904.xlsx");
|
||||
|
||||
xlnt::workbook wb;
|
||||
xlnt::excel_serializer serializer(wb);
|
||||
|
||||
serializer.load_workbook(path);
|
||||
wb.load(path);
|
||||
|
||||
return wb;
|
||||
}
|
||||
|
@ -173,9 +171,7 @@ public:
|
|||
auto path = PathHelper::GetDataDirectory("/reader/date_1900.xlsx");
|
||||
|
||||
xlnt::workbook wb;
|
||||
xlnt::excel_serializer serializer(wb);
|
||||
|
||||
serializer.load_workbook(path);
|
||||
wb.load(path);
|
||||
|
||||
return wb;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user