mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
some changes
This commit is contained in:
parent
d1337c48e4
commit
26892bf42b
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "third-party/pugixml"]
|
||||
path = third-party/pugixml
|
||||
url = https://github.com/zeux/pugixml.git
|
|
@ -23,7 +23,8 @@ project "xlnt.test"
|
|||
"$(opc_prefix)/plib/config/msvc/plib/include",
|
||||
"$(opc_prefix)/third_party/libxml2-2.7.7/include",
|
||||
"$(cxxtest_prefix)",
|
||||
"../include"
|
||||
"../include",
|
||||
"../third-party/pugixml/src"
|
||||
}
|
||||
defines { "WIN32" }
|
||||
files {
|
||||
|
@ -39,7 +40,7 @@ project "xlnt.test"
|
|||
"xml",
|
||||
"zlib"
|
||||
}
|
||||
prebuildcommands { "cxxtestgen --runner=ParenPrinter -o ../../source/tests/runner-autogen.cpp ../../source/tests/packaging/*.h" }
|
||||
prebuildcommands { "cxxtestgen --runner=ParenPrinter -o ../../source/tests/runner-autogen.cpp ../../source/tests/*.h" }
|
||||
libdirs { "$(opc_prefix)/win32/x64/Debug" }
|
||||
flags {
|
||||
"Unicode",
|
||||
|
@ -63,13 +64,16 @@ project "xlnt"
|
|||
"$(opc_prefix)/config",
|
||||
"$(opc_prefix)/plib/config/msvc/plib/include",
|
||||
"$(opc_prefix)/third_party/libxml2-2.7.7/include",
|
||||
"../include/xlnt"
|
||||
"../include/xlnt",
|
||||
"../third-party/pugixml/src",
|
||||
"../source/"
|
||||
}
|
||||
defines { "WIN32" }
|
||||
files {
|
||||
"../source/**.cpp",
|
||||
"../source/**.h",
|
||||
"../include/**.h"
|
||||
"../include/**.h",
|
||||
"../third-party/pugixml/src/pugixml.cpp"
|
||||
}
|
||||
excludes {
|
||||
"../source/tests/**.cpp",
|
||||
|
|
|
@ -21,23 +21,69 @@ THE SOFTWARE.
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "variant.h"
|
||||
struct tm;
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class cell_impl;
|
||||
class style;
|
||||
class worksheet;
|
||||
struct cell_struct;
|
||||
|
||||
struct coordinate
|
||||
{
|
||||
std::string column;
|
||||
int row;
|
||||
};
|
||||
|
||||
class cell
|
||||
{
|
||||
public:
|
||||
cell();
|
||||
|
||||
variant &value();
|
||||
|
||||
private:
|
||||
std::shared_ptr<cell_impl> impl_;
|
||||
enum class type
|
||||
{
|
||||
null,
|
||||
numeric,
|
||||
string,
|
||||
date,
|
||||
formula,
|
||||
boolean,
|
||||
error
|
||||
};
|
||||
|
||||
static coordinate coordinate_from_string(const std::string &address);
|
||||
static int column_index_from_string(const std::string &column_string);
|
||||
static std::string get_column_letter(int column_index);
|
||||
static std::string absolute_coordinate(const std::string &absolute_address);
|
||||
|
||||
cell(const cell ©);
|
||||
cell(worksheet &ws, const std::string &column, int row);
|
||||
cell(worksheet &ws, const std::string &column, int row, const std::string &value);
|
||||
~cell();
|
||||
|
||||
cell &operator=(int value);
|
||||
cell &operator=(double value);
|
||||
cell &operator=(const std::string &value);
|
||||
cell &operator=(const char *value);
|
||||
cell &operator=(const tm &value);
|
||||
|
||||
friend bool operator==(const std::string &comparand, const cell &cell);
|
||||
friend bool operator==(const char *comparand, const cell &cell);
|
||||
friend bool operator==(const tm &comparand, const cell &cell);
|
||||
|
||||
std::string to_string() const;
|
||||
bool is_date() const;
|
||||
style &get_style();
|
||||
type get_data_type();
|
||||
|
||||
private:
|
||||
cell_struct *root_;
|
||||
};
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &stream, const cell &cell)
|
||||
{
|
||||
return stream << cell.to_string();
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
30
include/xlnt/chart.h
Normal file
30
include/xlnt/chart.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright (c) 2012-2014 Thomas Fussell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class style
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
0
include/xlnt/date_time.h
Normal file
0
include/xlnt/date_time.h
Normal file
30
include/xlnt/drawing.h
Normal file
30
include/xlnt/drawing.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright (c) 2012-2014 Thomas Fussell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class style
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
0
include/xlnt/exceptions.h
Normal file
0
include/xlnt/exceptions.h
Normal file
|
@ -1,148 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
/// <summary>
|
||||
/// Provides attributes for files and directories.
|
||||
/// </summary>
|
||||
enum class file_attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// The file is a candidate for backup or removal.
|
||||
/// </summary>
|
||||
Archive,
|
||||
/// <summary>
|
||||
/// The file is compressed.
|
||||
/// </summary>
|
||||
Compressed,
|
||||
/// <summary>
|
||||
/// Reserved for future use.
|
||||
/// </summary>
|
||||
Device,
|
||||
/// <summary>
|
||||
/// The file is a directory.
|
||||
/// </summary>
|
||||
Directory,
|
||||
/// <summary>
|
||||
/// The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and directories.
|
||||
/// </summary>
|
||||
Encrypted,
|
||||
/// <summary>
|
||||
/// The file is hidden, and thus is not included in an ordinary directory listing.
|
||||
/// </summary>
|
||||
Hidden,
|
||||
/// <summary>
|
||||
/// The file or directory includes data integrity support. When this value is applied to a file, all data streams in the file have integrity support. When this value is applied to a directory, all new files and subdirectories within that directory, by default, include integrity support.
|
||||
/// </summary>
|
||||
IntegrityStream,
|
||||
/// <summary>
|
||||
/// The file is a standard file that has no special attributes. This attribute is valid only if it is used alone.
|
||||
/// </summary>
|
||||
Normal,
|
||||
/// <summary>
|
||||
/// The file or directory is excluded from the data integrity scan. When this value is applied to a directory, by default, all new files and subdirectories within that directory are excluded from data integrity.
|
||||
/// </summary>
|
||||
NoScrubData,
|
||||
/// <summary>
|
||||
/// The file will not be indexed by the operating system's content indexing service.
|
||||
/// </summary>
|
||||
NotContentIndexed,
|
||||
/// <summary>
|
||||
/// The file is offline. The data of the file is not immediately available.
|
||||
/// </summary>
|
||||
Offline,
|
||||
/// <summary>
|
||||
/// The file is read-only.
|
||||
/// </summary>
|
||||
ReadOnly,
|
||||
/// <summary>
|
||||
/// The file contains a reparse point, which is a block of user-defined data associated with a file or a directory.
|
||||
/// </summary>
|
||||
ReparsePoint,
|
||||
/// <summary>
|
||||
/// The file is a sparse file. Sparse files are typically large files whose data consists of mostly zeros.
|
||||
/// </summary>
|
||||
SparseFile,
|
||||
/// <summary>
|
||||
/// The file is a system file. That is, the file is part of the operating system or is used exclusively by the operating system.
|
||||
/// </summary>
|
||||
System,
|
||||
/// <summary>
|
||||
/// The file is temporary. A temporary file contains data that is needed while an application is executing but is not needed after the application is finished. File systems try to keep all the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.
|
||||
/// </summary>
|
||||
Temporary
|
||||
};
|
||||
|
||||
class file_info
|
||||
{
|
||||
public:
|
||||
file_info(const std::string &fileName);
|
||||
|
||||
file_attributes get_attributes() const { return attributes_; }
|
||||
void set_attributes(file_attributes attributes) { attributes_ = attributes; }
|
||||
|
||||
tm get_creation_time() const { return creationTime_; }
|
||||
void set_creation_time(const tm &creationTime) { creationTime_ = creationTime; }
|
||||
|
||||
tm get_creation_time_utc() const { return time_to_utc(creationTime_); }
|
||||
void set_creation_time_utc(const tm &creationTime) { creationTime_ = time_from_utc(creationTime); }
|
||||
|
||||
std::string get_directory_name() const { return directoryName_; }
|
||||
|
||||
bool exists() const;
|
||||
|
||||
std::string get_extension() const { return split_extension(fullName_).second; }
|
||||
|
||||
std::string get_full_name() const { return fullName_; }
|
||||
|
||||
bool IsReadOnly() const { return readOnly_; }
|
||||
void set_ReadOnly(bool readOnly) { readOnly_ = readOnly; }
|
||||
|
||||
tm get_LastAccessTime() const { return creationTime_; }
|
||||
void set_LastAccessTime(const tm &creationTime) { creationTime_ = creationTime; }
|
||||
|
||||
tm get_LastAccessUtc() const { return time_to_utc(creationTime_); }
|
||||
void set_LastAccessUtc(const tm &creationTime) { creationTime_ = time_from_utc(creationTime); }
|
||||
|
||||
tm get_LastWriteTime() const { return creationTime_; }
|
||||
void set_LastWriteTime(const tm &creationTime) { creationTime_ = creationTime; }
|
||||
|
||||
tm get_LastWriteTimeUtc() const { return time_to_utc(creationTime_); }
|
||||
void set_LastWriteTimeUtc(const tm &creationTime) { creationTime_ = time_from_utc(creationTime); }
|
||||
|
||||
void delete_();
|
||||
void encrypt();
|
||||
void move_to();
|
||||
void open();
|
||||
void open_read();
|
||||
void open_text();
|
||||
void open_write();
|
||||
void refresh();
|
||||
void replace(const std::string &, const std::string &);
|
||||
void replace(const std::string &, const std::string &, bool);
|
||||
void set_access_control();
|
||||
std::string to_string();
|
||||
|
||||
private:
|
||||
static tm time_to_utc(const tm &time);
|
||||
static tm time_from_utc(const tm &time);
|
||||
static std::pair<std::string, std::string> split_extension(const std::string &name);
|
||||
|
||||
file_attributes attributes_;
|
||||
tm creationTime_;
|
||||
std::string directoryName_;
|
||||
bool exists_;
|
||||
std::string fullName_;
|
||||
bool readOnly_;
|
||||
tm lastAccessTime_;
|
||||
tm lastWriteTime_;
|
||||
int length_;
|
||||
|
||||
std::string path_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
30
include/xlnt/namedrange.h
Normal file
30
include/xlnt/namedrange.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright (c) 2012-2014 Thomas Fussell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class style
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
30
include/xlnt/strings.h
Normal file
30
include/xlnt/strings.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright (c) 2012-2014 Thomas Fussell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class style
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
0
include/xlnt/theme.h
Normal file
0
include/xlnt/theme.h
Normal file
|
@ -1,356 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2012-2014 Thomas Fussell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/** @file variant.h
|
||||
* @brief A dynamic container holding one of the seven JSON primitives.
|
||||
*
|
||||
* Declaration of variant class which represents a dynamic type. It can be assigned any
|
||||
* one of the following value types as defined in RFC 4627: false, null, true,
|
||||
* object, array, number, string.
|
||||
*
|
||||
* @author Thomas A. Fussell (tfussell)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
/**
|
||||
* A dynamic type exception may be raised when an operation is attempted
|
||||
* on a dynamic type which does not support it. For example, trying to
|
||||
* index an integer type.
|
||||
*/
|
||||
class dynamic_type_exception : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
dynamic_type_exception() : std::runtime_error("Error: wrong type")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Must be forward declared so that object and array can store pointers to this
|
||||
* heretofore incomplete type.
|
||||
*/
|
||||
class variant;
|
||||
|
||||
/**
|
||||
* A variant class can be dynamically assigned to one of the following: null, true,
|
||||
* false, number, string.
|
||||
*
|
||||
* Note: This class uses a long double to store its dynamic number values. This
|
||||
* is consistent with JavaScript's number type, but it may limit the precision
|
||||
* on very large or very small numbers and introduce rounding errors.
|
||||
*/
|
||||
class variant
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* An enumeration of possible dynamic types that the containing class may assume.
|
||||
*/
|
||||
enum Type
|
||||
{
|
||||
T_Null, /**< null */
|
||||
T_True, /**< true */
|
||||
T_False, /**< false */
|
||||
T_Number, /**< number */
|
||||
T_String, /**< string */
|
||||
};
|
||||
|
||||
public:
|
||||
#pragma region Constructors
|
||||
/**
|
||||
* Constructs a new empty variant of null type.
|
||||
*/
|
||||
variant() : type_(T_Null) { }
|
||||
|
||||
/**
|
||||
* Constructs a new variant class of type T_True or T_False if the given paramter, b, is true or false respectively.
|
||||
*/
|
||||
variant(bool b) : type_(b ? T_True : T_False) { }
|
||||
|
||||
/**
|
||||
* Constructs a new variant class of type T_Number with a dynamic numeric value based on the given parameter, i.
|
||||
*/
|
||||
variant(int i) : type_(T_Number), number_(i) { }
|
||||
|
||||
/**
|
||||
* Constructs a new variant class of type T_Number with a dynamic numeric value based on the given parameter, i.
|
||||
*/
|
||||
variant(long long i) : type_(T_Number), number_(static_cast<long double>(i)) { }
|
||||
|
||||
/**
|
||||
* Constructs a new variant class of type T_Number with a dynamic numeric value based on the given parameter, d.
|
||||
*/
|
||||
variant(double d) : type_(T_Number), number_(d) { }
|
||||
|
||||
/**
|
||||
* Constructs a new variant class of type T_Number with a dynamic numeric value based on the given parameter, d.
|
||||
*/
|
||||
variant(long double d) : type_(T_Number), number_(d) { }
|
||||
|
||||
/**
|
||||
* Constructs a new variant class of type T_String with a dynamic string value based on the given parameter, s.
|
||||
*/
|
||||
variant(const char *s) : type_(T_String), string_(s) { }
|
||||
|
||||
/**
|
||||
* Constructs a new variant class of type T_String with a dynamic string value based on the given parameter, s.
|
||||
*/
|
||||
variant(const std::string &s) : type_(T_String), string_(s) { }
|
||||
|
||||
/**
|
||||
* Constructs a new variant as a deep-copy of an existing object.
|
||||
*/
|
||||
variant(const variant &v) { *this = v; }
|
||||
|
||||
/**
|
||||
* If this is a container type, destroys contents and clears the container.
|
||||
*/
|
||||
~variant();
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Operators
|
||||
/**
|
||||
* Assigns the fields of this object to those of the given parameter, rhs, by creating a deep-copy of containers.
|
||||
*/
|
||||
variant &operator=(const variant &rhs);
|
||||
|
||||
/**
|
||||
* Returns true if the types of this object and the given parameter, rhs, are equal and checks the corresponding
|
||||
* field for equality. For container types, this recursively checks for element-by-element equality in the same
|
||||
* way.
|
||||
*/
|
||||
bool operator==(const variant &rhs) const;
|
||||
|
||||
/**
|
||||
* Returns the negation of the result of the equality operator.
|
||||
*/
|
||||
bool operator!=(const variant &rhs) const { return !(*this == rhs); }
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Casts
|
||||
template <class T> T cast() const;
|
||||
|
||||
template <>
|
||||
bool variant::cast() const
|
||||
{
|
||||
if(type_ == T_True)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if(type_ == T_False)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
throw dynamic_type_exception();
|
||||
}
|
||||
|
||||
template <>
|
||||
int variant::cast() const
|
||||
{
|
||||
if(type_ == T_Number)
|
||||
{
|
||||
return static_cast<int>(number_);
|
||||
}
|
||||
|
||||
throw dynamic_type_exception();
|
||||
}
|
||||
|
||||
template <>
|
||||
double variant::cast() const
|
||||
{
|
||||
if(type_ == T_Number)
|
||||
{
|
||||
return static_cast<double>(number_);
|
||||
}
|
||||
|
||||
throw dynamic_type_exception();
|
||||
}
|
||||
|
||||
template <>
|
||||
long long variant::cast() const
|
||||
{
|
||||
if(type_ == T_Number)
|
||||
{
|
||||
return static_cast<long long>(number_);
|
||||
}
|
||||
|
||||
throw dynamic_type_exception();
|
||||
}
|
||||
|
||||
template <>
|
||||
long double variant::cast() const
|
||||
{
|
||||
if(type_ == T_Number)
|
||||
{
|
||||
return number_;
|
||||
}
|
||||
|
||||
throw dynamic_type_exception();
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string variant::cast() const
|
||||
{
|
||||
if(type_ == T_String)
|
||||
{
|
||||
return string_;
|
||||
}
|
||||
|
||||
throw dynamic_type_exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* See: bool ToBool() const
|
||||
*/
|
||||
operator bool() const { return cast<bool>(); }
|
||||
|
||||
/**
|
||||
* See: int ToInt() const
|
||||
*/
|
||||
operator int() const { return cast<int>(); }
|
||||
|
||||
/**
|
||||
* See: double ToDouble() const
|
||||
*/
|
||||
operator double() const { return cast<double>(); }
|
||||
|
||||
/**
|
||||
* See: long long ToLongLong() const
|
||||
*/
|
||||
operator long long() const { return cast<long long>(); }
|
||||
|
||||
/**
|
||||
* See: long double ToLongDouble() const
|
||||
*/
|
||||
operator long double() const { return cast<long double>(); }
|
||||
|
||||
/**
|
||||
* See: std::string ToString() const
|
||||
*/
|
||||
operator std::string() const { return cast<std::string>(); }
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Type checks
|
||||
|
||||
/**
|
||||
* Returns true if the type of this object is T_Null.
|
||||
*/
|
||||
bool isnull() const { return type_ == T_Null; }
|
||||
|
||||
/**
|
||||
* Returns true if the type of this object is T_True.
|
||||
*/
|
||||
bool istrue() const { return type_ == T_True; }
|
||||
|
||||
/**
|
||||
* Returns true if the type of this object is T_False.
|
||||
*/
|
||||
bool isfalse() const { return type_ == T_False; }
|
||||
|
||||
/**
|
||||
* Returns true if the type of this object is T_True or T_False.
|
||||
*/
|
||||
bool isboolean() const { return istrue() || isfalse(); }
|
||||
|
||||
/**
|
||||
* Returns true if the type of this object is T_Number.
|
||||
*/
|
||||
bool isnumber() const { return type_ == T_Number; }
|
||||
|
||||
/**
|
||||
* Returns true if the type of this object is T_Number and number has no decimal part.
|
||||
*/
|
||||
bool isint() const { return isnumber() && !isfloat(); }
|
||||
|
||||
/**
|
||||
* Returns true if the type of this object is T_Number and number has a decimal part.
|
||||
*/
|
||||
bool isfloat() const { return isnumber() && ceil(number_) != number_; }
|
||||
|
||||
/**
|
||||
* Returns true if the type of this object is T_String.
|
||||
*/
|
||||
bool isstring() const { return type_ == T_String; }
|
||||
|
||||
#pragma endregion
|
||||
|
||||
private:
|
||||
/**
|
||||
* Constructs a new variant of the given type with an optional parameter indicating whether this
|
||||
* variant preserves order (only relevant if it is of type T_Object).
|
||||
*/
|
||||
variant(Type type) : type_(type) { }
|
||||
|
||||
/**
|
||||
* Attempts to convert the current value of this object to a bool.
|
||||
* This will raise an error if the internal type is not T_True or T_False.
|
||||
*/
|
||||
bool asbool() const;
|
||||
|
||||
/*
|
||||
* Attempts to convert the current value of this object to an int.
|
||||
* This will raise an error if the internal type is not T_Number.
|
||||
* This conversion may overflow.
|
||||
*/
|
||||
int asint() const;
|
||||
|
||||
/*
|
||||
* Attempts to convert the current value of this object to a double.
|
||||
* This will raise an error if the internal type is not T_Number.
|
||||
* This conversion may overflow.
|
||||
*/
|
||||
double asdouble() const;
|
||||
|
||||
/*
|
||||
* Attempts to convert the current value of this object to a long long int.
|
||||
* This will raise an error if the internal type is not T_Number.
|
||||
*/
|
||||
long long aslonglong() const;
|
||||
|
||||
/*
|
||||
* Attempts to convert the current value of this object to a long double.
|
||||
* This will raise an error if the internal type is not T_Number.
|
||||
*/
|
||||
long double aslongdouble() const;
|
||||
|
||||
/*
|
||||
* Attempts to convert the current value of this object to a string.
|
||||
* This will raise an error if the internal type is not T_String.
|
||||
*/
|
||||
std::string asstring() const;
|
||||
|
||||
Type type_; /**< Dynamic type of the contained value. */
|
||||
|
||||
long double number_; /**< Holder for numeric value if this has type T_Number */
|
||||
std::string string_; /**< Holder for string value if this has type T_String */
|
||||
};
|
||||
|
||||
extern const variant $; /**< Special variant which represents null JSON literal */
|
||||
|
||||
} // namespace xlnt
|
|
@ -23,29 +23,32 @@ THE SOFTWARE.
|
|||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class workbook_impl;
|
||||
struct workbook_struct;
|
||||
class worksheet;
|
||||
|
||||
class workbook
|
||||
{
|
||||
public:
|
||||
workbook();
|
||||
workbook(const workbook &) = delete;
|
||||
const workbook &operator=(const workbook &) = delete;
|
||||
|
||||
worksheet &get_sheet_by_name(const std::string &sheet_name);
|
||||
worksheet &get_active();
|
||||
worksheet &create_sheet();
|
||||
worksheet &create_sheet(std::size_t index);
|
||||
worksheet get_sheet_by_name(const std::string &sheet_name);
|
||||
worksheet get_active();
|
||||
worksheet create_sheet();
|
||||
worksheet create_sheet(std::size_t index);
|
||||
std::vector<std::string> get_sheet_names() const;
|
||||
std::vector<worksheet>::iterator begin();
|
||||
std::vector<worksheet>::iterator end();
|
||||
worksheet &operator[](const std::string &name);
|
||||
worksheet operator[](const std::string &name);
|
||||
void save(const std::string &filename);
|
||||
|
||||
private:
|
||||
std::shared_ptr<workbook_impl> impl_;
|
||||
workbook_struct *root_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -21,18 +21,18 @@ THE SOFTWARE.
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cell.h"
|
||||
#include "relationship.h"
|
||||
#include "workbook.h"
|
||||
#include <unordered_map>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class worksheet_impl;
|
||||
class cell;
|
||||
class relationship;
|
||||
class workbook;
|
||||
struct worksheet_struct;
|
||||
|
||||
typedef std::vector<std::vector<cell>> range;
|
||||
|
||||
class worksheet
|
||||
|
@ -77,7 +77,7 @@ public:
|
|||
void operator=(const worksheet &other);
|
||||
cell operator[](const std::string &address);
|
||||
std::string to_string() const;
|
||||
workbook get_parent() const;
|
||||
workbook &get_parent() const;
|
||||
void garbage_collect();
|
||||
std::set<cell> get_cell_collection();
|
||||
std::string get_title() const;
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
int get_highest_column() const;
|
||||
std::string calculate_dimension() const;
|
||||
range range(const std::string &range_string, int row_offset, int column_offset);
|
||||
relationship create_relationship(relationship::type relationship_type);
|
||||
relationship create_relationship(const std::string &relationship_type);
|
||||
//void add_chart(chart chart);
|
||||
void merge_cells(const std::string &range_string);
|
||||
void merge_cells(int start_row, int start_column, int end_row, int end_column);
|
||||
|
@ -106,7 +106,7 @@ public:
|
|||
bool operator==(const worksheet &other);
|
||||
|
||||
private:
|
||||
std::shared_ptr<worksheet_impl> impl_;
|
||||
worksheet_struct *root_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
156
source/excel/cell.cpp
Normal file
156
source/excel/cell.cpp
Normal file
|
@ -0,0 +1,156 @@
|
|||
#include <ctime>
|
||||
|
||||
#include "cell.h"
|
||||
#include "worksheet.h"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
struct cell_struct
|
||||
{
|
||||
cell_struct() : type(cell::type::null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cell_struct(worksheet *ws, const std::string &column, int row)
|
||||
: type(cell::type::null), parent_worksheet(ws),
|
||||
column(xlnt::cell::column_index_from_string(column) - 1), row(row)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case cell::type::numeric: return std::to_string(numeric_value);
|
||||
case cell::type::boolean: return bool_value ? "true" : "false";
|
||||
case cell::type::string: return string_value;
|
||||
default: throw std::runtime_error("bad enum");
|
||||
}
|
||||
}
|
||||
|
||||
cell::type type;
|
||||
|
||||
union
|
||||
{
|
||||
long double numeric_value;
|
||||
bool bool_value;
|
||||
};
|
||||
|
||||
tm date_value;
|
||||
std::string string_value;
|
||||
worksheet *parent_worksheet;
|
||||
int column;
|
||||
int row;
|
||||
};
|
||||
|
||||
cell::cell(const cell ©)
|
||||
{
|
||||
root_ = copy.root_;
|
||||
}
|
||||
|
||||
coordinate cell::coordinate_from_string(const std::string &address)
|
||||
{
|
||||
if(address == "A1")
|
||||
{
|
||||
return {"A", 1};
|
||||
}
|
||||
|
||||
return {"A", 1};
|
||||
}
|
||||
|
||||
int cell::column_index_from_string(const std::string &column_string)
|
||||
{
|
||||
return column_string[0] - 'A';
|
||||
}
|
||||
|
||||
std::string cell::get_column_letter(int column_index)
|
||||
{
|
||||
return std::string(1, (char)('A' + column_index - 1));
|
||||
}
|
||||
|
||||
bool cell::is_date() const
|
||||
{
|
||||
return root_->type == type::date;
|
||||
}
|
||||
|
||||
bool operator==(const char *comparand, const cell &cell)
|
||||
{
|
||||
return std::string(comparand) == cell;
|
||||
}
|
||||
|
||||
bool operator==(const std::string &comparand, const cell &cell)
|
||||
{
|
||||
return cell.root_->type == cell::type::string && cell.root_->string_value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(const tm &comparand, const cell &cell)
|
||||
{
|
||||
return cell.root_->type == cell::type::date && cell.root_->date_value.tm_hour == comparand.tm_hour;
|
||||
}
|
||||
|
||||
std::string cell::absolute_coordinate(const std::string &absolute_address)
|
||||
{
|
||||
return absolute_address;
|
||||
}
|
||||
|
||||
cell::cell(worksheet &ws, const std::string &column, int row) : root_(new cell_struct(&ws, column, row))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cell::cell(worksheet &ws, const std::string &column, int row, const std::string &value) : root_(new cell_struct(&ws, column, row))
|
||||
{
|
||||
*this = value;
|
||||
}
|
||||
|
||||
cell::type cell::get_data_type()
|
||||
{
|
||||
return root_->type;
|
||||
}
|
||||
|
||||
cell &cell::operator=(int value)
|
||||
{
|
||||
root_->type = type::numeric;
|
||||
root_->numeric_value = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
cell &cell::operator=(double value)
|
||||
{
|
||||
root_->type = type::numeric;
|
||||
root_->numeric_value = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
cell &cell::operator=(const std::string &value)
|
||||
{
|
||||
root_->type = type::string;
|
||||
root_->string_value = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
cell &cell::operator=(const char *value)
|
||||
{
|
||||
return *this = std::string(value);
|
||||
}
|
||||
|
||||
cell &cell::operator=(const tm &value)
|
||||
{
|
||||
root_->type = type::date;
|
||||
root_->date_value = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
cell::~cell()
|
||||
{
|
||||
delete root_;
|
||||
}
|
||||
|
||||
std::string cell::to_string() const
|
||||
{
|
||||
return root_->to_string();
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
|
@ -3,27 +3,26 @@
|
|||
#include <unordered_map>
|
||||
|
||||
#include "workbook.h"
|
||||
#include "package.h"
|
||||
#include "worksheet.h"
|
||||
#include "packaging/package.h"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class workbook_impl
|
||||
struct workbook_struct
|
||||
{
|
||||
public:
|
||||
workbook_impl(workbook *parent) : parent_(parent)
|
||||
workbook_struct(workbook *parent) : parent_(parent)
|
||||
{
|
||||
worksheets_.emplace_back(*parent, "Sheet1");
|
||||
active_name_ = "Sheet1";
|
||||
}
|
||||
|
||||
worksheet &get_sheet_by_name(const std::string &name)
|
||||
worksheet get_sheet_by_name(const std::string &name)
|
||||
{
|
||||
auto match = std::find_if(worksheets_.begin(), worksheets_.end(), [=](const worksheet &w) { return w.get_title() == name; });
|
||||
return *match;
|
||||
}
|
||||
|
||||
worksheet &get_active()
|
||||
worksheet get_active()
|
||||
{
|
||||
return get_sheet_by_name(active_name_);
|
||||
}
|
||||
|
@ -48,14 +47,14 @@ public:
|
|||
return names;
|
||||
}
|
||||
|
||||
worksheet &create_sheet()
|
||||
worksheet create_sheet()
|
||||
{
|
||||
worksheets_.emplace_back(*parent_, "Sheet");
|
||||
worksheets_.back().set_title("Sheet" + std::to_string(worksheets_.size()));
|
||||
return worksheets_.back();
|
||||
}
|
||||
|
||||
worksheet &create_sheet(std::size_t index)
|
||||
worksheet create_sheet(std::size_t index)
|
||||
{
|
||||
worksheets_.emplace(worksheets_.begin() + index, *parent_, "Sheet");
|
||||
worksheets_[index].set_title("Sheet" + std::to_string(worksheets_.size()));
|
||||
|
@ -73,60 +72,58 @@ public:
|
|||
workbook *parent_;
|
||||
};
|
||||
|
||||
workbook::workbook() : impl_(nullptr)
|
||||
workbook::workbook() : root_(new workbook_struct(this))
|
||||
{
|
||||
auto new_impl = std::make_shared<workbook_impl>(this);
|
||||
impl_.swap(new_impl);
|
||||
}
|
||||
|
||||
worksheet &workbook::get_sheet_by_name(const std::string &name)
|
||||
worksheet workbook::get_sheet_by_name(const std::string &name)
|
||||
{
|
||||
if(impl_ == nullptr)
|
||||
if(root_ == nullptr)
|
||||
{
|
||||
throw std::runtime_error("workbook not initialized");
|
||||
}
|
||||
|
||||
return impl_->get_sheet_by_name(name);
|
||||
return root_->get_sheet_by_name(name);
|
||||
}
|
||||
|
||||
worksheet &workbook::get_active()
|
||||
worksheet workbook::get_active()
|
||||
{
|
||||
return impl_->get_active();
|
||||
return root_->get_active();
|
||||
}
|
||||
|
||||
worksheet &workbook::create_sheet()
|
||||
worksheet workbook::create_sheet()
|
||||
{
|
||||
return impl_->create_sheet();
|
||||
return root_->create_sheet();
|
||||
}
|
||||
|
||||
worksheet &workbook::create_sheet(std::size_t index)
|
||||
worksheet workbook::create_sheet(std::size_t index)
|
||||
{
|
||||
return impl_->create_sheet(index);
|
||||
return root_->create_sheet(index);
|
||||
}
|
||||
|
||||
std::vector<worksheet>::iterator workbook::begin()
|
||||
{
|
||||
return impl_->begin();
|
||||
return root_->begin();
|
||||
}
|
||||
|
||||
std::vector<worksheet>::iterator workbook::end()
|
||||
{
|
||||
return impl_->end();
|
||||
return root_->end();
|
||||
}
|
||||
|
||||
std::vector<std::string> workbook::get_sheet_names() const
|
||||
{
|
||||
return impl_->get_sheet_names();
|
||||
return root_->get_sheet_names();
|
||||
}
|
||||
|
||||
worksheet &workbook::operator[](const std::string &name)
|
||||
worksheet workbook::operator[](const std::string &name)
|
||||
{
|
||||
return get_sheet_by_name(name);
|
||||
}
|
||||
|
||||
void workbook::save(const std::string &filename)
|
||||
{
|
||||
impl_->save(filename);
|
||||
root_->save(filename);
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
|
@ -1,4 +1,9 @@
|
|||
#include <unordered_map>
|
||||
|
||||
#include "worksheet.h"
|
||||
#include "workbook.h"
|
||||
#include "cell.h"
|
||||
#include "packaging/relationship.h"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -50,11 +55,10 @@ std::string get_column_letter(int column_index)
|
|||
|
||||
}
|
||||
|
||||
class worksheet_impl
|
||||
struct worksheet_struct
|
||||
{
|
||||
public:
|
||||
worksheet_impl(workbook &parent_workbook, const std::string &title)
|
||||
: parent_(parent_workbook), title_(title)
|
||||
worksheet_struct(workbook &parent_workbook, worksheet &owner, const std::string &title)
|
||||
: parent_(parent_workbook), title_(title), freeze_panes_(owner, "A", 1), owner_(owner)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -101,7 +105,14 @@ public:
|
|||
|
||||
xlnt::cell cell(const std::string &coordinate)
|
||||
{
|
||||
return cells_[coordinate];
|
||||
if(cell_map_.find(coordinate) == cell_map_.end())
|
||||
{
|
||||
auto coord = xlnt::cell::coordinate_from_string(coordinate);
|
||||
cells_.emplace_back(owner_, coord.column, coord.row);
|
||||
cell_map_[coordinate] = &cells_.back();
|
||||
}
|
||||
|
||||
return *cell_map_[coordinate];
|
||||
}
|
||||
|
||||
xlnt::cell cell(int row, int column)
|
||||
|
@ -140,7 +151,7 @@ public:
|
|||
throw not_implemented();
|
||||
}
|
||||
|
||||
relationship create_relationship(relationship::type relationship_type)
|
||||
relationship create_relationship(const std::string &relationship_type)
|
||||
{
|
||||
relationships_.push_back(relationship(relationship_type));
|
||||
return relationships_.back();
|
||||
|
@ -172,7 +183,7 @@ public:
|
|||
{
|
||||
for(auto cell : cells)
|
||||
{
|
||||
cells_["a"] = cell;
|
||||
*cell_map_["a"] = cell;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +191,7 @@ public:
|
|||
{
|
||||
for(auto cell : cells)
|
||||
{
|
||||
cells_[cell.first] = cell.second;
|
||||
*cell_map_[cell.first] = cell.second;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +199,7 @@ public:
|
|||
{
|
||||
for(auto cell : cells)
|
||||
{
|
||||
cells_[get_column_letter(cell.first + 1)] = cell.second;
|
||||
*cell_map_[get_column_letter(cell.first + 1)] = cell.second;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,161 +213,163 @@ public:
|
|||
throw not_implemented();
|
||||
}
|
||||
|
||||
void operator=(const worksheet_impl &other) = delete;
|
||||
void operator=(const worksheet_struct &other) = delete;
|
||||
|
||||
workbook &parent_;
|
||||
std::string title_;
|
||||
xlnt::cell freeze_panes_;
|
||||
std::unordered_map<std::string, xlnt::cell> cells_;
|
||||
std::vector<xlnt::cell> cells_;
|
||||
std::unordered_map<std::string, xlnt::cell *> cell_map_;
|
||||
std::vector<relationship> relationships_;
|
||||
worksheet &owner_;
|
||||
};
|
||||
|
||||
worksheet::worksheet(workbook &parent_workbook, const std::string &title)
|
||||
: impl_(std::make_shared<worksheet_impl>(parent_workbook, title))
|
||||
: root_(nullptr)
|
||||
{
|
||||
|
||||
root_ = new worksheet_struct(parent_workbook, *this, title);
|
||||
}
|
||||
|
||||
std::string worksheet::to_string() const
|
||||
{
|
||||
return "<Worksheet \"" + impl_->title_ + "\">";
|
||||
return "<Worksheet \"" + root_->title_ + "\">";
|
||||
}
|
||||
|
||||
workbook worksheet::get_parent() const
|
||||
workbook &worksheet::get_parent() const
|
||||
{
|
||||
return impl_->parent_;
|
||||
return root_->parent_;
|
||||
}
|
||||
|
||||
void worksheet::garbage_collect()
|
||||
{
|
||||
impl_->garbage_collect();
|
||||
root_->garbage_collect();
|
||||
}
|
||||
|
||||
std::set<cell> worksheet::get_cell_collection()
|
||||
{
|
||||
return impl_->get_cell_collection();
|
||||
return root_->get_cell_collection();
|
||||
}
|
||||
|
||||
std::string worksheet::get_title() const
|
||||
{
|
||||
return impl_->title_;
|
||||
return root_->title_;
|
||||
}
|
||||
|
||||
void worksheet::set_title(const std::string &title)
|
||||
{
|
||||
impl_->title_ = title;
|
||||
root_->title_ = title;
|
||||
}
|
||||
|
||||
cell worksheet::get_freeze_panes() const
|
||||
{
|
||||
return impl_->freeze_panes_;
|
||||
return root_->freeze_panes_;
|
||||
}
|
||||
|
||||
void worksheet::set_freeze_panes(xlnt::cell top_left_cell)
|
||||
{
|
||||
impl_->set_freeze_panes(top_left_cell);
|
||||
root_->set_freeze_panes(top_left_cell);
|
||||
}
|
||||
|
||||
void worksheet::set_freeze_panes(const std::string &top_left_coordinate)
|
||||
{
|
||||
impl_->set_freeze_panes(top_left_coordinate);
|
||||
root_->set_freeze_panes(top_left_coordinate);
|
||||
}
|
||||
|
||||
void worksheet::unfreeze_panes()
|
||||
{
|
||||
impl_->unfreeze_panes();
|
||||
root_->unfreeze_panes();
|
||||
}
|
||||
|
||||
xlnt::cell worksheet::cell(const std::string &coordinate)
|
||||
{
|
||||
return impl_->cell(coordinate);
|
||||
return root_->cell(coordinate);
|
||||
}
|
||||
|
||||
xlnt::cell worksheet::cell(int row, int column)
|
||||
{
|
||||
return impl_->cell(row, column);
|
||||
return root_->cell(row, column);
|
||||
}
|
||||
|
||||
int worksheet::get_highest_row() const
|
||||
{
|
||||
return impl_->get_highest_row();
|
||||
return root_->get_highest_row();
|
||||
}
|
||||
|
||||
int worksheet::get_highest_column() const
|
||||
{
|
||||
return impl_->get_highest_column();
|
||||
return root_->get_highest_column();
|
||||
}
|
||||
|
||||
std::string worksheet::calculate_dimension() const
|
||||
{
|
||||
return impl_->calculate_dimension();
|
||||
return root_->calculate_dimension();
|
||||
}
|
||||
|
||||
range worksheet::range(const std::string &range_string, int row_offset, int column_offset)
|
||||
{
|
||||
return impl_->range(range_string, row_offset, column_offset);
|
||||
return root_->range(range_string, row_offset, column_offset);
|
||||
}
|
||||
|
||||
relationship worksheet::create_relationship(relationship::type relationship_type)
|
||||
relationship worksheet::create_relationship(const std::string &relationship_type)
|
||||
{
|
||||
return impl_->create_relationship(relationship_type);
|
||||
return root_->create_relationship(relationship_type);
|
||||
}
|
||||
|
||||
//void worksheet::add_chart(chart chart);
|
||||
|
||||
void worksheet::merge_cells(const std::string &range_string)
|
||||
{
|
||||
impl_->merge_cells(range_string);
|
||||
root_->merge_cells(range_string);
|
||||
}
|
||||
|
||||
void worksheet::merge_cells(int start_row, int start_column, int end_row, int end_column)
|
||||
{
|
||||
impl_->merge_cells(start_row, start_column, end_row, end_column);
|
||||
root_->merge_cells(start_row, start_column, end_row, end_column);
|
||||
}
|
||||
|
||||
void worksheet::unmerge_cells(const std::string &range_string)
|
||||
{
|
||||
impl_->unmerge_cells(range_string);
|
||||
root_->unmerge_cells(range_string);
|
||||
}
|
||||
|
||||
void worksheet::unmerge_cells(int start_row, int start_column, int end_row, int end_column)
|
||||
{
|
||||
impl_->unmerge_cells(start_row, start_column, end_row, end_column);
|
||||
root_->unmerge_cells(start_row, start_column, end_row, end_column);
|
||||
}
|
||||
|
||||
void worksheet::append(const std::vector<xlnt::cell> &cells)
|
||||
{
|
||||
impl_->append(cells);
|
||||
root_->append(cells);
|
||||
}
|
||||
|
||||
void worksheet::append(const std::unordered_map<std::string, xlnt::cell> &cells)
|
||||
{
|
||||
impl_->append(cells);
|
||||
root_->append(cells);
|
||||
}
|
||||
|
||||
void worksheet::append(const std::unordered_map<int, xlnt::cell> &cells)
|
||||
{
|
||||
impl_->append(cells);
|
||||
root_->append(cells);
|
||||
}
|
||||
|
||||
xlnt::range worksheet::rows() const
|
||||
{
|
||||
return impl_->rows();
|
||||
return root_->rows();
|
||||
}
|
||||
|
||||
xlnt::range worksheet::columns() const
|
||||
{
|
||||
return impl_->columns();
|
||||
return root_->columns();
|
||||
}
|
||||
|
||||
bool worksheet::operator==(const worksheet &other)
|
||||
{
|
||||
return impl_ == other.impl_;
|
||||
return root_ == other.root_;
|
||||
}
|
||||
|
||||
void worksheet::operator=(const worksheet &other)
|
||||
{
|
||||
impl_ = other.impl_;
|
||||
root_ = other.root_;
|
||||
}
|
||||
|
||||
cell worksheet::operator[](const std::string &address)
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2012-2014 Thomas Fussell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "variant.h"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
const variant $ = variant();
|
||||
|
||||
variant::~variant()
|
||||
{
|
||||
}
|
||||
|
||||
variant &variant::operator=(const variant &rhs)
|
||||
{
|
||||
type_ = rhs.type_;
|
||||
|
||||
switch(type_)
|
||||
{
|
||||
case T_Null:
|
||||
case T_True:
|
||||
case T_False:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case T_Number:
|
||||
{
|
||||
number_ = rhs.number_;
|
||||
break;
|
||||
}
|
||||
case T_String:
|
||||
{
|
||||
string_ = rhs.string_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool variant::operator==(const variant &rhs) const
|
||||
{
|
||||
if(rhs.type_ != type_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(type_)
|
||||
{
|
||||
case T_Null:
|
||||
case T_True:
|
||||
case T_False:
|
||||
return true;
|
||||
case T_Number:
|
||||
return std::abs(number_ - rhs.number_) < 0.001;
|
||||
case T_String:
|
||||
return string_.compare(rhs.string_) == 0;
|
||||
}
|
||||
|
||||
throw dynamic_type_exception();
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
|
@ -1,35 +0,0 @@
|
|||
#include <Windows.h>
|
||||
|
||||
#include "file_info.h"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
file_info::file_info(const std::string &path)
|
||||
{
|
||||
fullName_ = path;
|
||||
}
|
||||
|
||||
void file_info::delete_()
|
||||
{
|
||||
std::wstring wFileName(fullName_.begin(), fullName_.end());
|
||||
LPCWSTR lpFileName = wFileName.c_str();
|
||||
|
||||
BOOL result = DeleteFile(lpFileName);
|
||||
|
||||
if(result == 0)
|
||||
{
|
||||
throw std::runtime_error("delete failed: " + fullName_);
|
||||
}
|
||||
}
|
||||
|
||||
bool file_info::exists() const
|
||||
{
|
||||
std::wstring wFileName(fullName_.begin(), fullName_.end());
|
||||
LPCWSTR lpFileName = wFileName.c_str();
|
||||
|
||||
DWORD dwAttrib = GetFileAttributes(lpFileName);
|
||||
|
||||
return dwAttrib != INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
|
@ -8,9 +8,8 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
class package_impl
|
||||
struct package_struct
|
||||
{
|
||||
public:
|
||||
package *parent_;
|
||||
opcContainer *opc_container_;
|
||||
std::iostream &stream_;
|
||||
|
@ -42,13 +41,13 @@ public:
|
|||
return package_properties_;
|
||||
}
|
||||
|
||||
package_impl(package *parent, std::iostream &stream, file_mode package_mode, file_access package_access)
|
||||
package_struct(package *parent, std::iostream &stream, file_mode package_mode, file_access package_access)
|
||||
: parent_(parent), stream_(stream), container_buffer_(4096), package_mode_(package_mode), package_access_(package_access)
|
||||
{
|
||||
open_container();
|
||||
}
|
||||
|
||||
package_impl(package *parent, const std::string &path, file_mode package_mode, file_access package_access)
|
||||
package_struct(package *parent, const std::string &path, file_mode package_mode, file_access package_access)
|
||||
: parent_(parent), stream_(file_stream_), container_buffer_(4096), package_mode_(package_mode), package_access_(package_access)
|
||||
{
|
||||
switch(package_mode)
|
||||
|
@ -175,7 +174,7 @@ public:
|
|||
open_ = true;
|
||||
}
|
||||
|
||||
~package_impl()
|
||||
~package_struct()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
@ -257,38 +256,38 @@ public:
|
|||
|
||||
static int read_callback(void *context, char *buffer, int length)
|
||||
{
|
||||
auto object = static_cast<package_impl *>(context);
|
||||
auto object = static_cast<package_struct *>(context);
|
||||
return object->write(buffer, length);
|
||||
}
|
||||
|
||||
static int write_callback(void *context, const char *buffer, int length)
|
||||
{
|
||||
auto object = static_cast<package_impl *>(context);
|
||||
auto object = static_cast<package_struct *>(context);
|
||||
return object->read(buffer, length);
|
||||
}
|
||||
|
||||
static int close_callback(void *context)
|
||||
{
|
||||
auto object = static_cast<package_impl *>(context);
|
||||
auto object = static_cast<package_struct *>(context);
|
||||
object->close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static opc_ofs_t seek_callback(void *context, opc_ofs_t ofs)
|
||||
{
|
||||
auto object = static_cast<package_impl *>(context);
|
||||
auto object = static_cast<package_struct *>(context);
|
||||
return static_cast<opc_ofs_t>(object->seek(ofs));
|
||||
}
|
||||
|
||||
static int trim_callback(void *context, opc_ofs_t new_size)
|
||||
{
|
||||
auto object = static_cast<package_impl *>(context);
|
||||
auto object = static_cast<package_struct *>(context);
|
||||
return object->trim(new_size);
|
||||
}
|
||||
|
||||
static int flush_callback(void *context)
|
||||
{
|
||||
auto object = static_cast<package_impl *>(context);
|
||||
auto object = static_cast<package_struct *>(context);
|
||||
object->flush();
|
||||
return 0;
|
||||
}
|
||||
|
@ -296,12 +295,12 @@ public:
|
|||
|
||||
file_access package::get_file_open_access() const
|
||||
{
|
||||
return impl_->get_file_open_access();
|
||||
return root_->get_file_open_access();
|
||||
}
|
||||
|
||||
package_properties package::get_package_properties() const
|
||||
{
|
||||
return impl_->get_package_properties();
|
||||
return root_->get_package_properties();
|
||||
}
|
||||
|
||||
package package::open(std::iostream &stream, file_mode package_mode, file_access package_access)
|
||||
|
@ -315,80 +314,80 @@ package package::open(const std::string &path, file_mode package_mode, file_acce
|
|||
}
|
||||
|
||||
package::package(std::iostream &stream, file_mode package_mode, file_access package_access)
|
||||
: impl_(new package_impl(this, stream, package_mode, package_access))
|
||||
: root_(new package_struct(this, stream, package_mode, package_access))
|
||||
{
|
||||
open_container();
|
||||
}
|
||||
|
||||
package::package(const std::string &path, file_mode package_mode, file_access package_access)
|
||||
: impl_(new package_impl(this, path, package_mode, package_access))
|
||||
: root_(new package_struct(this, path, package_mode, package_access))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void package::open_container()
|
||||
{
|
||||
impl_->open_container();
|
||||
root_->open_container();
|
||||
}
|
||||
|
||||
void package::close()
|
||||
{
|
||||
impl_->close();
|
||||
root_->close();
|
||||
}
|
||||
|
||||
part package::create_part(const uri &part_uri, const std::string &content_type, compression_option compression)
|
||||
{
|
||||
return impl_->create_part(part_uri, content_type, compression);
|
||||
return root_->create_part(part_uri, content_type, compression);
|
||||
}
|
||||
|
||||
void package::delete_part(const uri &part_uri)
|
||||
{
|
||||
impl_->delete_part(part_uri);
|
||||
root_->delete_part(part_uri);
|
||||
}
|
||||
|
||||
void package::flush()
|
||||
{
|
||||
impl_->flush();
|
||||
root_->flush();
|
||||
}
|
||||
|
||||
part package::get_part(const uri &part_uri)
|
||||
{
|
||||
return impl_->get_part(part_uri);
|
||||
return root_->get_part(part_uri);
|
||||
}
|
||||
|
||||
part_collection package::get_parts()
|
||||
{
|
||||
return impl_->get_parts();
|
||||
return root_->get_parts();
|
||||
}
|
||||
|
||||
int package::write(char *buffer, int length)
|
||||
{
|
||||
return impl_->write(buffer, length);
|
||||
return root_->write(buffer, length);
|
||||
}
|
||||
|
||||
int package::read(const char *buffer, int length)
|
||||
{
|
||||
return impl_->read(buffer, length);
|
||||
return root_->read(buffer, length);
|
||||
}
|
||||
|
||||
std::ios::pos_type package::seek(std::ios::pos_type offset)
|
||||
{
|
||||
return impl_->seek(offset);
|
||||
return root_->seek(offset);
|
||||
}
|
||||
|
||||
int package::trim(std::ios::pos_type new_size)
|
||||
{
|
||||
return impl_->trim(new_size);
|
||||
return root_->trim(new_size);
|
||||
}
|
||||
|
||||
bool package::operator==(const package &comparand) const
|
||||
{
|
||||
return impl_.get() == comparand.impl_.get();
|
||||
return root_ == comparand.root_;
|
||||
}
|
||||
|
||||
bool package::operator==(const nullptr_t &) const
|
||||
{
|
||||
return impl_.get() == nullptr;
|
||||
return root_ == nullptr;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <opc/opc.h>
|
||||
#include <opc/container.h>
|
||||
|
||||
|
@ -17,7 +18,7 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
class package_impl;
|
||||
struct package_struct;
|
||||
|
||||
/// <summary>
|
||||
/// Implements a derived subclass of the abstract Package base class—the ZipPackage class uses a
|
||||
|
@ -131,7 +132,7 @@ private:
|
|||
|
||||
int trim(std::ios::pos_type new_size);
|
||||
|
||||
std::shared_ptr<package_impl> impl_;
|
||||
std::shared_ptr<package_struct> root_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
|
@ -2,20 +2,19 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
class part_impl
|
||||
struct part_struct
|
||||
{
|
||||
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_impl(package &package, const uri &uri_part, const std::string &mime_type = "", compression_option compression = compression_option::NotCompressed)
|
||||
part_struct(package &package, const uri &uri_part, const std::string &mime_type = "", compression_option compression = compression_option::NotCompressed)
|
||||
: package_(package),
|
||||
uri_(uri_part),
|
||||
content_type_(mime_type),
|
||||
compression_option_(compression)
|
||||
{}
|
||||
|
||||
part_impl(package &package, const uri &uri, opcContainer *container)
|
||||
part_struct(package &package, const uri &uri, opcContainer *container)
|
||||
: package_(package),
|
||||
uri_(uri),
|
||||
container_(container)
|
||||
|
@ -117,7 +116,7 @@ public:
|
|||
/// </summary>
|
||||
bool is_valid_xml_id(const std::string &id);
|
||||
|
||||
void operator=(const part_impl &other);
|
||||
void operator=(const part_struct &other);
|
||||
|
||||
compression_option compression_option_;
|
||||
std::string content_type_;
|
||||
|
@ -126,12 +125,12 @@ public:
|
|||
opcContainer *container_;
|
||||
};
|
||||
|
||||
part::part() : impl_(nullptr)
|
||||
part::part() : root_(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
part::part(package &package, const uri &uri, opcContainer *container) : impl_(std::make_shared<part_impl>(package, uri, container))
|
||||
part::part(package &package, const uri &uri, opcContainer *container) : root_(new part_struct(package, uri, container))
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -143,32 +142,32 @@ std::string part::get_content_type() const
|
|||
|
||||
std::string part::read()
|
||||
{
|
||||
if(impl_.get() == nullptr)
|
||||
if(root_ == nullptr)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return impl_->read();
|
||||
return root_->read();
|
||||
}
|
||||
|
||||
void part::write(const std::string &data)
|
||||
{
|
||||
if(impl_.get() == nullptr)
|
||||
if(root_ == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return impl_->write(data);
|
||||
return root_->write(data);
|
||||
}
|
||||
|
||||
bool part::operator==(const part &comparand) const
|
||||
{
|
||||
return impl_.get() == comparand.impl_.get();
|
||||
return root_ == comparand.root_;
|
||||
}
|
||||
|
||||
bool part::operator==(const nullptr_t &) const
|
||||
{
|
||||
return impl_.get() == nullptr;
|
||||
return root_ == nullptr;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
class part_impl;
|
||||
struct part_struct;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a part that is stored in a ZipPackage.
|
||||
|
@ -92,12 +92,12 @@ public:
|
|||
bool operator==(const nullptr_t &) const;
|
||||
|
||||
private:
|
||||
friend class package_impl;
|
||||
friend struct package_struct;
|
||||
|
||||
part();
|
||||
part(package &package, const uri &uri, opcContainer *container);
|
||||
|
||||
std::shared_ptr<part_impl> impl_;
|
||||
part_struct *root_;
|
||||
};
|
||||
|
||||
typedef std::vector<part> part_collection;
|
|
@ -27,9 +27,12 @@ public:
|
|||
theme
|
||||
};
|
||||
|
||||
relationship(type type) : source_uri_(""), target_uri_(""), type_(type)
|
||||
relationship(const std::string &type) : source_uri_(""), target_uri_("")
|
||||
{
|
||||
|
||||
if(type == "hyperlink")
|
||||
{
|
||||
type_ = type::hyperlink;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
|
@ -2,7 +2,7 @@
|
|||
#include <Shlwapi.h>
|
||||
#include <Windows.h>
|
||||
|
||||
#include "File.h"
|
||||
#include "../file.h"
|
||||
|
||||
namespace xlnt {
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#include "reader.h"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
workbook reader::load_workbook(const std::string &/*filename*/)
|
||||
{
|
||||
return workbook();
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
|
@ -1,21 +0,0 @@
|
|||
#include "cell.h"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class cell_impl
|
||||
{
|
||||
public:
|
||||
variant value;
|
||||
};
|
||||
|
||||
cell::cell() : impl_(std::make_shared<cell_impl>())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
variant &cell::value()
|
||||
{
|
||||
return impl_->value;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
317
source/tests/CellTestSuite.h
Normal file
317
source/tests/CellTestSuite.h
Normal file
|
@ -0,0 +1,317 @@
|
|||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/cell.h>
|
||||
#include <xlnt/style.h>
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class CellTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
CellTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_coordinates()
|
||||
{
|
||||
auto coord = xlnt::cell::coordinate_from_string("ZF46");
|
||||
TS_ASSERT_EQUALS("ZF", coord.column);
|
||||
TS_ASSERT_EQUALS(46, coord.row);
|
||||
}
|
||||
|
||||
void test_invalid_coordinate()
|
||||
{
|
||||
TS_ASSERT_THROWS_ANYTHING(xlnt::cell::coordinate_from_string("AAA"));
|
||||
}
|
||||
|
||||
void test_zero_row()
|
||||
{
|
||||
TS_ASSERT_THROWS_ANYTHING(xlnt::cell::coordinate_from_string("AQ0"));
|
||||
}
|
||||
|
||||
void test_absolute()
|
||||
{
|
||||
TS_ASSERT_EQUALS("$ZF$51", xlnt::cell::absolute_coordinate("ZF51"));
|
||||
}
|
||||
|
||||
void test_absolute_multiple()
|
||||
{
|
||||
TS_ASSERT_EQUALS("$ZF$51:$ZF$53", xlnt::cell::absolute_coordinate("ZF51:ZF$53"));
|
||||
}
|
||||
|
||||
void test_column_index()
|
||||
{
|
||||
TS_ASSERT_EQUALS(10, xlnt::cell::column_index_from_string("J"));
|
||||
TS_ASSERT_EQUALS(270, xlnt::cell::column_index_from_string("jJ"));
|
||||
TS_ASSERT_EQUALS(7030, xlnt::cell::column_index_from_string("jjj"));
|
||||
}
|
||||
|
||||
|
||||
void test_bad_column_index()
|
||||
{
|
||||
auto _check = [](const std::string &bad_string)
|
||||
{
|
||||
xlnt::cell::column_index_from_string(bad_string);
|
||||
};
|
||||
|
||||
auto bad_strings = {"JJJJ", "", "$", "1"};
|
||||
for(auto bad_string : bad_strings)
|
||||
{
|
||||
TS_ASSERT_THROWS_ANYTHING(_check(bad_string));
|
||||
}
|
||||
}
|
||||
|
||||
void test_column_letter_boundries()
|
||||
{
|
||||
TS_ASSERT_THROWS_ANYTHING(xlnt::cell::get_column_letter(0));
|
||||
TS_ASSERT_THROWS_ANYTHING(xlnt::cell::get_column_letter(18279));
|
||||
}
|
||||
|
||||
|
||||
void test_column_letter()
|
||||
{
|
||||
TS_ASSERT_EQUALS("ZZZ", xlnt::cell::get_column_letter(18278));
|
||||
TS_ASSERT_EQUALS("JJJ", xlnt::cell::get_column_letter(7030));
|
||||
TS_ASSERT_EQUALS("AB", xlnt::cell::get_column_letter(28));
|
||||
TS_ASSERT_EQUALS("AA", xlnt::cell::get_column_letter(27));
|
||||
TS_ASSERT_EQUALS("Z", xlnt::cell::get_column_letter(26));
|
||||
}
|
||||
|
||||
|
||||
void test_initial_value()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1, "17.5");
|
||||
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
}
|
||||
|
||||
void test_null()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::null, cell.get_data_type());
|
||||
}
|
||||
|
||||
void test_numeric()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1, "17.5");
|
||||
|
||||
cell = 42;
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = "4.2";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = "-42.000";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = "0";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = 0;
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = 0.0001;
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = "0.9999";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = "99E-02";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = 1e1;
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = "4";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = "-1E3";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
cell = 4;
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
}
|
||||
|
||||
void test_string()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
cell = "hello";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::string, cell.get_data_type());
|
||||
}
|
||||
|
||||
void test_single_dot()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
cell = ".";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::string, cell.get_data_type());
|
||||
}
|
||||
|
||||
void test_formula()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
cell = "=42";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::formula, cell.get_data_type());
|
||||
}
|
||||
|
||||
void test_boolean()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
cell = true;
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::boolean, cell.get_data_type());
|
||||
cell = false;
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::boolean, cell.get_data_type());
|
||||
}
|
||||
|
||||
void test_leading_zero()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
cell = "0800";
|
||||
TS_ASSERT_EQUALS(xlnt::cell::type::string, cell.get_data_type());
|
||||
}
|
||||
|
||||
void check_error()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(xlnt::cell::type::error, cell.get_data_type());
|
||||
|
||||
//for(error_string in cell.ERROR_CODES.keys())
|
||||
//{
|
||||
// cell.value = error_string;
|
||||
// yield check_error;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
void test_data_type_check()
|
||||
{
|
||||
//xlnt::workbook wb;
|
||||
//xlnt::worksheet ws(wb);
|
||||
//xlnt::cell cell(ws, "A", 1);
|
||||
|
||||
//cell.bind_value(xlnt::cell::$);
|
||||
//TS_ASSERT_EQUALS(xlnt::cell::type::null, cell.get_data_type());
|
||||
|
||||
//cell.bind_value(".0e000");
|
||||
//TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
|
||||
//cell.bind_value("-0.e-0");
|
||||
//TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
|
||||
//cell.bind_value("1E");
|
||||
//TS_ASSERT_EQUALS(xlnt::cell::type::string, cell.get_data_type());
|
||||
}
|
||||
|
||||
void test_set_bad_type()
|
||||
{
|
||||
//xlnt::workbook wb;
|
||||
//xlnt::worksheet ws(wb);
|
||||
//xlnt::cell cell(ws, "A", 1);
|
||||
|
||||
//cell.set_value_explicit(1, "q");
|
||||
}
|
||||
|
||||
|
||||
void test_time()
|
||||
{
|
||||
//auto check_time = [](raw_value, coerced_value)
|
||||
//{
|
||||
// cell.value = raw_value
|
||||
// TS_ASSERT_EQUALS(cell.value, coerced_value)
|
||||
// TS_ASSERT_EQUALS(cell.TYPE_NUMERIC, cell.data_type)
|
||||
//};
|
||||
|
||||
//xlnt::workbook wb;
|
||||
//xlnt::worksheet ws(wb);
|
||||
//xlnt::cell cell(ws, "A", 1);
|
||||
|
||||
//cell = "03:40:16";
|
||||
//TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
//tm expected;
|
||||
//expected.tm_hour = 3;
|
||||
//expected.tm_min = 40;
|
||||
//expected.tm_sec = 16;
|
||||
//TS_ASSERT_EQUALS(cell, expected);
|
||||
|
||||
//cell = "03:40";
|
||||
//TS_ASSERT_EQUALS(xlnt::cell::type::numeric, cell.get_data_type());
|
||||
//tm expected;
|
||||
//expected.tm_hour = 3;
|
||||
//expected.tm_min = 40;
|
||||
//TS_ASSERT_EQUALS(cell, expected);
|
||||
}
|
||||
|
||||
void test_date_format_on_non_date()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
time_t t = time(0);
|
||||
tm now = *localtime(&t);
|
||||
cell = now;
|
||||
cell = "testme";
|
||||
TS_ASSERT("testme" == cell);
|
||||
}
|
||||
|
||||
void test_set_get_date()
|
||||
{
|
||||
tm today = {0};
|
||||
today.tm_year = 2010;
|
||||
today.tm_mon = 1;
|
||||
today.tm_yday = 18;
|
||||
today.tm_hour = 14;
|
||||
today.tm_min = 15;
|
||||
today.tm_sec = 20;
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
cell = today;
|
||||
TS_ASSERT(today == cell);
|
||||
}
|
||||
|
||||
void test_repr()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
TS_ASSERT_EQUALS(cell.to_string(), "<Cell Sheet1.A1>");
|
||||
}
|
||||
|
||||
void test_is_date()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
xlnt::worksheet ws(wb);
|
||||
xlnt::cell cell(ws, "A", 1);
|
||||
|
||||
time_t t = time(0);
|
||||
tm now = *localtime(&t);
|
||||
cell = now;
|
||||
TS_ASSERT_EQUALS(cell.is_date(), true);
|
||||
|
||||
cell = "testme";
|
||||
TS_ASSERT("testme", cell);
|
||||
TS_ASSERT_EQUALS(cell.is_date(), false);
|
||||
}
|
||||
|
||||
|
||||
void test_is_not_date_color_format()
|
||||
{
|
||||
//xlnt::workbook wb;
|
||||
//xlnt::worksheet ws(wb);
|
||||
//xlnt::cell cell(ws, "A", 1);
|
||||
|
||||
//cell = -13.5;
|
||||
//cell.get_style().get_number_format().set_format_code("0.00_);[Red]\(0.00\)");
|
||||
|
||||
//TS_ASSERT_EQUALS(cell.is_date(), false);
|
||||
}
|
||||
};
|
163
source/tests/ChartTestSuite.h
Normal file
163
source/tests/ChartTestSuite.h
Normal file
|
@ -0,0 +1,163 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class ChartTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
ChartTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setUp()
|
||||
{
|
||||
/*
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.get_active();
|
||||
ws.set_title("data");
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
ws.cell(i, 0) = i;
|
||||
auto chart = BarChart();
|
||||
chart.title = "TITLE";
|
||||
chart.add_serie(Serie(Reference(ws, (0, 0), (10, 0))));
|
||||
chart._series[-1].color = Color.GREEN;
|
||||
cw = ChartWriter(chart);
|
||||
root = Element("test");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void test_write_title()
|
||||
{
|
||||
/*
|
||||
cw._write_title(root);
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:title><c:tx><c:rich><a:bodyPr /><a:lstStyle /><a:p><a:pPr><a:defRPr /></a:pPr><a:r><a:rPr lang="fr-FR" /><a:t>TITLE</a:t></a:r></a:p></c:rich></c:tx><c:layout /></c:title></test>");
|
||||
*/
|
||||
}
|
||||
|
||||
void test_write_xaxis()
|
||||
{
|
||||
/*
|
||||
cw._write_axis(root, chart.x_axis, "c:catAx");
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:catAx><c:axId val="60871424" /><c:scaling><c:orientation val="minMax" /></c:scaling><c:axPos val="b" /><c:tickLblPos val="nextTo" /><c:crossAx val="60873344" /><c:crosses val="autoZero" /><c:auto val="1" /><c:lblAlgn val="ctr" /><c:lblOffset val="100" /></c:catAx></test>");
|
||||
*/
|
||||
}
|
||||
|
||||
void test_write_yaxis()
|
||||
{
|
||||
/*
|
||||
cw._write_axis(root, chart.y_axis, "c:valAx");
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:valAx><c:axId val="60873344" /><c:scaling><c:orientation val="minMax" /><c:max val="10.0" /><c:min val="0.0" /></c:scaling><c:axPos val="l" /><c:majorGridlines /><c:numFmt formatCode="General" sourceLinked="1" /><c:tickLblPos val="nextTo" /><c:crossAx val="60871424" /><c:crosses val="autoZero" /><c:crossBetween val="between" /><c:majorUnit val="2.0" /></c:valAx></test>");
|
||||
*/
|
||||
}
|
||||
|
||||
void test_write_series()
|
||||
{
|
||||
//cw._write_series(root);
|
||||
//TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:ser><c:idx val="0" /><c:order val="0" /><c:spPr><a:solidFill><a:srgbClr val="00FF00" /></a:solidFill><a:ln><a:solidFill><a:srgbClr val="00FF00" /></a:solidFill></a:ln></c:spPr><c:marker><c:symbol val="none" /></c:marker><c:val><c:numRef><c:f>\"data\"!$A$1:$A$11</c:f><c:numCache><c:formatCode>General</c:formatCode><c:ptCount val="11" /><c:pt idx="0"><c:v>0</c:v></c:pt><c:pt idx="1"><c:v>1</c:v></c:pt><c:pt idx="2"><c:v>2</c:v></c:pt><c:pt idx="3"><c:v>3</c:v></c:pt><c:pt idx="4"><c:v>4</c:v></c:pt><c:pt idx="5"><c:v>5</c:v></c:pt><c:pt idx="6"><c:v>6</c:v></c:pt><c:pt idx="7"><c:v>7</c:v></c:pt><c:pt idx="8"><c:v>8</c:v></c:pt><c:pt idx="9"><c:v>9</c:v></c:pt><c:pt idx="10"><c:v>None</c:v></c:pt></c:numCache></c:numRef></c:val></c:ser></test>");
|
||||
}
|
||||
|
||||
void test_write_legend()
|
||||
{
|
||||
/*cw._write_legend(root);
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:legend><c:legendPos val="r" /><c:layout /></c:legend></test>");*/
|
||||
}
|
||||
|
||||
void test_no_write_legend()
|
||||
{
|
||||
/*xlnt::workbook wb;
|
||||
auto ws = wb.get_active();
|
||||
ws.set_title("data");
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
ws.cell(i, 0) = i;
|
||||
ws.cell(i, 1) = i;
|
||||
scatterchart = ScatterChart();
|
||||
scatterchart.add_serie(Serie(Reference(ws, (0, 0), (10, 0)), ;
|
||||
xvalues = Reference(ws, (0, 1), (10, 1))));
|
||||
cw = ChartWriter(scatterchart);
|
||||
root = Element("test");
|
||||
scatterchart.show_legend = False;
|
||||
cw._write_legend(root);
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test />");
|
||||
}*/
|
||||
}
|
||||
|
||||
void test_write_print_settings()
|
||||
{
|
||||
/*cw._write_print_settings(root);
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:printSettings><c:headerFooter /><c:pageMargins b="0.75" footer="0.3" header="0.3" l="0.7" r="0.7" t="0.75" /><c:pageSetup /></c:printSettings></test>");*/
|
||||
}
|
||||
|
||||
void test_write_chart()
|
||||
{
|
||||
//cw._write_chart(root);
|
||||
//// Truncate floats because results differ with Python >= 3.2 and <= 3.1
|
||||
//test_xml = sub("([0-9][.][0-9]{4})[0-9]*", "\\1", get_xml(root));
|
||||
//TS_ASSERT_EQUALS(test_xml, "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:chart><c:title><c:tx><c:rich><a:bodyPr /><a:lstStyle /><a:p><a:pPr><a:defRPr /></a:pPr><a:r><a:rPr lang="fr-FR" /><a:t>TITLE</a:t></a:r></a:p></c:rich></c:tx><c:layout /></c:title><c:plotArea><c:layout><c:manualLayout><c:layoutTarget val="inner" /><c:xMode val="edge" /><c:yMode val="edge" /><c:x val="1.2857" /><c:y val="0.2125" /><c:w val="0.6" /><c:h val="0.6" /></c:manualLayout></c:layout><c:barChart><c:barDir val="col" /><c:grouping val="clustered" /><c:ser><c:idx val="0" /><c:order val="0" /><c:spPr><a:solidFill><a:srgbClr val="00FF00" /></a:solidFill><a:ln><a:solidFill><a:srgbClr val="00FF00" /></a:solidFill></a:ln></c:spPr><c:marker><c:symbol val="none" /></c:marker><c:val><c:numRef><c:f>\"data\"!$A$1:$A$11</c:f><c:numCache><c:formatCode>General</c:formatCode><c:ptCount val="11" /><c:pt idx="0"><c:v>0</c:v></c:pt><c:pt idx="1"><c:v>1</c:v></c:pt><c:pt idx="2"><c:v>2</c:v></c:pt><c:pt idx="3"><c:v>3</c:v></c:pt><c:pt idx="4"><c:v>4</c:v></c:pt><c:pt idx="5"><c:v>5</c:v></c:pt><c:pt idx="6"><c:v>6</c:v></c:pt><c:pt idx="7"><c:v>7</c:v></c:pt><c:pt idx="8"><c:v>8</c:v></c:pt><c:pt idx="9"><c:v>9</c:v></c:pt><c:pt idx="10"><c:v>None</c:v></c:pt></c:numCache></c:numRef></c:val></c:ser><c:marker val="1" /><c:axId val="60871424" /><c:axId val="60873344" /></c:barChart><c:catAx><c:axId val="60871424" /><c:scaling><c:orientation val="minMax" /></c:scaling><c:axPos val="b" /><c:tickLblPos val="nextTo" /><c:crossAx val="60873344" /><c:crosses val="autoZero" /><c:auto val="1" /><c:lblAlgn val="ctr" /><c:lblOffset val="100" /></c:catAx><c:valAx><c:axId val="60873344" /><c:scaling><c:orientation val="minMax" /><c:max val="10.0" /><c:min val="0.0" /></c:scaling><c:axPos val="l" /><c:majorGridlines /><c:numFmt formatCode="General" sourceLinked="1" /><c:tickLblPos val="nextTo" /><c:crossAx val="60871424" /><c:crosses val="autoZero" /><c:crossBetween val="between" /><c:majorUnit val="2.0" /></c:valAx></c:plotArea><c:legend><c:legendPos val="r" /><c:layout /></c:legend><c:plotVisOnly val="1" /></c:chart></test>");
|
||||
}
|
||||
|
||||
void setUp_scatter()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
ws = wb.get_active_sheet();
|
||||
ws.title = "data";
|
||||
for i in range(10)
|
||||
{
|
||||
ws.cell(row = i, column = 0).value = i;
|
||||
ws.cell(row = i, column = 1).value = i;
|
||||
scatterchart = ScatterChart();
|
||||
scatterchart.add_serie(Serie(Reference(ws, (0, 0), (10, 0)), ;
|
||||
xvalues = Reference(ws, (0, 1), (10, 1))));
|
||||
cw = ChartWriter(scatterchart);
|
||||
root = Element("test");
|
||||
}*/
|
||||
}
|
||||
|
||||
void test_write_xaxis_scatter()
|
||||
{
|
||||
/*scatterchart.x_axis.title = "test x axis title";
|
||||
cw._write_axis(root, scatterchart.x_axis, "c:valAx");
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:valAx><c:axId val="60871424" /><c:scaling><c:orientation val="minMax" /><c:max val="10.0" /><c:min val="0.0" /></c:scaling><c:axPos val="b" /><c:majorGridlines /><c:numFmt formatCode="General" sourceLinked="1" /><c:title><c:tx><c:rich><a:bodyPr /><a:lstStyle /><a:p><a:pPr><a:defRPr /></a:pPr><a:r><a:rPr lang="fr-FR" /><a:t>test x axis title</a:t></a:r></a:p></c:rich></c:tx><c:layout /></c:title><c:tickLblPos val="nextTo" /><c:crossAx val="60873344" /><c:crosses val="autoZero" /><c:auto val="1" /><c:lblAlgn val="ctr" /><c:lblOffset val="100" /><c:crossBetween val="midCat" /><c:majorUnit val="2.0" /></c:valAx></test>");*/
|
||||
}
|
||||
|
||||
void test_write_yaxis_scatter()
|
||||
{
|
||||
/*scatterchart.y_axis.title = "test y axis title";
|
||||
cw._write_axis(root, scatterchart.y_axis, "c:valAx");
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:valAx><c:axId val="60873344" /><c:scaling><c:orientation val="minMax" /><c:max val="10.0" /><c:min val="0.0" /></c:scaling><c:axPos val="l" /><c:majorGridlines /><c:numFmt formatCode="General" sourceLinked="1" /><c:title><c:tx><c:rich><a:bodyPr /><a:lstStyle /><a:p><a:pPr><a:defRPr /></a:pPr><a:r><a:rPr lang="fr-FR" /><a:t>test y axis title</a:t></a:r></a:p></c:rich></c:tx><c:layout /></c:title><c:tickLblPos val="nextTo" /><c:crossAx val="60871424" /><c:crosses val="autoZero" /><c:crossBetween val="midCat" /><c:majorUnit val="2.0" /></c:valAx></test>");*/
|
||||
}
|
||||
|
||||
void test_write_series_scatter()
|
||||
{
|
||||
/*cw._write_series(root);
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:ser><c:idx val="0" /><c:order val="0" /><c:marker><c:symbol val="none" /></c:marker><c:xVal><c:numRef><c:f>\"data\"!$B$1:$B$11</c:f><c:numCache><c:formatCode>General</c:formatCode><c:ptCount val="11" /><c:pt idx="0"><c:v>0</c:v></c:pt><c:pt idx="1"><c:v>1</c:v></c:pt><c:pt idx="2"><c:v>2</c:v></c:pt><c:pt idx="3"><c:v>3</c:v></c:pt><c:pt idx="4"><c:v>4</c:v></c:pt><c:pt idx="5"><c:v>5</c:v></c:pt><c:pt idx="6"><c:v>6</c:v></c:pt><c:pt idx="7"><c:v>7</c:v></c:pt><c:pt idx="8"><c:v>8</c:v></c:pt><c:pt idx="9"><c:v>9</c:v></c:pt><c:pt idx="10"><c:v>None</c:v></c:pt></c:numCache></c:numRef></c:xVal><c:yVal><c:numRef><c:f>\"data\"!$A$1:$A$11</c:f><c:numCache><c:formatCode>General</c:formatCode><c:ptCount val="11" /><c:pt idx="0"><c:v>0</c:v></c:pt><c:pt idx="1"><c:v>1</c:v></c:pt><c:pt idx="2"><c:v>2</c:v></c:pt><c:pt idx="3"><c:v>3</c:v></c:pt><c:pt idx="4"><c:v>4</c:v></c:pt><c:pt idx="5"><c:v>5</c:v></c:pt><c:pt idx="6"><c:v>6</c:v></c:pt><c:pt idx="7"><c:v>7</c:v></c:pt><c:pt idx="8"><c:v>8</c:v></c:pt><c:pt idx="9"><c:v>9</c:v></c:pt><c:pt idx="10"><c:v>None</c:v></c:pt></c:numCache></c:numRef></c:yVal></c:ser></test>");*/
|
||||
}
|
||||
|
||||
void test_write_legend_scatter()
|
||||
{
|
||||
/*cw._write_legend(root);
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:legend><c:legendPos val="r" /><c:layout /></c:legend></test>");*/
|
||||
}
|
||||
|
||||
void test_write_print_settings_scatter()
|
||||
{
|
||||
/*cw._write_print_settings(root);
|
||||
TS_ASSERT_EQUALS(get_xml(root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><test><c:printSettings><c:headerFooter /><c:pageMargins b="0.75" footer="0.3" header="0.3" l="0.7" r="0.7" t="0.75" /><c:pageSetup /></c:printSettings></test>");*/
|
||||
}
|
||||
|
||||
void test_write_chart_scatter()
|
||||
{
|
||||
//cw._write_chart(root);
|
||||
//// Truncate floats because results differ with Python >= 3.2 and <= 3.1
|
||||
//test_xml = sub("([0-9][.][0-9]{4})[0-9]*", "\\1", get_xml(root));
|
||||
//TS_ASSERT_EQUALS(test_xml, "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?>;
|
||||
}
|
||||
};
|
159
source/tests/DumpTestSuite.h
Normal file
159
source/tests/DumpTestSuite.h
Normal file
|
@ -0,0 +1,159 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class DumpTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
DumpTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void _get_test_filename()
|
||||
{
|
||||
/*test_file = NamedTemporaryFile(mode = "w", prefix = "openpyxl.", suffix = ".xlsx", delete = False);
|
||||
test_file.close();
|
||||
return test_file.name;*/
|
||||
}
|
||||
|
||||
//_COL_CONVERSION_CACHE = dict((get_column_letter(i), i) for i in range(1, 18279));
|
||||
|
||||
void test_dump_sheet_title()
|
||||
{
|
||||
/*test_filename = _get_test_filename();
|
||||
wb = Workbook(optimized_write = True);
|
||||
ws = wb.create_sheet(title = "Test1");
|
||||
wb.save(test_filename);
|
||||
wb2 = load_workbook(test_filename, True);
|
||||
ws = wb2.get_sheet_by_name("Test1");
|
||||
TS_ASSERT_EQUALS("Test1", ws.title);*/
|
||||
}
|
||||
|
||||
void test_dump_sheet()
|
||||
{
|
||||
/*test_filename = _get_test_filename();
|
||||
wb = Workbook(optimized_write = True);
|
||||
ws = wb.create_sheet();
|
||||
letters = [get_column_letter(x + 1) for x in range(20)];
|
||||
expected_rows = [];
|
||||
for(auto row : range(20))
|
||||
{
|
||||
expected_rows.append(["%s%d" % (letter, row + 1) for letter in letters]);
|
||||
for row in range(20)
|
||||
{
|
||||
expected_rows.append([(row + 1) for letter in letters]);
|
||||
for row in range(10)
|
||||
{
|
||||
expected_rows.append([datetime(2010, ((x % 12) + 1), row + 1) for x in range(len(letters))]);
|
||||
for row in range(20)
|
||||
{
|
||||
expected_rows.append(["=%s%d" % (letter, row + 1) for letter in letters]);
|
||||
for row in expected_rows
|
||||
{
|
||||
ws.append(row);
|
||||
}
|
||||
|
||||
wb.save(test_filename);
|
||||
wb2 = load_workbook(test_filename, True)
|
||||
}
|
||||
|
||||
ws = wb2.worksheets[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for ex_row, ws_row in zip(expected_rows[:-20], ws.iter_rows())
|
||||
{
|
||||
for ex_cell, ws_cell in zip(ex_row, ws_row)
|
||||
{
|
||||
TS_ASSERT_EQUALS(ex_cell, ws_cell.internal_value)
|
||||
|
||||
os.remove(test_filename)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void test_table_builder()
|
||||
{
|
||||
//sb = StringTableBuilder()
|
||||
|
||||
// result = {"a":0, "b" : 1, "c" : 2, "d" : 3}
|
||||
|
||||
// for letter in sorted(result.keys())
|
||||
// {
|
||||
// for x in range(5)
|
||||
// {
|
||||
// sb.add(letter)
|
||||
|
||||
// table = dict(sb.get_table())
|
||||
|
||||
// try
|
||||
// {
|
||||
// result_items = result.items()
|
||||
// }
|
||||
|
||||
// for key, idx in result_items
|
||||
// {
|
||||
// TS_ASSERT_EQUALS(idx, table[key])
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void test_open_too_many_files()
|
||||
{
|
||||
//test_filename = _get_test_filename();
|
||||
//wb = Workbook(optimized_write = True);
|
||||
|
||||
//for i in range(200) // over 200 worksheets should raise an OSError("too many open files")
|
||||
//{
|
||||
// wb.create_sheet();
|
||||
// wb.save(test_filename);
|
||||
// os.remove(test_filename);
|
||||
//}
|
||||
}
|
||||
|
||||
void test_create_temp_file()
|
||||
{
|
||||
//f = dump_worksheet.create_temporary_file();
|
||||
|
||||
//if(!osp.isfile(f))
|
||||
//{
|
||||
// raise Exception("The file %s does not exist" % f)
|
||||
//}
|
||||
}
|
||||
|
||||
void test_dump_twice()
|
||||
{
|
||||
//test_filename = _get_test_filename();
|
||||
|
||||
//wb = Workbook(optimized_write = True);
|
||||
//ws = wb.create_sheet();
|
||||
//ws.append(["hello"]);
|
||||
|
||||
//wb.save(test_filename);
|
||||
//os.remove(test_filename);
|
||||
|
||||
//wb.save(test_filename);
|
||||
}
|
||||
|
||||
void test_append_after_save()
|
||||
{
|
||||
//test_filename = _get_test_filename();
|
||||
|
||||
//wb = Workbook(optimized_write = True);
|
||||
//ws = wb.create_sheet();
|
||||
//ws.append(["hello"]);
|
||||
|
||||
//wb.save(test_filename);
|
||||
//os.remove(test_filename);
|
||||
|
||||
//ws.append(["hello"]);
|
||||
}
|
||||
};
|
|
@ -3,6 +3,7 @@
|
|||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/cell.h>
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
|
@ -16,7 +17,7 @@ public:
|
|||
|
||||
void test_1()
|
||||
{
|
||||
auto wb = xlnt::workbook();
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.get_active();
|
||||
auto ws1 = wb.create_sheet();
|
||||
auto ws2 = wb.create_sheet(0);
|
||||
|
@ -32,16 +33,16 @@ public:
|
|||
std::cout << sheet.get_title() << std::endl;
|
||||
}
|
||||
|
||||
auto cell_range = ws["A1:C2"];
|
||||
//auto cell_range = ws["A1:C2"];
|
||||
|
||||
auto c = ws["A4"];
|
||||
ws["A4"].value() = 4;
|
||||
/* auto c = ws["A4"];
|
||||
ws["A4"] = 4;
|
||||
auto d = ws.cell(4, 2);
|
||||
c.value() = "hello, world";
|
||||
std::cout << (std::string)c.value() << std::endl;
|
||||
d.value() = 3.14;
|
||||
std::cout << (double)d.value() << std::endl;
|
||||
c = "hello, world";
|
||||
std::cout << c << std::endl;
|
||||
d = 3.14;
|
||||
std::cout << d << std::endl;
|
||||
|
||||
wb.save("balances.xlsx");
|
||||
wb.save("balances.xlsx");*/
|
||||
}
|
||||
};
|
100
source/tests/IterTestSuite.h
Normal file
100
source/tests/IterTestSuite.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class IterTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
IterTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_1()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_get_dimensions()
|
||||
{
|
||||
//expected = ["A1:G5", "D1:K30", "D2:D2", "A1:C1"];
|
||||
|
||||
//wb = _open_wb();
|
||||
//for i, sheetn in enumerate(wb.get_sheet_names())
|
||||
//{
|
||||
// ws = wb.get_sheet_by_name(name = sheetn);
|
||||
// TS_ASSERT_EQUALS(ws._dimensions, expected[i]);
|
||||
//}
|
||||
}
|
||||
|
||||
void test_read_fast_integrated()
|
||||
{
|
||||
//sheet_name = "Sheet1 - Text"
|
||||
|
||||
// expected = [["This is cell A1 in Sheet 1", None, None, None, None, None, None],
|
||||
// [None, None, None, None, None, None, None],
|
||||
// [None, None, None, None, None, None, None],
|
||||
// [None, None, None, None, None, None, None],
|
||||
// [None, None, None, None, None, None, "This is cell G5"], ]
|
||||
|
||||
// wb = load_workbook(filename = workbook_name, use_iterators = True)
|
||||
// ws = wb.get_sheet_by_name(name = sheet_name)
|
||||
|
||||
// for row, expected_row in zip(ws.iter_rows(), expected) :
|
||||
|
||||
// row_values = [x.internal_value for x in row]
|
||||
|
||||
// TS_ASSERT_EQUALS(row_values, expected_row)
|
||||
}
|
||||
|
||||
void test_get_boundaries_range()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(get_range_boundaries("C1:C4"), (3, 1, 3, 4))
|
||||
}
|
||||
|
||||
void test_get_boundaries_one()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(get_range_boundaries("C1"), (3, 1, 4, 1))
|
||||
}
|
||||
|
||||
void test_read_single_cell_range()
|
||||
{
|
||||
//wb = load_workbook(filename = workbook_name, use_iterators = True)
|
||||
// ws = wb.get_sheet_by_name(name = sheet_name)
|
||||
|
||||
// TS_ASSERT_EQUALS("This is cell A1 in Sheet 1", list(ws.iter_rows("A1"))[0][0].internal_value)
|
||||
}
|
||||
|
||||
void test_read_fast_integrated2()
|
||||
{
|
||||
//sheet_name = "Sheet2 - Numbers"
|
||||
|
||||
// expected = [[x + 1] for x in range(30)]
|
||||
|
||||
// query_range = "D1:E30"
|
||||
|
||||
// wb = load_workbook(filename = workbook_name, use_iterators = True)
|
||||
// ws = wb.get_sheet_by_name(name = sheet_name)
|
||||
|
||||
// for row, expected_row in zip(ws.iter_rows(query_range), expected) :
|
||||
|
||||
// row_values = [x.internal_value for x in row]
|
||||
|
||||
// TS_ASSERT_EQUALS(row_values, expected_row)
|
||||
}
|
||||
|
||||
void test_read_single_cell_date()
|
||||
{
|
||||
//sheet_name = "Sheet4 - Dates"
|
||||
|
||||
// wb = load_workbook(filename = workbook_name, use_iterators = True)
|
||||
// ws = wb.get_sheet_by_name(name = sheet_name)
|
||||
|
||||
// TS_ASSERT_EQUALS(datetime.datetime(1973, 5, 20), list(ws.iter_rows("A1"))[0][0].internal_value)
|
||||
// TS_ASSERT_EQUALS(datetime.datetime(1973, 5, 20, 9, 15, 2), list(ws.iter_rows("C1"))[0][0].internal_value)
|
||||
}
|
||||
};
|
35
source/tests/MetaTestSuite.h
Normal file
35
source/tests/MetaTestSuite.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class MetaTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
MetaTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_write_content_types()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//wb.create_sheet();
|
||||
//wb.create_sheet();
|
||||
//content = write_content_types(wb);
|
||||
//reference_file = os.path.join(DATADIR, "writer", "expected",
|
||||
// "[Content_Types].xml");
|
||||
//assert_equals_file_content(reference_file, content);
|
||||
}
|
||||
|
||||
void test_write_root_rels()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//content = write_root_rels(wb);
|
||||
//reference_file = os.path.join(DATADIR, "writer", "expected", ".rels");
|
||||
//assert_equals_file_content(reference_file, content);
|
||||
}
|
||||
};
|
216
source/tests/NamedRangeTestSuite.h
Normal file
216
source/tests/NamedRangeTestSuite.h
Normal file
|
@ -0,0 +1,216 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class NamedRangeTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
NamedRangeTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_split()
|
||||
{
|
||||
/*TS_ASSERT_EQUALS([("My Sheet", "$D$8"), ], split_named_range(""My Sheet"!$D$8"))*/
|
||||
}
|
||||
|
||||
void test_split_no_quotes()
|
||||
{
|
||||
/*TS_ASSERT_EQUALS([("HYPOTHESES", "$B$3:$L$3"), ], split_named_range("HYPOTHESES!$B$3:$L$3"))*/
|
||||
}
|
||||
|
||||
void test_bad_range_name()
|
||||
{
|
||||
/*assert_raises(NamedRangeException, split_named_range, "HYPOTHESES$B$3")*/
|
||||
}
|
||||
|
||||
void test_range_name_worksheet_special_chars()
|
||||
{
|
||||
/*class DummyWs
|
||||
{
|
||||
title = "My Sheeet with a , and \""
|
||||
|
||||
void __str__()
|
||||
{
|
||||
return title
|
||||
}
|
||||
|
||||
ws = DummyWs()
|
||||
};
|
||||
|
||||
class DummyWB
|
||||
{
|
||||
void get_sheet_by_name(self, name)
|
||||
{
|
||||
if name == ws.title :
|
||||
return ws
|
||||
}
|
||||
};
|
||||
|
||||
handle = open(os.path.join(DATADIR, "reader", "workbook_namedrange.xml"))
|
||||
try
|
||||
{
|
||||
content = handle.read()
|
||||
named_ranges = read_named_ranges(content, DummyWB())
|
||||
TS_ASSERT_EQUALS(1, len(named_ranges))
|
||||
ok_(isinstance(named_ranges[0], NamedRange))
|
||||
TS_ASSERT_EQUALS([(ws, "$U$16:$U$24"), (ws, "$V$28:$V$36")], named_ranges[0].destinations)
|
||||
}
|
||||
finally
|
||||
{
|
||||
handle.close()
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void test_read_named_ranges()
|
||||
{
|
||||
/*class DummyWs
|
||||
{
|
||||
title = "My Sheeet"
|
||||
|
||||
void __str__()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
};
|
||||
|
||||
class DummyWB
|
||||
{
|
||||
void get_sheet_by_name(self, name)
|
||||
{
|
||||
return DummyWs()
|
||||
}
|
||||
};
|
||||
|
||||
handle = open(os.path.join(DATADIR, "reader", "workbook.xml"))
|
||||
try :
|
||||
content = handle.read()
|
||||
named_ranges = read_named_ranges(content, DummyWB())
|
||||
TS_ASSERT_EQUALS(["My Sheeet!$D$8"], [str(range) for range in named_ranges])
|
||||
finally :
|
||||
handle.close()*/
|
||||
}
|
||||
|
||||
void test_oddly_shaped_named_ranges()
|
||||
{
|
||||
/* ranges_counts = ((4, "TEST_RANGE"),
|
||||
(3, "TRAP_1"),
|
||||
(13, "TRAP_2"))*/
|
||||
}
|
||||
|
||||
//void check_ranges(ws, count, range_name)
|
||||
//{
|
||||
// /*TS_ASSERT_EQUALS(count, len(ws.range(range_name)))
|
||||
|
||||
// wb = load_workbook(os.path.join(DATADIR, "genuine", "merge_range.xlsx"),
|
||||
// use_iterators = False)
|
||||
|
||||
// ws = wb.worksheets[0]
|
||||
|
||||
// for count, range_name in ranges_counts
|
||||
// {
|
||||
// yield check_ranges, ws, count, range_name
|
||||
// }*/
|
||||
//}
|
||||
|
||||
|
||||
void test_merged_cells_named_range()
|
||||
{
|
||||
/*wb = load_workbook(os.path.join(DATADIR, "genuine", "merge_range.xlsx"),
|
||||
use_iterators = False)
|
||||
|
||||
ws = wb.worksheets[0]
|
||||
|
||||
cell = ws.range("TRAP_3")
|
||||
|
||||
TS_ASSERT_EQUALS("B15", cell.get_coordinate())
|
||||
|
||||
TS_ASSERT_EQUALS(10, cell.value)*/
|
||||
}
|
||||
|
||||
void setUp()
|
||||
{
|
||||
/*wb = load_workbook(os.path.join(DATADIR, "genuine", "NameWithValueBug.xlsx"))
|
||||
ws = wb.get_sheet_by_name("Sheet1")
|
||||
make_tmpdir()*/
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
/* clean_tmpdir()*/
|
||||
}
|
||||
|
||||
void test_has_ranges()
|
||||
{
|
||||
/*ranges = wb.get_named_ranges()
|
||||
TS_ASSERT_EQUALS(["MyRef", "MySheetRef", "MySheetRef", "MySheetValue", "MySheetValue", "MyValue"], [range.name for range in ranges])*/
|
||||
}
|
||||
|
||||
void test_workbook_has_normal_range()
|
||||
{
|
||||
/*normal_range = wb.get_named_range("MyRef")
|
||||
TS_ASSERT_EQUALS("MyRef", normal_range.name)*/
|
||||
}
|
||||
|
||||
void test_workbook_has_value_range()
|
||||
{
|
||||
/*value_range = wb.get_named_range("MyValue")
|
||||
TS_ASSERT_EQUALS("MyValue", value_range.name)
|
||||
TS_ASSERT_EQUALS("9.99", value_range.value)*/
|
||||
}
|
||||
|
||||
void test_worksheet_range()
|
||||
{
|
||||
/*range = ws.range("MyRef")*/
|
||||
}
|
||||
|
||||
void test_worksheet_range_error_on_value_range()
|
||||
{
|
||||
/*assert_raises(NamedRangeException, ws.range, "MyValue")*/
|
||||
}
|
||||
|
||||
//void range_as_string(self, range, include_value = False)
|
||||
//{
|
||||
// /*void scope_as_string(range)
|
||||
// {
|
||||
// if range.scope
|
||||
// {
|
||||
// return range.scope.title
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return "Workbook"
|
||||
// }
|
||||
// }
|
||||
// retval = "%s: %s" % (range.name, scope_as_string(range))
|
||||
// if include_value :
|
||||
// if isinstance(range, NamedRange) :
|
||||
// retval += "=[range]"
|
||||
// else :
|
||||
// retval += "=" + range.value
|
||||
// return retval*/
|
||||
//}
|
||||
|
||||
void test_handles_scope()
|
||||
{
|
||||
/*ranges = wb.get_named_ranges()
|
||||
TS_ASSERT_EQUALS(["MyRef: Workbook", "MySheetRef: Sheet1", "MySheetRef: Sheet2", "MySheetValue: Sheet1", "MySheetValue: Sheet2", "MyValue: Workbook"],
|
||||
[range_as_string(range) for range in ranges])*/
|
||||
}
|
||||
|
||||
void test_can_be_saved()
|
||||
{
|
||||
/*FNAME = os.path.join(TMPDIR, "foo.xlsx")
|
||||
wb.save(FNAME)
|
||||
|
||||
wbcopy = load_workbook(FNAME)
|
||||
TS_ASSERT_EQUALS(["MyRef: Workbook=[range]", "MySheetRef: Sheet1=[range]", "MySheetRef: Sheet2=[range]", "MySheetValue: Sheet1=3.33", "MySheetValue: Sheet2=14.4", "MyValue: Workbook=9.99"],
|
||||
[range_as_string(range, include_value = True) for range in wbcopy.get_named_ranges()])*/
|
||||
}
|
||||
};
|
|
@ -3,7 +3,7 @@
|
|||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "../../misc/nullable.h"
|
||||
#include "../misc/nullable.h"
|
||||
|
||||
class NullableTestSuite : public CxxTest::TestSuite
|
||||
{
|
166
source/tests/NumberFormatTestSuite.h
Normal file
166
source/tests/NumberFormatTestSuite.h
Normal file
|
@ -0,0 +1,166 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class NumberFormatTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
NumberFormatTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//void setup_class(cls)
|
||||
//{
|
||||
// //cls.workbook = Workbook()
|
||||
// // cls.worksheet = Worksheet(cls.workbook, "Test")
|
||||
// // cls.sd = SharedDate()
|
||||
//}
|
||||
|
||||
void test_convert_date_to_julian()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(40167, sd.to_julian(2009, 12, 20))
|
||||
}
|
||||
|
||||
void test_convert_date_from_julian()
|
||||
{
|
||||
}
|
||||
|
||||
//void test_date_equal(julian, datetime)
|
||||
//{
|
||||
// //TS_ASSERT_EQUALS(sd.from_julian(julian), datetime);
|
||||
|
||||
// //date_pairs = (
|
||||
// // (40167, datetime(2009, 12, 20)),
|
||||
// // (21980, datetime(1960, 3, 5)),
|
||||
// // );
|
||||
|
||||
// //for count, dt in date_pairs
|
||||
// //{
|
||||
// // yield test_date_equal, count, dt;
|
||||
// //}
|
||||
//}
|
||||
|
||||
void test_convert_datetime_to_julian()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(40167, sd.datetime_to_julian(datetime(2009, 12, 20)))
|
||||
// TS_ASSERT_EQUALS(40196.5939815, sd.datetime_to_julian(datetime(2010, 1, 18, 14, 15, 20, 1600)))
|
||||
}
|
||||
|
||||
void test_insert_float()
|
||||
{
|
||||
//worksheet.cell("A1").value = 3.14
|
||||
// TS_ASSERT_EQUALS(Cell.TYPE_NUMERIC, worksheet.cell("A1")._data_type)
|
||||
}
|
||||
|
||||
void test_insert_percentage()
|
||||
{
|
||||
//worksheet.cell("A1").value = "3.14%"
|
||||
// TS_ASSERT_EQUALS(Cell.TYPE_NUMERIC, worksheet.cell("A1")._data_type)
|
||||
// assert_almost_equal(0.0314, worksheet.cell("A1").value)
|
||||
}
|
||||
|
||||
void test_insert_datetime()
|
||||
{
|
||||
//worksheet.cell("A1").value = date.today()
|
||||
// TS_ASSERT_EQUALS(Cell.TYPE_NUMERIC, worksheet.cell("A1")._data_type)
|
||||
}
|
||||
|
||||
void test_insert_date()
|
||||
{
|
||||
//worksheet.cell("A1").value = datetime.now()
|
||||
// TS_ASSERT_EQUALS(Cell.TYPE_NUMERIC, worksheet.cell("A1")._data_type)
|
||||
}
|
||||
|
||||
void test_internal_date()
|
||||
{
|
||||
//dt = datetime(2010, 7, 13, 6, 37, 41)
|
||||
// worksheet.cell("A3").value = dt
|
||||
// TS_ASSERT_EQUALS(40372.27616898148, worksheet.cell("A3")._value)
|
||||
}
|
||||
|
||||
void test_datetime_interpretation()
|
||||
{
|
||||
//dt = datetime(2010, 7, 13, 6, 37, 41)
|
||||
// worksheet.cell("A3").value = dt
|
||||
// TS_ASSERT_EQUALS(dt, worksheet.cell("A3").value)
|
||||
}
|
||||
|
||||
void test_date_interpretation()
|
||||
{
|
||||
//dt = date(2010, 7, 13)
|
||||
// worksheet.cell("A3").value = dt
|
||||
// TS_ASSERT_EQUALS(datetime(2010, 7, 13, 0, 0), worksheet.cell("A3").value)
|
||||
}
|
||||
|
||||
void test_number_format_style()
|
||||
{
|
||||
//worksheet.cell("A1").value = "12.6%"
|
||||
// TS_ASSERT_EQUALS(NumberFormat.FORMAT_PERCENTAGE, \
|
||||
// worksheet.cell("A1").style.number_format.format_code)
|
||||
}
|
||||
|
||||
void test_date_format_on_non_date()
|
||||
{
|
||||
//cell = worksheet.cell("A1");
|
||||
}
|
||||
|
||||
//void check_date_pair(count, date_string)
|
||||
//{
|
||||
// //cell.value = strptime(date_string, "%Y-%m-%d");
|
||||
// //TS_ASSERT_EQUALS(count, cell._value);
|
||||
|
||||
// //date_pairs = (
|
||||
// // (15, "1900-01-15"),
|
||||
// // (59, "1900-02-28"),
|
||||
// // (61, "1900-03-01"),
|
||||
// // (367, "1901-01-01"),
|
||||
// // (2958465, "9999-12-31"), );
|
||||
// //for count, date_string in date_pairs
|
||||
// //{
|
||||
// // yield check_date_pair, count, date_string;
|
||||
// //}
|
||||
//}
|
||||
|
||||
void test_1900_leap_year()
|
||||
{
|
||||
//assert_raises(ValueError, sd.from_julian, 60)
|
||||
// assert_raises(ValueError, sd.to_julian, 1900, 2, 29)
|
||||
}
|
||||
|
||||
void test_bad_date()
|
||||
{
|
||||
//void check_bad_date(year, month, day)
|
||||
//{
|
||||
// assert_raises(ValueError, sd.to_julian, year, month, day)
|
||||
//}
|
||||
|
||||
//bad_dates = ((1776, 7, 4), (1899, 12, 31), )
|
||||
// for year, month, day in bad_dates
|
||||
// {
|
||||
// yield check_bad_date, year, month, day
|
||||
// }
|
||||
}
|
||||
|
||||
void test_bad_julian_date()
|
||||
{
|
||||
//assert_raises(ValueError, sd.from_julian, -1)
|
||||
}
|
||||
|
||||
void test_mac_date()
|
||||
{
|
||||
//sd.excel_base_date = CALENDAR_MAC_1904
|
||||
|
||||
// datetuple = (2011, 10, 31)
|
||||
|
||||
// dt = date(datetuple[0], datetuple[1], datetuple[2])
|
||||
// julian = sd.to_julian(datetuple[0], datetuple[1], datetuple[2])
|
||||
// reverse = sd.from_julian(julian).date()
|
||||
// TS_ASSERT_EQUALS(dt, reverse)
|
||||
// sd.excel_base_date = CALENDAR_WINDOWS_1900
|
||||
}
|
||||
};
|
|
@ -2,21 +2,21 @@
|
|||
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/file.h>
|
||||
#include <xlnt/package.h>
|
||||
#include "../../misc/pugixml.hpp"
|
||||
#include "../packaging/file.h"
|
||||
#include "../packaging/package.h"
|
||||
#include "pugixml.hpp"
|
||||
|
||||
class ZipPackageTestSuite : public CxxTest::TestSuite
|
||||
class PackageTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
ZipPackageTestSuite()
|
||||
PackageTestSuite()
|
||||
{
|
||||
xlnt::file::copy("../../source/tests/packaging/test.zip", "../../source/tests/packaging/a.zip", true);
|
||||
xlnt::file::copy("../../source/tests/test_data/packaging/test.zip", "../../source/tests/test_data/packaging/a.zip", true);
|
||||
}
|
||||
|
||||
void test_read_text()
|
||||
{
|
||||
auto package = xlnt::package::open("../../source/tests/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
|
||||
auto package = xlnt::package::open("../../source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
|
||||
TS_ASSERT_DIFFERS(package, nullptr);
|
||||
|
||||
auto part_1 = package.get_part(xlnt::uri("a.txt", xlnt::uri_kind::Relative));
|
||||
|
@ -29,7 +29,7 @@ public:
|
|||
void test_write_text()
|
||||
{
|
||||
{
|
||||
auto package = xlnt::package::open("../../source/tests/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
|
||||
auto package = xlnt::package::open("../../source/test_data/tests/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
|
||||
TS_ASSERT_DIFFERS(package, nullptr);
|
||||
|
||||
auto part_1 = package.get_part(xlnt::uri("a.txt", xlnt::uri_kind::Relative));
|
||||
|
@ -39,7 +39,7 @@ public:
|
|||
}
|
||||
|
||||
{
|
||||
auto package = xlnt::package::open("../../source/tests/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
|
||||
auto package = xlnt::package::open("../../source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
|
||||
TS_ASSERT_DIFFERS(package, nullptr);
|
||||
|
||||
auto part_1 = package.get_part(xlnt::uri("a.txt", xlnt::uri_kind::Relative));
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
|
||||
void test_read_xml()
|
||||
{
|
||||
auto package = xlnt::package::open("../../source/tests/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
|
||||
auto package = xlnt::package::open("../../source/tests/test_data/packaging/a.zip", xlnt::file_mode::Open, xlnt::file_access::ReadWrite);
|
||||
TS_ASSERT_DIFFERS(package, nullptr);
|
||||
|
||||
auto part_2 = package.get_part(xlnt::uri("a.xml", xlnt::uri_kind::Relative));
|
28
source/tests/PasswordHashTestSuite.h
Normal file
28
source/tests/PasswordHashTestSuite.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class PasswordHashTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
PasswordHashTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_hasher()
|
||||
{
|
||||
//TS_ASSERT_EQUALS("CBEB", hash_password("test"));
|
||||
}
|
||||
|
||||
void test_sheet_protection()
|
||||
{
|
||||
//protection = SheetProtection();
|
||||
//protection.password = "test";
|
||||
//TS_ASSERT_EQUALS("CBEB", protection.password);
|
||||
}
|
||||
};
|
117
source/tests/PropsTestSuite.h
Normal file
117
source/tests/PropsTestSuite.h
Normal file
|
@ -0,0 +1,117 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class PropsTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
PropsTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_1()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//class TestReaderProps
|
||||
//{
|
||||
// void setup_class(cls)
|
||||
// {
|
||||
// cls.genuine_filename = os.path.join(DATADIR, "genuine", "empty.xlsx");
|
||||
// cls.archive = ZipFile(cls.genuine_filename, "r", ZIP_DEFLATED);
|
||||
// }
|
||||
|
||||
// void teardown_class(cls)
|
||||
// {
|
||||
// cls.archive.close();
|
||||
// }
|
||||
//};
|
||||
|
||||
void test_read_properties_core()
|
||||
{
|
||||
//content = archive.read(ARC_CORE)
|
||||
// prop = read_properties_core(content)
|
||||
// TS_ASSERT_EQUALS(prop.creator, "*.*")
|
||||
// eacute = chr(233)
|
||||
// TS_ASSERT_EQUALS(prop.last_modified_by, "Aur" + eacute + "lien Camp" + eacute + "as")
|
||||
// TS_ASSERT_EQUALS(prop.created, datetime(2010, 4, 9, 20, 43, 12))
|
||||
// TS_ASSERT_EQUALS(prop.modified, datetime(2011, 2, 9, 13, 49, 32))
|
||||
}
|
||||
|
||||
void test_read_sheets_titles()
|
||||
{
|
||||
//content = archive.read(ARC_WORKBOOK);
|
||||
//sheet_titles = read_sheets_titles(content);
|
||||
//TS_ASSERT_EQUALS(sheet_titles, \
|
||||
// ["Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"]);
|
||||
}
|
||||
|
||||
// Just tests that the correct date / time format is returned from LibreOffice saved version
|
||||
|
||||
//void setup_class(cls)
|
||||
//{
|
||||
// cls.genuine_filename = os.path.join(DATADIR, "genuine", "empty_libre.xlsx")
|
||||
// cls.archive = ZipFile(cls.genuine_filename, "r", ZIP_DEFLATED)
|
||||
//}
|
||||
|
||||
//void teardown_class(cls)
|
||||
//{
|
||||
// cls.archive.close()
|
||||
//}
|
||||
|
||||
void test_read_properties_core2()
|
||||
{
|
||||
//content = archive.read(ARC_CORE)
|
||||
// prop = read_properties_core(content)
|
||||
// TS_ASSERT_EQUALS(prop.excel_base_date, CALENDAR_WINDOWS_1900)
|
||||
}
|
||||
|
||||
void test_read_sheets_titles2()
|
||||
{
|
||||
//content = archive.read(ARC_WORKBOOK)
|
||||
// sheet_titles = read_sheets_titles(content)
|
||||
// TS_ASSERT_EQUALS(sheet_titles, \
|
||||
// ["Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"])
|
||||
}
|
||||
|
||||
//void setup_class(cls)
|
||||
//{
|
||||
// make_tmpdir()
|
||||
// cls.tmp_filename = os.path.join(TMPDIR, "test.xlsx")
|
||||
// cls.prop = DocumentProperties()
|
||||
//}
|
||||
|
||||
//void teardown_class(cls)
|
||||
//{
|
||||
// clean_tmpdir()
|
||||
//}
|
||||
|
||||
void test_write_properties_core()
|
||||
{
|
||||
//prop.creator = "TEST_USER"
|
||||
// prop.last_modified_by = "SOMEBODY"
|
||||
// prop.created = datetime(2010, 4, 1, 20, 30, 00)
|
||||
// prop.modified = datetime(2010, 4, 5, 14, 5, 30)
|
||||
// content = write_properties_core(prop)
|
||||
// assert_equals_file_content(
|
||||
// os.path.join(DATADIR, "writer", "expected", "core.xml"),
|
||||
// content)
|
||||
}
|
||||
|
||||
void test_write_properties_app()
|
||||
{
|
||||
//wb = Workbook()
|
||||
// wb.create_sheet()
|
||||
// wb.create_sheet()
|
||||
// content = write_properties_app(wb)
|
||||
// assert_equals_file_content(
|
||||
// os.path.join(DATADIR, "writer", "expected", "app.xml"),
|
||||
// content)
|
||||
}
|
||||
};
|
197
source/tests/ReadTestSuite.h
Normal file
197
source/tests/ReadTestSuite.h
Normal file
|
@ -0,0 +1,197 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class ReadTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
ReadTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_read_standalone_worksheet()
|
||||
{
|
||||
//path = os.path.join(DATADIR, "reader", "sheet2.xml")
|
||||
// ws = None
|
||||
// handle = open(path)
|
||||
// try :
|
||||
// ws = read_worksheet(handle.read(), DummyWb(),
|
||||
// "Sheet 2", {1: "hello"}, {1: Style()})
|
||||
// finally :
|
||||
// handle.close()
|
||||
// assert isinstance(ws, Worksheet)
|
||||
// TS_ASSERT_EQUALS(ws.cell("G5").value, "hello")
|
||||
// TS_ASSERT_EQUALS(ws.cell("D30").value, 30)
|
||||
// TS_ASSERT_EQUALS(ws.cell("K9").value, 0.09)
|
||||
}
|
||||
|
||||
void test_read_standard_workbook()
|
||||
{
|
||||
//path = os.path.join(DATADIR, "genuine", "empty.xlsx")
|
||||
// wb = load_workbook(path)
|
||||
// assert isinstance(wb, Workbook)
|
||||
}
|
||||
|
||||
void test_read_standard_workbook_from_fileobj()
|
||||
{
|
||||
//path = os.path.join(DATADIR, "genuine", "empty.xlsx")
|
||||
// fo = open(path, mode = "rb")
|
||||
// wb = load_workbook(fo)
|
||||
// assert isinstance(wb, Workbook)
|
||||
}
|
||||
|
||||
void test_read_worksheet()
|
||||
{
|
||||
//path = os.path.join(DATADIR, "genuine", "empty.xlsx")
|
||||
// wb = load_workbook(path)
|
||||
// sheet2 = wb.get_sheet_by_name("Sheet2 - Numbers")
|
||||
// assert isinstance(sheet2, Worksheet)
|
||||
// TS_ASSERT_EQUALS("This is cell G5", sheet2.cell("G5").value)
|
||||
// TS_ASSERT_EQUALS(18, sheet2.cell("D18").value)
|
||||
}
|
||||
|
||||
void test_read_nostring_workbook()
|
||||
{
|
||||
//genuine_wb = os.path.join(DATADIR, "genuine", "empty-no-string.xlsx")
|
||||
// wb = load_workbook(genuine_wb)
|
||||
// assert isinstance(wb, Workbook)
|
||||
}
|
||||
|
||||
// @raises(InvalidFileException)
|
||||
void test_read_empty_file()
|
||||
{
|
||||
//null_file = os.path.join(DATADIR, "reader", "null_file.xlsx")
|
||||
// wb = load_workbook(null_file)
|
||||
}
|
||||
|
||||
//@raises(InvalidFileException)
|
||||
void test_read_empty_archive()
|
||||
{
|
||||
//null_file = os.path.join(DATADIR, "reader", "null_archive.xlsx")
|
||||
// wb = load_workbook(null_file)
|
||||
}
|
||||
|
||||
void test_read_dimension()
|
||||
{
|
||||
//path = os.path.join(DATADIR, "reader", "sheet2.xml")
|
||||
|
||||
// dimension = None
|
||||
// handle = open(path)
|
||||
// try :
|
||||
// dimension = read_dimension(xml_source = handle.read())
|
||||
// finally :
|
||||
// handle.close()
|
||||
|
||||
// TS_ASSERT_EQUALS(("D", 1, "K", 30), dimension)
|
||||
}
|
||||
|
||||
void test_calculate_dimension_iter()
|
||||
{
|
||||
//path = os.path.join(DATADIR, "genuine", "empty.xlsx")
|
||||
// wb = load_workbook(filename = path, use_iterators = True)
|
||||
// sheet2 = wb.get_sheet_by_name("Sheet2 - Numbers")
|
||||
// dimensions = sheet2.calculate_dimension()
|
||||
// TS_ASSERT_EQUALS("%s%s:%s%s" % ("D", 1, "K", 30), dimensions)
|
||||
}
|
||||
|
||||
void test_get_highest_row_iter()
|
||||
{
|
||||
//path = os.path.join(DATADIR, "genuine", "empty.xlsx")
|
||||
// wb = load_workbook(filename = path, use_iterators = True)
|
||||
// sheet2 = wb.get_sheet_by_name("Sheet2 - Numbers")
|
||||
// max_row = sheet2.get_highest_row()
|
||||
// TS_ASSERT_EQUALS(30, max_row)
|
||||
}
|
||||
|
||||
void test_read_workbook_with_no_properties()
|
||||
{
|
||||
//genuine_wb = os.path.join(DATADIR, "genuine", \
|
||||
// "empty_with_no_properties.xlsx")
|
||||
// wb = load_workbook(filename = genuine_wb)
|
||||
}
|
||||
|
||||
//void setup_class_with_styles(cls)
|
||||
//{
|
||||
// //cls.genuine_wb = os.path.join(DATADIR, "genuine", \
|
||||
// // "empty-with-styles.xlsx")
|
||||
// // wb = load_workbook(cls.genuine_wb)
|
||||
// // cls.ws = wb.get_sheet_by_name("Sheet1")
|
||||
//}
|
||||
|
||||
void test_read_general_style()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(ws.cell("A1").style.number_format.format_code,
|
||||
// NumberFormat.FORMAT_GENERAL)
|
||||
}
|
||||
|
||||
void test_read_date_style()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(ws.cell("A2").style.number_format.format_code,
|
||||
// NumberFormat.FORMAT_DATE_XLSX14)
|
||||
}
|
||||
|
||||
void test_read_number_style()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(ws.cell("A3").style.number_format.format_code,
|
||||
// NumberFormat.FORMAT_NUMBER_00)
|
||||
}
|
||||
|
||||
void test_read_time_style()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(ws.cell("A4").style.number_format.format_code,
|
||||
// NumberFormat.FORMAT_DATE_TIME3)
|
||||
}
|
||||
|
||||
void test_read_percentage_style()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(ws.cell("A5").style.number_format.format_code,
|
||||
// NumberFormat.FORMAT_PERCENTAGE_00)
|
||||
}
|
||||
|
||||
//void setup_class_base_date_format(cls)
|
||||
//{
|
||||
// //mac_wb_path = os.path.join(DATADIR, "reader", "date_1904.xlsx")
|
||||
// // cls.mac_wb = load_workbook(mac_wb_path)
|
||||
// // cls.mac_ws = cls.mac_wb.get_sheet_by_name("Sheet1")
|
||||
|
||||
// // win_wb_path = os.path.join(DATADIR, "reader", "date_1900.xlsx")
|
||||
// // cls.win_wb = load_workbook(win_wb_path)
|
||||
// // cls.win_ws = cls.win_wb.get_sheet_by_name("Sheet1")
|
||||
//}
|
||||
|
||||
void test_read_win_base_date()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(win_wb.properties.excel_base_date, CALENDAR_WINDOWS_1900)
|
||||
}
|
||||
|
||||
void test_read_mac_base_date()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(mac_wb.properties.excel_base_date, CALENDAR_MAC_1904)
|
||||
}
|
||||
|
||||
void test_read_date_style_mac()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(mac_ws.cell("A1").style.number_format.format_code,
|
||||
// NumberFormat.FORMAT_DATE_XLSX14)
|
||||
}
|
||||
|
||||
void test_read_date_style_win()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(win_ws.cell("A1").style.number_format.format_code,
|
||||
// NumberFormat.FORMAT_DATE_XLSX14)
|
||||
}
|
||||
|
||||
void test_read_date_value()
|
||||
{
|
||||
//datetuple = (2011, 10, 31)
|
||||
// dt = datetime(datetuple[0], datetuple[1], datetuple[2])
|
||||
// TS_ASSERT_EQUALS(mac_ws.cell("A1").value, dt)
|
||||
// TS_ASSERT_EQUALS(win_ws.cell("A1").value, dt)
|
||||
// TS_ASSERT_EQUALS(mac_ws.cell("A1").value, win_ws.cell("A1").value)
|
||||
}
|
||||
};
|
61
source/tests/StringsTestSuite.h
Normal file
61
source/tests/StringsTestSuite.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class StringsTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
StringsTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_create_string_table()
|
||||
{
|
||||
//wb = Workbook()
|
||||
// ws = wb.create_sheet()
|
||||
// ws.cell("B12").value = "hello"
|
||||
// ws.cell("B13").value = "world"
|
||||
// ws.cell("D28").value = "hello"
|
||||
// table = create_string_table(wb)
|
||||
// TS_ASSERT_EQUALS({"hello": 1, "world" : 0}, table)
|
||||
}
|
||||
|
||||
void test_read_string_table()
|
||||
{
|
||||
//handle = open(os.path.join(DATADIR, "reader", "sharedStrings.xml"))
|
||||
// try :
|
||||
// content = handle.read()
|
||||
// string_table = read_string_table(content)
|
||||
// TS_ASSERT_EQUALS({0: "This is cell A1 in Sheet 1", 1 : "This is cell G5"}, string_table)
|
||||
// finally :
|
||||
// handle.close()
|
||||
}
|
||||
|
||||
void test_empty_string()
|
||||
{
|
||||
//handle = open(os.path.join(DATADIR, "reader", "sharedStrings-emptystring.xml"))
|
||||
// try :
|
||||
// content = handle.read()
|
||||
// string_table = read_string_table(content)
|
||||
// TS_ASSERT_EQUALS({0: "Testing empty cell", 1 : ""}, string_table)
|
||||
// finally :
|
||||
// handle.close()
|
||||
}
|
||||
|
||||
void test_formatted_string_table()
|
||||
{
|
||||
//handle = open(os.path.join(DATADIR, "reader", "shared-strings-rich.xml"))
|
||||
// try :
|
||||
// content = handle.read()
|
||||
// string_table = read_string_table(content)
|
||||
// TS_ASSERT_EQUALS({0: "Welcome", 1 : "to the best shop in town",
|
||||
// 2 : " let"s play "}, string_table)
|
||||
// finally :
|
||||
// handle.close()
|
||||
}
|
||||
};
|
204
source/tests/StyleTestSuite.h
Normal file
204
source/tests/StyleTestSuite.h
Normal file
|
@ -0,0 +1,204 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class StyleTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
StyleTestSuite()
|
||||
{
|
||||
}
|
||||
/*
|
||||
now = datetime.datetime.now();
|
||||
cls.workbook = Workbook();
|
||||
cls.worksheet = cls.workbook.create_sheet();
|
||||
cls.worksheet.cell(coordinate = "A1").value = "12.34%";
|
||||
cls.worksheet.cell(coordinate = "B4").value = now;
|
||||
cls.worksheet.cell(coordinate = "B5").value = now;
|
||||
cls.worksheet.cell(coordinate = "C14").value = "This is a test";
|
||||
cls.worksheet.cell(coordinate = "D9").value = "31.31415";
|
||||
cls.worksheet.cell(coordinate = "D9").style.number_format.format_code = \
|
||||
NumberFormat.FORMAT_NUMBER_00;
|
||||
cls.writer = StyleWriter(cls.workbook);
|
||||
}
|
||||
*/
|
||||
|
||||
void test_create_style_table()
|
||||
{
|
||||
//TS_ASSERT_EQUALS(3, len(writer.style_table));
|
||||
}
|
||||
|
||||
void test_write_style_table()
|
||||
{
|
||||
//reference_file = os.path.join(DATADIR, "writer", "expected", "simple-styles.xml");
|
||||
//assert_equals_file_content(reference_file, writer.write_table());
|
||||
}
|
||||
|
||||
void setUp_writer()
|
||||
{
|
||||
//workbook = Workbook()
|
||||
// worksheet = workbook.create_sheet()
|
||||
}
|
||||
|
||||
void test_no_style()
|
||||
{
|
||||
|
||||
//w = StyleWriter(workbook)
|
||||
// TS_ASSERT_EQUALS(0, len(w.style_table))
|
||||
}
|
||||
|
||||
void test_nb_style()
|
||||
{
|
||||
//for i in range(1, 6)
|
||||
//{
|
||||
// worksheet.cell(row = 1, column = i).style.font.size += i
|
||||
// w = StyleWriter(workbook)
|
||||
// TS_ASSERT_EQUALS(5, len(w.style_table))
|
||||
|
||||
// worksheet.cell("A10").style.borders.top = Border.BORDER_THIN
|
||||
// w = StyleWriter(workbook)
|
||||
// TS_ASSERT_EQUALS(6, len(w.style_table))
|
||||
//}
|
||||
}
|
||||
|
||||
void test_style_unicity()
|
||||
{
|
||||
//for i in range(1, 6)
|
||||
//{
|
||||
// worksheet.cell(row = 1, column = i).style.font.bold = True
|
||||
// w = StyleWriter(workbook)
|
||||
// TS_ASSERT_EQUALS(1, len(w.style_table))
|
||||
//}
|
||||
}
|
||||
|
||||
void test_fonts()
|
||||
{
|
||||
//worksheet.cell("A1").style.font.size = 12
|
||||
// worksheet.cell("A1").style.font.bold = True
|
||||
// w = StyleWriter(workbook)
|
||||
// w._write_fonts()
|
||||
// TS_ASSERT_EQUALS(get_xml(w._root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="2"><font><sz val="11" /><color theme="1" /><name val="Calibri" /><family val="2" /><scheme val="minor" /></font><font><sz val="12" /><color rgb="FF000000" /><name val="Calibri" /><family val="2" /><b /><u val="none" /></font></fonts></styleSheet>")
|
||||
|
||||
// worksheet.cell("A1").style.font.underline = Font.UNDERLINE_SINGLE
|
||||
// w = StyleWriter(workbook)
|
||||
// w._write_fonts()
|
||||
// TS_ASSERT_EQUALS(get_xml(w._root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="2"><font><sz val="11" /><color theme="1" /><name val="Calibri" /><family val="2" /><scheme val="minor" /></font><font><sz val="12" /><color rgb="FF000000" /><name val="Calibri" /><family val="2" /><b /><u /></font></fonts></styleSheet>")
|
||||
}
|
||||
|
||||
void test_fills()
|
||||
{
|
||||
//worksheet.cell("A1").style.fill.fill_type = "solid"
|
||||
// worksheet.cell("A1").style.fill.start_color.index = Color.DARKYELLOW
|
||||
// w = StyleWriter(workbook)
|
||||
// w._write_fills()
|
||||
// TS_ASSERT_EQUALS(get_xml(w._root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fills count="3"><fill><patternFill patternType="none" /></fill><fill><patternFill patternType="gray125" /></fill><fill><patternFill patternType="solid"><fgColor rgb="FF808000" /></patternFill></fill></fills></styleSheet>")
|
||||
}
|
||||
|
||||
void test_borders()
|
||||
{
|
||||
//worksheet.cell("A1").style.borders.top.border_style = Border.BORDER_THIN
|
||||
// worksheet.cell("A1").style.borders.top.color.index = Color.DARKYELLOW
|
||||
// w = StyleWriter(workbook)
|
||||
// w._write_borders()
|
||||
// TS_ASSERT_EQUALS(get_xml(w._root), "<?xml version=\"1.0\" encoding=\"" + utf8_xml_str + "\"?><styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><borders count="2"><border><left /><right /><top /><bottom /><diagonal /></border><border><left style="none"><color rgb="FF000000" /></left><right style="none"><color rgb="FF000000" /></right><top style="thin"><color rgb="FF808000" /></top><bottom style="none"><color rgb="FF000000" /></bottom><diagonal style="none"><color rgb="FF000000" /></diagonal></border></borders></styleSheet>")
|
||||
}
|
||||
|
||||
void test_write_cell_xfs_1()
|
||||
{
|
||||
//worksheet.cell("A1").style.font.size = 12
|
||||
// w = StyleWriter(workbook)
|
||||
// ft = w._write_fonts()
|
||||
// nft = w._write_number_formats()
|
||||
// w._write_cell_xfs(nft, ft, {}, {})
|
||||
// xml = get_xml(w._root)
|
||||
// ok_("applyFont="1"" in xml)
|
||||
// ok_("applyFillId="1"" not in xml)
|
||||
// ok_("applyBorder="1"" not in xml)
|
||||
// ok_("applyAlignment="1"" not in xml)
|
||||
}
|
||||
|
||||
void test_alignment()
|
||||
{
|
||||
//worksheet.cell("A1").style.alignment.horizontal = "center"
|
||||
// worksheet.cell("A1").style.alignment.vertical = "center"
|
||||
// w = StyleWriter(workbook)
|
||||
// nft = w._write_number_formats()
|
||||
// w._write_cell_xfs(nft, {}, {}, {})
|
||||
// xml = get_xml(w._root)
|
||||
// ok_("applyAlignment="1"" in xml)
|
||||
// ok_("horizontal="center"" in xml)
|
||||
// ok_("vertical="center"" in xml)
|
||||
}
|
||||
|
||||
void test_alignment_rotation()
|
||||
{
|
||||
//worksheet.cell("A1").style.alignment.vertical = "center"
|
||||
// worksheet.cell("A1").style.alignment.text_rotation = 90
|
||||
// worksheet.cell("A2").style.alignment.vertical = "center"
|
||||
// worksheet.cell("A2").style.alignment.text_rotation = 135
|
||||
// w = StyleWriter(workbook)
|
||||
// nft = w._write_number_formats()
|
||||
// w._write_cell_xfs(nft, {}, {}, {})
|
||||
// xml = get_xml(w._root)
|
||||
// ok_("textRotation="90"" in xml)
|
||||
// ok_("textRotation="135"" in xml)
|
||||
}
|
||||
|
||||
|
||||
void test_format_comparisions()
|
||||
{
|
||||
//format1 = NumberFormat()
|
||||
// format2 = NumberFormat()
|
||||
// format3 = NumberFormat()
|
||||
// format1.format_code = "m/d/yyyy"
|
||||
// format2.format_code = "m/d/yyyy"
|
||||
// format3.format_code = "mm/dd/yyyy"
|
||||
// assert not format1 < format2
|
||||
// assert format1 < format3
|
||||
// assert format1 == format2
|
||||
// assert format1 != format3
|
||||
}
|
||||
|
||||
|
||||
void test_builtin_format()
|
||||
{
|
||||
//format = NumberFormat()
|
||||
// format.format_code = "0.00"
|
||||
// TS_ASSERT_EQUALS(format.builtin_format_code(2), format._format_code)
|
||||
}
|
||||
|
||||
|
||||
void test_read_style()
|
||||
{
|
||||
//reference_file = os.path.join(DATADIR, "reader", "simple-styles.xml")
|
||||
|
||||
// handle = open(reference_file, "r")
|
||||
// try :
|
||||
// content = handle.read()
|
||||
// finally :
|
||||
// handle.close()
|
||||
// style_table = read_style_table(content)
|
||||
// TS_ASSERT_EQUALS(4, len(style_table))
|
||||
// TS_ASSERT_EQUALS(NumberFormat._BUILTIN_FORMATS[9],
|
||||
// style_table[1].number_format.format_code)
|
||||
// TS_ASSERT_EQUALS("yyyy-mm-dd", style_table[2].number_format.format_code)
|
||||
}
|
||||
|
||||
|
||||
void test_read_cell_style()
|
||||
{
|
||||
//reference_file = os.path.join(
|
||||
// DATADIR, "reader", "empty-workbook-styles.xml")
|
||||
// handle = open(reference_file, "r")
|
||||
// try :
|
||||
// content = handle.read()
|
||||
// finally :
|
||||
// handle.close()
|
||||
// style_table = read_style_table(content)
|
||||
// TS_ASSERT_EQUALS(2, len(style_table))
|
||||
}
|
||||
};
|
23
source/tests/ThemeTestSuite.h
Normal file
23
source/tests/ThemeTestSuite.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class ThemeTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
ThemeTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_write_theme()
|
||||
{
|
||||
//content = write_theme();
|
||||
//assert_equals_file_content(
|
||||
// os.path.join(DATADIR, "writer", "expected", "theme1.xml"), content);
|
||||
}
|
||||
};
|
22
source/tests/UnicodeTestSuite.h
Normal file
22
source/tests/UnicodeTestSuite.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class UnicodeTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
UnicodeTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_read_workbook_with_unicode_character()
|
||||
{
|
||||
//unicode_wb = os.path.join(DATADIR, "genuine", "unicode.xlsx");
|
||||
//wb = load_workbook(filename = unicode_wb);
|
||||
}
|
||||
};
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include <xlnt/uri.h>
|
||||
#include "../packaging/uri.h"
|
||||
|
||||
class uriTestSuite : public CxxTest::TestSuite
|
||||
{
|
384
source/tests/WorkbookTestSuite.h
Normal file
384
source/tests/WorkbookTestSuite.h
Normal file
|
@ -0,0 +1,384 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class WorkbookTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
WorkbookTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_get_active_sheet()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//active_sheet = wb.get_active_sheet();
|
||||
//TS_ASSERT_EQUALS(active_sheet, wb.worksheets[0]);
|
||||
}
|
||||
|
||||
void test_create_sheet()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//new_sheet = wb.create_sheet(0);
|
||||
//TS_ASSERT_EQUALS(new_sheet, wb.worksheets[0]);
|
||||
}
|
||||
|
||||
void test_create_sheet_with_name()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//new_sheet = wb.create_sheet(0, title = "LikeThisName");
|
||||
//TS_ASSERT_EQUALS(new_sheet, wb.worksheets[0]);
|
||||
}
|
||||
|
||||
void test_add_correct_sheet()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//new_sheet = wb.create_sheet(0);
|
||||
//wb.add_sheet(new_sheet);
|
||||
//TS_ASSERT_EQUALS(new_sheet, wb.worksheets[2]);
|
||||
}
|
||||
|
||||
void test_add_incorrect_sheet()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//wb.add_sheet("Test");
|
||||
}
|
||||
|
||||
void test_create_sheet_readonly()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//wb._set_optimized_read();
|
||||
//wb.create_sheet();
|
||||
}
|
||||
|
||||
void test_remove_sheet()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//new_sheet = wb.create_sheet(0);
|
||||
//wb.remove_sheet(new_sheet);
|
||||
//assert new_sheet not in wb.worksheets;
|
||||
}
|
||||
|
||||
void test_get_sheet_by_name()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//new_sheet = wb.create_sheet();
|
||||
//title = "my sheet";
|
||||
//new_sheet.title = title;
|
||||
//found_sheet = wb.get_sheet_by_name(title);
|
||||
//TS_ASSERT_EQUALS(new_sheet, found_sheet);
|
||||
}
|
||||
|
||||
void test_get_index2()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//new_sheet = wb.create_sheet(0);
|
||||
//sheet_index = wb.get_index(new_sheet);
|
||||
//TS_ASSERT_EQUALS(sheet_index, 0);
|
||||
}
|
||||
|
||||
void test_get_sheet_names()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//names = ["Sheet", "Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5"];
|
||||
//for(auto count : range(5))
|
||||
//{
|
||||
// wb.create_sheet(0)
|
||||
// actual_names = wb.get_sheet_names()
|
||||
// TS_ASSERT_EQUALS(sorted(actual_names), sorted(names))
|
||||
//}
|
||||
}
|
||||
|
||||
void test_get_named_ranges2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
TS_ASSERT_EQUALS(wb.get_named_ranges(), wb._named_ranges);*/
|
||||
}
|
||||
void test_get_active_sheet2()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//active_sheet = wb.get_active_sheet();
|
||||
//TS_ASSERT_EQUALS(active_sheet, wb.worksheets[0]);
|
||||
}
|
||||
|
||||
void test_create_sheet2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet(0);
|
||||
TS_ASSERT_EQUALS(new_sheet, wb.worksheets[0]);*/
|
||||
}
|
||||
|
||||
void test_create_sheet_with_name2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet(0, title = "LikeThisName");
|
||||
TS_ASSERT_EQUALS(new_sheet, wb.worksheets[0]);*/
|
||||
}
|
||||
|
||||
void test_add_correct_sheet2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet(0);
|
||||
wb.add_sheet(new_sheet);
|
||||
TS_ASSERT_EQUALS(new_sheet, wb.worksheets[2]);*/
|
||||
}
|
||||
|
||||
//@raises(AssertionError)
|
||||
void test_add_incorrect_sheet2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
wb.add_sheet("Test");*/
|
||||
}
|
||||
|
||||
//@raises(ReadOnlyWorkbookException)
|
||||
void test_create_sheet_readonly2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
wb._set_optimized_read();
|
||||
wb.create_sheet();*/
|
||||
}
|
||||
|
||||
void test_remove_sheet2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet(0);
|
||||
wb.remove_sheet(new_sheet);
|
||||
assert new_sheet not in wb.worksheets;*/
|
||||
}
|
||||
|
||||
void test_get_sheet_by_name2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet();
|
||||
title = "my sheet";
|
||||
new_sheet.title = title;
|
||||
found_sheet = wb.get_sheet_by_name(title);
|
||||
TS_ASSERT_EQUALS(new_sheet, found_sheet);*/
|
||||
}
|
||||
|
||||
void test_get_index()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet(0);
|
||||
sheet_index = wb.get_index(new_sheet);
|
||||
TS_ASSERT_EQUALS(sheet_index, 0);*/
|
||||
}
|
||||
|
||||
void test_get_sheet_names2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
names = ["Sheet", "Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5"];
|
||||
for(auto count in range(5))
|
||||
{
|
||||
wb.create_sheet(0)
|
||||
actual_names = wb.get_sheet_names()
|
||||
TS_ASSERT_EQUALS(sorted(actual_names), sorted(names))
|
||||
}*/
|
||||
}
|
||||
|
||||
void test_get_named_ranges()
|
||||
{
|
||||
/* wb = Workbook();
|
||||
TS_ASSERT_EQUALS(wb.get_named_ranges(), wb._named_ranges);*/
|
||||
}
|
||||
|
||||
void test_add_named_range()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet();
|
||||
named_range = NamedRange("test_nr", [(new_sheet, "A1")]);
|
||||
wb.add_named_range(named_range);
|
||||
named_ranges_list = wb.get_named_ranges();
|
||||
assert named_range in named_ranges_list;*/
|
||||
}
|
||||
|
||||
void test_get_named_range2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet();
|
||||
named_range = NamedRange("test_nr", [(new_sheet, "A1")]);
|
||||
wb.add_named_range(named_range);
|
||||
found_named_range = wb.get_named_range("test_nr");
|
||||
TS_ASSERT_EQUALS(named_range, found_named_range);*/
|
||||
}
|
||||
|
||||
void test_remove_named_range2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet();
|
||||
named_range = NamedRange("test_nr", [(new_sheet, "A1")]);
|
||||
wb.add_named_range(named_range);
|
||||
wb.remove_named_range(named_range);
|
||||
named_ranges_list = wb.get_named_ranges();
|
||||
assert named_range not in named_ranges_list;*/
|
||||
}
|
||||
|
||||
//@with_setup(setup = make_tmpdir, teardown = clean_tmpdir)
|
||||
void test_add_local_named_range2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet();
|
||||
named_range = NamedRange("test_nr", [(new_sheet, "A1")]);
|
||||
named_range.scope = new_sheet;
|
||||
wb.add_named_range(named_range);
|
||||
dest_filename = osp.join(TMPDIR, "local_named_range_book.xlsx");
|
||||
wb.save(dest_filename);*/
|
||||
}
|
||||
|
||||
//@with_setup(setup = make_tmpdir, teardown = clean_tmpdir)
|
||||
void test_write_regular_date()
|
||||
{
|
||||
/*today = datetime.datetime(2010, 1, 18, 14, 15, 20, 1600);
|
||||
|
||||
book = Workbook();
|
||||
sheet = book.get_active_sheet();
|
||||
sheet.cell("A1").value = today;
|
||||
dest_filename = osp.join(TMPDIR, "date_read_write_issue.xlsx");
|
||||
book.save(dest_filename);
|
||||
|
||||
test_book = load_workbook(dest_filename);
|
||||
test_sheet = test_book.get_active_sheet();
|
||||
|
||||
TS_ASSERT_EQUALS(test_sheet.cell("A1").value, today);*/
|
||||
}
|
||||
|
||||
// @with_setup(setup = make_tmpdir, teardown = clean_tmpdir)
|
||||
void test_write_regular_float()
|
||||
{
|
||||
/*float_value = 1.0 / 3.0;
|
||||
book = Workbook();
|
||||
sheet = book.get_active_sheet();
|
||||
sheet.cell("A1").value = float_value;
|
||||
dest_filename = osp.join(TMPDIR, "float_read_write_issue.xlsx");
|
||||
book.save(dest_filename);
|
||||
|
||||
test_book = load_workbook(dest_filename);
|
||||
test_sheet = test_book.get_active_sheet();
|
||||
|
||||
TS_ASSERT_EQUALS(test_sheet.cell("A1").value, float_value);*/
|
||||
}
|
||||
|
||||
//@raises(UnicodeDecodeError)
|
||||
void test_bad_encoding2()
|
||||
{
|
||||
/*pound = chr(163);
|
||||
test_string = ("Compound Value (" + pound + ")").encode("latin1");
|
||||
|
||||
utf_book = Workbook();
|
||||
utf_sheet = utf_book.get_active_sheet();
|
||||
utf_sheet.cell("A1").value = test_string;*/
|
||||
}
|
||||
|
||||
void test_good_encoding2()
|
||||
{
|
||||
/*pound = chr(163);
|
||||
test_string = ("Compound Value (" + pound + ")").encode("latin1");
|
||||
|
||||
lat_book = Workbook(encoding = "latin1");
|
||||
lat_sheet = lat_book.get_active_sheet();
|
||||
lat_sheet.cell("A1").value = test_string;*/
|
||||
}
|
||||
|
||||
void test_add_named_range2()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet();
|
||||
named_range = NamedRange("test_nr", [(new_sheet, "A1")]);
|
||||
wb.add_named_range(named_range);
|
||||
named_ranges_list = wb.get_named_ranges();
|
||||
assert named_range in named_ranges_list;*/
|
||||
}
|
||||
|
||||
void test_get_named_range()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet();
|
||||
named_range = NamedRange("test_nr", [(new_sheet, "A1")]);
|
||||
wb.add_named_range(named_range);
|
||||
found_named_range = wb.get_named_range("test_nr");
|
||||
TS_ASSERT_EQUALS(named_range, found_named_range);*/
|
||||
}
|
||||
|
||||
void test_remove_named_range()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet();
|
||||
named_range = NamedRange("test_nr", [(new_sheet, "A1")]);
|
||||
wb.add_named_range(named_range);
|
||||
wb.remove_named_range(named_range);
|
||||
named_ranges_list = wb.get_named_ranges();
|
||||
assert named_range not in named_ranges_list;*/
|
||||
}
|
||||
|
||||
//@with_setup(setup = make_tmpdir, teardown = clean_tmpdir)
|
||||
void test_add_local_named_range()
|
||||
{
|
||||
/*wb = Workbook();
|
||||
new_sheet = wb.create_sheet();
|
||||
named_range = NamedRange("test_nr", [(new_sheet, "A1")]);
|
||||
named_range.scope = new_sheet;
|
||||
wb.add_named_range(named_range);
|
||||
dest_filename = osp.join(TMPDIR, "local_named_range_book.xlsx");
|
||||
wb.save(dest_filename);*/
|
||||
}
|
||||
|
||||
|
||||
// @with_setup(setup = make_tmpdir, teardown = clean_tmpdir)
|
||||
void test_write_regular_date2()
|
||||
{
|
||||
/*today = datetime.datetime(2010, 1, 18, 14, 15, 20, 1600);
|
||||
|
||||
book = Workbook();
|
||||
sheet = book.get_active_sheet();
|
||||
sheet.cell("A1").value = today;
|
||||
dest_filename = osp.join(TMPDIR, "date_read_write_issue.xlsx");
|
||||
book.save(dest_filename);
|
||||
|
||||
test_book = load_workbook(dest_filename);
|
||||
test_sheet = test_book.get_active_sheet();
|
||||
|
||||
TS_ASSERT_EQUALS(test_sheet.cell("A1").value, today);*/
|
||||
}
|
||||
|
||||
// @with_setup(setup = make_tmpdir, teardown = clean_tmpdir)
|
||||
void test_write_regular_float2()
|
||||
{
|
||||
/*float_value = 1.0 / 3.0;
|
||||
book = Workbook();
|
||||
sheet = book.get_active_sheet();
|
||||
sheet.cell("A1").value = float_value;
|
||||
dest_filename = osp.join(TMPDIR, "float_read_write_issue.xlsx");
|
||||
book.save(dest_filename);
|
||||
|
||||
test_book = load_workbook(dest_filename);
|
||||
test_sheet = test_book.get_active_sheet();
|
||||
|
||||
TS_ASSERT_EQUALS(test_sheet.cell("A1").value, float_value);*/
|
||||
}
|
||||
|
||||
// @raises(UnicodeDecodeError)
|
||||
void test_bad_encoding()
|
||||
{
|
||||
/*pound = chr(163);
|
||||
test_string = ("Compound Value (" + pound + ")").encode("latin1");
|
||||
|
||||
utf_book = Workbook();
|
||||
utf_sheet = utf_book.get_active_sheet();
|
||||
utf_sheet.cell("A1").value = test_string;*/
|
||||
}
|
||||
|
||||
void test_good_encoding()
|
||||
{
|
||||
/*pound = chr(163);
|
||||
test_string = ("Compound Value (" + pound + ")").encode("latin1");
|
||||
|
||||
lat_book = Workbook(encoding = "latin1");
|
||||
lat_sheet = lat_book.get_active_sheet();
|
||||
lat_sheet.cell("A1").value = test_string;*/
|
||||
}
|
||||
};
|
336
source/tests/WorksheetTestSuite.h
Normal file
336
source/tests/WorksheetTestSuite.h
Normal file
|
@ -0,0 +1,336 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class WorksheetTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
WorksheetTestSuite()
|
||||
{
|
||||
}/*
|
||||
cls.wb = Workbook()
|
||||
}
|
||||
*/
|
||||
|
||||
void test_new_worksheet()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//TS_ASSERT_EQUALS(wb, ws._parent);
|
||||
}
|
||||
|
||||
void test_new_sheet_name()
|
||||
{
|
||||
//wb.worksheets = [];
|
||||
//ws = Worksheet(wb, title = "");
|
||||
//TS_ASSERT_EQUALS(repr(ws), "<Worksheet "Sheet1">");
|
||||
}
|
||||
|
||||
void test_get_cell()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//cell = ws.cell("A1");
|
||||
//TS_ASSERT_EQUALS(cell.get_coordinate(), "A1");
|
||||
}
|
||||
|
||||
void test_set_bad_title()
|
||||
{
|
||||
//Worksheet(wb, "X" * 50);
|
||||
}
|
||||
|
||||
void test_set_bad_title_character()
|
||||
{
|
||||
//assert_raises(SheetTitleException, Worksheet, wb, "[");
|
||||
//assert_raises(SheetTitleException, Worksheet, wb, "]");
|
||||
//assert_raises(SheetTitleException, Worksheet, wb, "*");
|
||||
//assert_raises(SheetTitleException, Worksheet, wb, ":");
|
||||
//assert_raises(SheetTitleException, Worksheet, wb, "?");
|
||||
//assert_raises(SheetTitleException, Worksheet, wb, "/");
|
||||
//assert_raises(SheetTitleException, Worksheet, wb, "\\");
|
||||
}
|
||||
|
||||
void test_worksheet_dimension()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//TS_ASSERT_EQUALS("A1:A1", ws.calculate_dimension());
|
||||
//ws.cell("B12").value = "AAA";
|
||||
//TS_ASSERT_EQUALS("A1:B12", ws.calculate_dimension());
|
||||
}
|
||||
|
||||
void test_worksheet_range()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//xlrange = ws.range("A1:C4");
|
||||
//assert isinstance(xlrange, tuple);
|
||||
//TS_ASSERT_EQUALS(4, len(xlrange));
|
||||
//TS_ASSERT_EQUALS(3, len(xlrange[0]));
|
||||
}
|
||||
|
||||
void test_worksheet_named_range()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//wb.create_named_range("test_range", ws, "C5");
|
||||
//xlrange = ws.range("test_range");
|
||||
//assert isinstance(xlrange, Cell);
|
||||
//TS_ASSERT_EQUALS(5, xlrange.row);
|
||||
}
|
||||
|
||||
void test_bad_named_range()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//ws.range("bad_range");
|
||||
}
|
||||
|
||||
void test_named_range_wrong_sheet()
|
||||
{
|
||||
//ws1 = Worksheet(wb);
|
||||
//ws2 = Worksheet(wb);
|
||||
//wb.create_named_range("wrong_sheet_range", ws1, "C5");
|
||||
//ws2.range("wrong_sheet_range");
|
||||
}
|
||||
|
||||
void test_cell_offset()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//TS_ASSERT_EQUALS("C17", ws.cell("B15").offset(2, 1).get_coordinate());
|
||||
}
|
||||
|
||||
void test_range_offset()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//xlrange = ws.range("A1:C4", 1, 3);
|
||||
//assert isinstance(xlrange, tuple);
|
||||
//TS_ASSERT_EQUALS(4, len(xlrange));
|
||||
//TS_ASSERT_EQUALS(3, len(xlrange[0]));
|
||||
//TS_ASSERT_EQUALS("D2", xlrange[0][0].get_coordinate());
|
||||
}
|
||||
|
||||
void test_cell_alternate_coordinates()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//cell = ws.cell(row = 8, column = 4);
|
||||
//TS_ASSERT_EQUALS("E9", cell.get_coordinate());
|
||||
}
|
||||
|
||||
void test_cell_insufficient_coordinates()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//cell = ws.cell(row = 8);
|
||||
}
|
||||
|
||||
void test_cell_range_name()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//wb.create_named_range("test_range_single", ws, "B12");
|
||||
//assert_raises(CellCoordinatesException, ws.cell, "test_range_single");
|
||||
//c_range_name = ws.range("test_range_single");
|
||||
//c_range_coord = ws.range("B12");
|
||||
//c_cell = ws.cell("B12");
|
||||
//TS_ASSERT_EQUALS(c_range_coord, c_range_name);
|
||||
//TS_ASSERT_EQUALS(c_range_coord, c_cell);
|
||||
}
|
||||
|
||||
void test_garbage_collect()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//ws.cell("A1").value = "";
|
||||
//ws.cell("B2").value = "0";
|
||||
//ws.cell("C4").value = 0;
|
||||
//ws.garbage_collect();
|
||||
//for i, cell in enumerate(ws.get_cell_collection())
|
||||
//{
|
||||
// TS_ASSERT_EQUALS(cell, [ws.cell("B2"), ws.cell("C4")][i]);
|
||||
//}
|
||||
}
|
||||
|
||||
void test_hyperlink_relationships()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//TS_ASSERT_EQUALS(len(ws.relationships), 0);
|
||||
|
||||
//ws.cell("A1").hyperlink = "http://test.com";
|
||||
//TS_ASSERT_EQUALS(len(ws.relationships), 1);
|
||||
//TS_ASSERT_EQUALS("rId1", ws.cell("A1").hyperlink_rel_id);
|
||||
//TS_ASSERT_EQUALS("rId1", ws.relationships[0].id);
|
||||
//TS_ASSERT_EQUALS("http://test.com", ws.relationships[0].target);
|
||||
//TS_ASSERT_EQUALS("External", ws.relationships[0].target_mode);
|
||||
|
||||
//ws.cell("A2").hyperlink = "http://test2.com";
|
||||
//TS_ASSERT_EQUALS(len(ws.relationships), 2);
|
||||
//TS_ASSERT_EQUALS("rId2", ws.cell("A2").hyperlink_rel_id);
|
||||
//TS_ASSERT_EQUALS("rId2", ws.relationships[1].id);
|
||||
//TS_ASSERT_EQUALS("http://test2.com", ws.relationships[1].target);
|
||||
//TS_ASSERT_EQUALS("External", ws.relationships[1].target_mode);
|
||||
}
|
||||
|
||||
void test_bad_relationship_type()
|
||||
{
|
||||
//rel = Relationship("bad_type");
|
||||
}
|
||||
|
||||
void test_append_list()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
|
||||
//ws.append(["This is A1", "This is B1"]);
|
||||
|
||||
//TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value);
|
||||
//TS_ASSERT_EQUALS("This is B1", ws.cell("B1").value);
|
||||
}
|
||||
|
||||
void test_append_dict_letter()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
|
||||
//ws.append({"A" : "This is A1", "C" : "This is C1"});
|
||||
|
||||
//TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value);
|
||||
//TS_ASSERT_EQUALS("This is C1", ws.cell("C1").value);
|
||||
}
|
||||
|
||||
void test_append_dict_index()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
|
||||
//ws.append({0 : "This is A1", 2 : "This is C1"});
|
||||
|
||||
//TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value);
|
||||
//TS_ASSERT_EQUALS("This is C1", ws.cell("C1").value);
|
||||
}
|
||||
|
||||
void test_bad_append()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//ws.append("test");
|
||||
}
|
||||
|
||||
void test_append_2d_list()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
|
||||
//ws.append(["This is A1", "This is B1"]);
|
||||
//ws.append(["This is A2", "This is B2"]);
|
||||
|
||||
//vals = ws.range("A1:B2");
|
||||
|
||||
//TS_ASSERT_EQUALS((("This is A1", "This is B1"),
|
||||
// ("This is A2", "This is B2"), ), flatten(vals));
|
||||
}
|
||||
|
||||
void test_rows()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
|
||||
//ws.cell("A1").value = "first";
|
||||
//ws.cell("C9").value = "last";
|
||||
|
||||
//rows = ws.rows;
|
||||
|
||||
//TS_ASSERT_EQUALS(len(rows), 9);
|
||||
|
||||
//TS_ASSERT_EQUALS(rows[0][0].value, "first");
|
||||
//TS_ASSERT_EQUALS(rows[-1][-1].value, "last");
|
||||
}
|
||||
|
||||
void test_cols()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
|
||||
//ws.cell("A1").value = "first";
|
||||
//ws.cell("C9").value = "last";
|
||||
|
||||
//cols = ws.columns;
|
||||
|
||||
//TS_ASSERT_EQUALS(len(cols), 3);
|
||||
|
||||
//TS_ASSERT_EQUALS(cols[0][0].value, "first");
|
||||
//TS_ASSERT_EQUALS(cols[-1][-1].value, "last");
|
||||
}
|
||||
|
||||
void test_auto_filter()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//ws.auto_filter = ws.range("a1:f1");
|
||||
//assert ws.auto_filter == "A1:F1";
|
||||
|
||||
//ws.auto_filter = "";
|
||||
//assert ws.auto_filter is None;
|
||||
|
||||
//ws.auto_filter = "c1:g9";
|
||||
//assert ws.auto_filter == "C1:G9";
|
||||
}
|
||||
|
||||
void test_page_margins()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//ws.page_margins.left = 2.0;
|
||||
//ws.page_margins.right = 2.0;
|
||||
//ws.page_margins.top = 2.0;
|
||||
//ws.page_margins.bottom = 2.0;
|
||||
//ws.page_margins.header = 1.5;
|
||||
//ws.page_margins.footer = 1.5;
|
||||
//xml_string = write_worksheet(ws, None, None);
|
||||
//assert "<pageMargins left="2.00" right="2.00" top="2.00" bottom="2.00" header="1.50" footer="1.50"></pageMargins>" in xml_string;
|
||||
|
||||
//ws = Worksheet(wb);
|
||||
//xml_string = write_worksheet(ws, None, None);
|
||||
//assert "<pageMargins" not in xml_string;
|
||||
}
|
||||
|
||||
void test_merge()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//string_table = {"":"", "Cell A1" : "Cell A1", "Cell B1" : "Cell B1"};
|
||||
|
||||
//ws.cell("A1").value = "Cell A1";
|
||||
//ws.cell("B1").value = "Cell B1";
|
||||
//xml_string = write_worksheet(ws, string_table, None);
|
||||
//assert "<c r="B1" t="s"><v>Cell B1</v></c>" in xml_string;
|
||||
|
||||
//ws.merge_cells("A1:B1");
|
||||
//xml_string = write_worksheet(ws, string_table, None);
|
||||
//assert "<c r="B1" t="s"><v>Cell B1</v></c>" not in xml_string;
|
||||
//assert "<mergeCells><mergeCell ref="A1:B1"></mergeCell></mergeCells>" in xml_string;
|
||||
|
||||
//ws.unmerge_cells("A1:B1");
|
||||
//xml_string = write_worksheet(ws, string_table, None);
|
||||
//assert "<mergeCell ref="A1:B1"></mergeCell>" not in xml_string;
|
||||
}
|
||||
|
||||
void test_freeze()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//ws.freeze_panes = ws.cell("b2");
|
||||
//assert ws.freeze_panes == "B2";
|
||||
|
||||
//ws.freeze_panes = "";
|
||||
//assert ws.freeze_panes is None;
|
||||
|
||||
//ws.freeze_panes = "c5";
|
||||
//assert ws.freeze_panes == "C5";
|
||||
|
||||
//ws.freeze_panes = ws.cell("A1");
|
||||
//assert ws.freeze_panes is None;
|
||||
}
|
||||
|
||||
void test_printer_settings()
|
||||
{
|
||||
//ws = Worksheet(wb);
|
||||
//ws.page_setup.orientation = ws.ORIENTATION_LANDSCAPE;
|
||||
//ws.page_setup.paperSize = ws.PAPERSIZE_TABLOID;
|
||||
//ws.page_setup.fitToPage = True;
|
||||
//ws.page_setup.fitToHeight = 0;
|
||||
//ws.page_setup.fitToWidth = 1;
|
||||
//xml_string = write_worksheet(ws, None, None);
|
||||
//assert "<pageSetup orientation="landscape" paperSize="3" fitToHeight="0" fitToWidth="1"></pageSetup>" in xml_string;
|
||||
//assert "<pageSetUpPr fitToPage="1"></pageSetUpPr>" in xml_string;
|
||||
|
||||
//ws = Worksheet(wb);
|
||||
//xml_string = write_worksheet(ws, None, None);
|
||||
//assert "<pageSetup" not in xml_string;
|
||||
//assert "<pageSetUpPr" not in xml_string;
|
||||
}
|
||||
};
|
240
source/tests/WriteTestSuite.h
Normal file
240
source/tests/WriteTestSuite.h
Normal file
|
@ -0,0 +1,240 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include <xlnt/workbook.h>
|
||||
#include <xlnt/worksheet.h>
|
||||
|
||||
class WriteTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
WriteTestSuite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void test_write_empty_workbook()
|
||||
{
|
||||
//make_tmpdir();
|
||||
//wb = Workbook();
|
||||
//dest_filename = os.path.join(TMPDIR, "empty_book.xlsx");
|
||||
//save_workbook(wb, dest_filename);
|
||||
//assert os.path.isfile(dest_filename);
|
||||
//clean_tmpdir();
|
||||
}
|
||||
|
||||
void test_write_virtual_workbook()
|
||||
{
|
||||
//old_wb = Workbook();
|
||||
//saved_wb = save_virtual_workbook(old_wb);
|
||||
//new_wb = load_workbook(BytesIO(saved_wb));
|
||||
//assert new_wb;
|
||||
}
|
||||
|
||||
void test_write_workbook_rels()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//content = write_workbook_rels(wb);
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "workbook.xml.rels"), content);
|
||||
}
|
||||
|
||||
void test_write_workbook()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//content = write_workbook(wb);
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "workbook.xml"), content);
|
||||
}
|
||||
|
||||
|
||||
void test_write_string_table()
|
||||
{
|
||||
//table = {"hello": 1, "world" : 2, "nice" : 3};
|
||||
//content = write_string_table(table);
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sharedStrings.xml"), content);
|
||||
}
|
||||
|
||||
void test_write_worksheet()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("F42").value = "hello";
|
||||
//content = write_worksheet(ws, {"hello": 0}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1.xml"), content);
|
||||
}
|
||||
|
||||
void test_write_hidden_worksheet()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.sheet_state = ws.SHEETSTATE_HIDDEN;
|
||||
//ws.cell("F42").value = "hello";
|
||||
//content = write_worksheet(ws, {"hello": 0}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1.xml"), content);
|
||||
}
|
||||
|
||||
void test_write_bool()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("F42").value = False;
|
||||
//ws.cell("F43").value = True;
|
||||
//content = write_worksheet(ws, {}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_bool.xml"), content);
|
||||
}
|
||||
|
||||
void test_write_formula()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("F1").value = 10;
|
||||
//ws.cell("F2").value = 32;
|
||||
//ws.cell("F3").value = "=F1+F2";
|
||||
//content = write_worksheet(ws, {}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_formula.xml"), content);
|
||||
}
|
||||
|
||||
void test_write_style()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("F1").value = "13%";
|
||||
//style_id_by_hash = StyleWriter(wb).get_style_by_hash();
|
||||
//content = write_worksheet(ws, {}, style_id_by_hash);
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_style.xml"), content);
|
||||
}
|
||||
|
||||
void test_write_height()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("F1").value = 10;
|
||||
//ws.row_dimensions[ws.cell("F1").row].height = 30;
|
||||
//content = write_worksheet(ws, {}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_height.xml"), content);
|
||||
}
|
||||
|
||||
void test_write_hyperlink()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("A1").value = "test";
|
||||
//ws.cell("A1").hyperlink = "http://test.com";
|
||||
//content = write_worksheet(ws, {"test": 0}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_hyperlink.xml"), content);
|
||||
}
|
||||
|
||||
void test_write_hyperlink_rels()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//TS_ASSERT_EQUALS(0, len(ws.relationships));
|
||||
//ws.cell("A1").value = "test";
|
||||
//ws.cell("A1").hyperlink = "http://test.com/";
|
||||
//TS_ASSERT_EQUALS(1, len(ws.relationships));
|
||||
//ws.cell("A2").value = "test";
|
||||
//ws.cell("A2").hyperlink = "http://test2.com/";
|
||||
//TS_ASSERT_EQUALS(2, len(ws.relationships));
|
||||
//content = write_worksheet_rels(ws, 1);
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_hyperlink.xml.rels"), content);
|
||||
}
|
||||
|
||||
void test_hyperlink_value()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("A1").hyperlink = "http://test.com";
|
||||
//TS_ASSERT_EQUALS("http://test.com", ws.cell("A1").value);
|
||||
//ws.cell("A1").value = "test";
|
||||
//TS_ASSERT_EQUALS("test", ws.cell("A1").value);
|
||||
}
|
||||
|
||||
void test_write_auto_filter()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.worksheets[0];
|
||||
//ws.cell("F42").value = "hello";
|
||||
//ws.auto_filter = "A1:F1";
|
||||
//content = write_worksheet(ws, {"hello": 0}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_auto_filter.xml"), content);
|
||||
|
||||
//content = write_workbook(wb);
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "workbook_auto_filter.xml"), content);
|
||||
}
|
||||
|
||||
void test_freeze_panes_horiz()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("F42").value = "hello";
|
||||
//ws.freeze_panes = "A4";
|
||||
//content = write_worksheet(ws, {"hello": 0}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_freeze_panes_horiz.xml"), content);
|
||||
}
|
||||
|
||||
void test_freeze_panes_vert()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("F42").value = "hello";
|
||||
//ws.freeze_panes = "D1";
|
||||
//content = write_worksheet(ws, {"hello": 0}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_freeze_panes_vert.xml"), content);
|
||||
}
|
||||
|
||||
void test_freeze_panes_both()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("F42").value = "hello";
|
||||
//ws.freeze_panes = "D4";
|
||||
//content = write_worksheet(ws, {"hello": 0}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "sheet1_freeze_panes_both.xml"), content);
|
||||
}
|
||||
|
||||
void test_long_number()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("A1").value = 9781231231230;
|
||||
//content = write_worksheet(ws, {}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "long_number.xml"), content);
|
||||
}
|
||||
|
||||
void test_decimal()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("A1").value = decimal.Decimal("3.14");
|
||||
//content = write_worksheet(ws, {}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "decimal.xml"), content);
|
||||
}
|
||||
|
||||
void test_short_number()
|
||||
{
|
||||
//wb = Workbook();
|
||||
//ws = wb.create_sheet();
|
||||
//ws.cell("A1").value = 1234567890;
|
||||
//content = write_worksheet(ws, {}, {});
|
||||
//assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
|
||||
// "short_number.xml"), content);
|
||||
}
|
||||
};
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
source/tests/test_data/genuine/NameWithValueBug.xlsx
Normal file
BIN
source/tests/test_data/genuine/NameWithValueBug.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/genuine/empty-no-string.xlsx
Normal file
BIN
source/tests/test_data/genuine/empty-no-string.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/genuine/empty-with-styles.xlsx
Normal file
BIN
source/tests/test_data/genuine/empty-with-styles.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/genuine/empty.xlsx
Normal file
BIN
source/tests/test_data/genuine/empty.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/genuine/empty_libre.xlsx
Normal file
BIN
source/tests/test_data/genuine/empty_libre.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/genuine/empty_no_dimensions.xlsx
Normal file
BIN
source/tests/test_data/genuine/empty_no_dimensions.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/genuine/empty_with_no_properties.xlsx
Normal file
BIN
source/tests/test_data/genuine/empty_with_no_properties.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/genuine/merge_range.xlsx
Normal file
BIN
source/tests/test_data/genuine/merge_range.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/genuine/unicode.xlsx
Normal file
BIN
source/tests/test_data/genuine/unicode.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/packaging/a.zip
Normal file
BIN
source/tests/test_data/packaging/a.zip
Normal file
Binary file not shown.
BIN
source/tests/test_data/reader/date_1900.xlsx
Normal file
BIN
source/tests/test_data/reader/date_1900.xlsx
Normal file
Binary file not shown.
BIN
source/tests/test_data/reader/date_1904.xlsx
Normal file
BIN
source/tests/test_data/reader/date_1904.xlsx
Normal file
Binary file not shown.
53
source/tests/test_data/reader/empty-workbook-styles.xml
Normal file
53
source/tests/test_data/reader/empty-workbook-styles.xml
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<fonts count="2">
|
||||
<font>
|
||||
<sz val="11" />
|
||||
<color theme="1" />
|
||||
<name val="Calibri" />
|
||||
<family val="2" />
|
||||
<scheme val="minor" />
|
||||
</font>
|
||||
<font>
|
||||
<sz val="11" />
|
||||
<color theme="1" />
|
||||
<name val="Calibri" />
|
||||
<family val="2" />
|
||||
<scheme val="minor" />
|
||||
</font>
|
||||
</fonts>
|
||||
<fills count="2">
|
||||
<fill>
|
||||
<patternFill patternType="none" />
|
||||
</fill>
|
||||
<fill>
|
||||
<patternFill patternType="gray125" />
|
||||
</fill>
|
||||
</fills>
|
||||
<borders count="1">
|
||||
<border>
|
||||
<left />
|
||||
<right />
|
||||
<top />
|
||||
<bottom />
|
||||
<diagonal />
|
||||
</border>
|
||||
</borders>
|
||||
<cellStyleXfs count="2">
|
||||
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" />
|
||||
<xf numFmtId="9" fontId="1" fillId="0" borderId="0" applyFont="0"
|
||||
applyFill="0" applyBorder="0" applyAlignment="0" applyProtection="0" />
|
||||
</cellStyleXfs>
|
||||
<cellXfs count="2">
|
||||
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" />
|
||||
<xf numFmtId="9" fontId="0" fillId="0" borderId="0" xfId="1"
|
||||
applyFont="1" />
|
||||
</cellXfs>
|
||||
<cellStyles count="2">
|
||||
<cellStyle name="Normal" xfId="0" builtinId="0" />
|
||||
<cellStyle name="Percent" xfId="1" builtinId="5" />
|
||||
</cellStyles>
|
||||
<dxfs count="0" />
|
||||
<tableStyles count="0" defaultTableStyle="TableStyleMedium9"
|
||||
defaultPivotStyle="PivotStyleLight16" />
|
||||
</styleSheet>
|
2
source/tests/test_data/reader/merged-ranges.xml
Normal file
2
source/tests/test_data/reader/merged-ranges.xml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:E15"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="B16" sqref="B16"/></sheetView></sheetViews><sheetFormatPr defaultRowHeight="15"/><sheetData><row r="1" spans="1:5"><c r="A1" s="3"><v>1</v></c><c r="B1" s="3"><v>2</v></c><c r="C1" s="3"><v>3</v></c><c r="D1" s="3"><v>4</v></c></row><row r="3" spans="1:5"><c r="A3" s="2" t="s"><v>0</v></c><c r="B3" t="s"><v>1</v></c><c r="C3" s="2" t="s"><v>2</v></c><c r="D3" s="2" t="s"><v>3</v></c></row><row r="5" spans="1:5"><c r="C5" s="1" t="s"><v>4</v></c><c r="E5" s="1" t="s"><v>6</v></c></row><row r="6" spans="1:5"><c r="C6" s="1" t="s"><v>4</v></c><c r="E6" s="1" t="s"><v>6</v></c></row><row r="7" spans="1:5"><c r="C7" s="1" t="s"><v>4</v></c><c r="E7" s="1" t="s"><v>6</v></c></row><row r="8" spans="1:5"><c r="D8" s="1" t="s"><v>5</v></c></row><row r="9" spans="1:5"><c r="C9" s="1" t="s"><v>4</v></c><c r="E9" s="1" t="s"><v>6</v></c></row><row r="10" spans="1:5"><c r="C10" s="1" t="s"><v>4</v></c><c r="E10" s="1" t="s"><v>6</v></c></row><row r="11" spans="1:5"><c r="C11" s="1" t="s"><v>4</v></c><c r="E11" s="1" t="s"><v>6</v></c></row><row r="15" spans="1:5"><c r="B15" s="4"><v>10</v></c><c r="C15" s="4"/><c r="D15" s="4"/></row></sheetData><mergeCells count="1"><mergeCell ref="B15:D15"/></mergeCells><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/><pageSetup orientation="portrait" horizontalDpi="200" verticalDpi="200" r:id="rId1"/></worksheet>
|
BIN
source/tests/test_data/reader/null_archive.xlsx
Normal file
BIN
source/tests/test_data/reader/null_archive.xlsx
Normal file
Binary file not shown.
0
source/tests/test_data/reader/null_file.xlsx
Normal file
0
source/tests/test_data/reader/null_file.xlsx
Normal file
33
source/tests/test_data/reader/shared-strings-rich.xml
Normal file
33
source/tests/test_data/reader/shared-strings-rich.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="3" uniqueCount="3">
|
||||
<si>
|
||||
<t>Welcome</t>
|
||||
</si>
|
||||
<si>
|
||||
<r>
|
||||
<t xml:space="preserve">to the best </t>
|
||||
</r><r>
|
||||
<rPr>
|
||||
<b/>
|
||||
<sz val="11"/>
|
||||
<color theme="1"/>
|
||||
<rFont val="Calibri"/>
|
||||
<family val="2"/>
|
||||
<scheme val="minor"/>
|
||||
</rPr><t xml:space="preserve">shop in </t>
|
||||
</r><r>
|
||||
<rPr>
|
||||
<b/>
|
||||
<u/>
|
||||
<sz val="11"/>
|
||||
<color theme="1"/>
|
||||
<rFont val="Calibri"/>
|
||||
<family val="2"/>
|
||||
<scheme val="minor"/>
|
||||
</rPr><t>town</t>
|
||||
</r>
|
||||
</si>
|
||||
<si>
|
||||
<t xml:space="preserve"> let's play </t>
|
||||
</si>
|
||||
</sst>
|
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<sst count="1" uniqueCount="1" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><si><t>Testing empty cell</t></si> <si><t/></si></sst>
|
||||
|
2
source/tests/test_data/reader/sharedStrings.xml
Normal file
2
source/tests/test_data/reader/sharedStrings.xml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="3" uniqueCount="2"><si><t>This is cell A1 in Sheet 1</t></si><si><t>This is cell G5</t></si></sst>
|
2
source/tests/test_data/reader/sheet2.xml
Normal file
2
source/tests/test_data/reader/sheet2.xml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="D1:K30"/><sheetViews><sheetView workbookViewId="0"><selection activeCell="L2" sqref="L2"/></sheetView></sheetViews><sheetFormatPr defaultRowHeight="15"/><sheetData><row r="1" spans="4:11"><c r="D1"><v>1</v></c><c r="K1" s="1"><v>0.01</v></c></row><row r="2" spans="4:11"><c r="D2"><v>2</v></c><c r="K2" s="1"><v>0.02</v></c></row><row r="3" spans="4:11"><c r="D3"><v>3</v></c><c r="K3" s="1"><v>0.03</v></c></row><row r="4" spans="4:11"><c r="D4"><v>4</v></c><c r="K4" s="1"><v>0.04</v></c></row><row r="5" spans="4:11"><c r="D5"><v>5</v></c><c r="G5" t="s"><v>1</v></c><c r="K5" s="1"><v>0.05</v></c></row><row r="6" spans="4:11"><c r="D6"><v>6</v></c><c r="K6" s="1"><v>0.06</v></c></row><row r="7" spans="4:11"><c r="D7"><v>7</v></c><c r="K7" s="1"><v>7.0000000000000007E-2</v></c></row><row r="8" spans="4:11"><c r="D8"><v>8</v></c><c r="K8" s="1"><v>0.08</v></c></row><row r="9" spans="4:11"><c r="D9"><v>9</v></c><c r="K9" s="1"><v>0.09</v></c></row><row r="10" spans="4:11"><c r="D10"><v>10</v></c><c r="K10" s="1"><v>0.1</v></c></row><row r="11" spans="4:11"><c r="D11"><v>11</v></c><c r="K11" s="1"><v>0.11</v></c></row><row r="12" spans="4:11"><c r="D12"><v>12</v></c><c r="K12" s="1"><v>0.12</v></c></row><row r="13" spans="4:11"><c r="D13"><v>13</v></c><c r="K13" s="1"><v>0.13</v></c></row><row r="14" spans="4:11"><c r="D14"><v>14</v></c><c r="K14" s="1"><v>0.14000000000000001</v></c></row><row r="15" spans="4:11"><c r="D15"><v>15</v></c><c r="K15" s="1"><v>0.15</v></c></row><row r="16" spans="4:11"><c r="D16"><v>16</v></c><c r="K16" s="1"><v>0.16</v></c></row><row r="17" spans="4:11"><c r="D17"><v>17</v></c><c r="K17" s="1"><v>0.17</v></c></row><row r="18" spans="4:11"><c r="D18"><v>18</v></c><c r="K18" s="1"><v>0.18</v></c></row><row r="19" spans="4:11"><c r="D19"><v>19</v></c><c r="K19" s="1"><v>0.19</v></c></row><row r="20" spans="4:11"><c r="D20"><v>20</v></c><c r="K20" s="1"><v>0.2</v></c></row><row r="21" spans="4:11"><c r="D21"><v>21</v></c><c r="K21" s="1"><v>0.21</v></c></row><row r="22" spans="4:11"><c r="D22"><v>22</v></c><c r="K22" s="1"><v>0.22</v></c></row><row r="23" spans="4:11"><c r="D23"><v>23</v></c><c r="K23" s="1"><v>0.23</v></c></row><row r="24" spans="4:11"><c r="D24"><v>24</v></c><c r="K24" s="1"><v>0.24</v></c></row><row r="25" spans="4:11"><c r="D25"><v>25</v></c><c r="K25" s="1"><v>0.25</v></c></row><row r="26" spans="4:11"><c r="D26"><v>26</v></c><c r="K26" s="1"><v>0.26</v></c></row><row r="27" spans="4:11"><c r="D27"><v>27</v></c><c r="K27" s="1"><v>0.27</v></c></row><row r="28" spans="4:11"><c r="D28"><v>28</v></c><c r="K28" s="1"><v>0.28000000000000003</v></c></row><row r="29" spans="4:11"><c r="D29"><v>29</v></c><c r="K29" s="1"><v>0.28999999999999998</v></c></row><row r="30" spans="4:11"><c r="D30"><v>30</v></c><c r="K30" s="1"><v>0.3</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>
|
46
source/tests/test_data/reader/simple-styles.xml
Normal file
46
source/tests/test_data/reader/simple-styles.xml
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<numFmts count="1">
|
||||
<numFmt numFmtId="165" formatCode="yyyy-mm-dd"/>
|
||||
</numFmts>
|
||||
<fonts count="1">
|
||||
<font>
|
||||
<sz val="11"/>
|
||||
<color theme="1"/>
|
||||
<name val="Calibri"/>
|
||||
<family val="2"/>
|
||||
<scheme val="minor"/>
|
||||
</font>
|
||||
</fonts>
|
||||
<fills count="2">
|
||||
<fill>
|
||||
<patternFill patternType="none"/>
|
||||
</fill>
|
||||
<fill>
|
||||
<patternFill patternType="gray125"/>
|
||||
</fill>
|
||||
</fills>
|
||||
<borders count="1">
|
||||
<border>
|
||||
<left/>
|
||||
<right/>
|
||||
<top/>
|
||||
<bottom/>
|
||||
<diagonal/>
|
||||
</border>
|
||||
</borders>
|
||||
<cellStyleXfs count="1">
|
||||
<xf numFmtId="0" fontId="0" fillId="0" borderId="0"/>
|
||||
</cellStyleXfs>
|
||||
<cellXfs count="4">
|
||||
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
|
||||
<xf numFmtId="9" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
|
||||
<xf numFmtId="165" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
|
||||
<xf numFmtId="2" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>
|
||||
</cellXfs>
|
||||
<cellStyles count="1">
|
||||
<cellStyle name="Normal" xfId="0" builtinId="0"/>
|
||||
</cellStyles>
|
||||
<dxfs count="0"/>
|
||||
<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleLight16"/>
|
||||
</styleSheet>
|
2
source/tests/test_data/reader/workbook.xml
Normal file
2
source/tests/test_data/reader/workbook.xml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<workbook xml:space="preserve" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4505" /><workbookPr codeName="ThisWorkbook" defaultThemeVersion="124226" /><bookViews><workbookView activeTab="0" autoFilterDateGrouping="1" firstSheet="0" minimized="0" showHorizontalScroll="1" showSheetTabs="1" showVerticalScroll="1" tabRatio="600" visibility="visible" /></bookViews><sheets><sheet name="My Sheeet" r:id="rId1" sheetId="1" /><sheet name="My Second Sheet" r:id="rId2" sheetId="2" /></sheets><definedNames><definedName name="THE_GREAT_ANSWER">'My Sheeet'!$D$8</definedName></definedNames><calcPr calcId="124519" calcMode="auto" fullCalcOnLoad="1" /></workbook>
|
16
source/tests/test_data/reader/workbook_namedrange.xml
Normal file
16
source/tests/test_data/reader/workbook_namedrange.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xml:space="preserve">
|
||||
<fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4505"/>
|
||||
<workbookPr codeName="ThisWorkbook" defaultThemeVersion="124226"/>
|
||||
<bookViews>
|
||||
<workbookView activeTab="0" autoFilterDateGrouping="1" firstSheet="0" minimized="0" showHorizontalScroll="1" showSheetTabs="1" showVerticalScroll="1" tabRatio="600" visibility="visible"/>
|
||||
</bookViews>
|
||||
<sheets>
|
||||
<sheet name="My Sheeet with a , and ''" r:id="rId1" sheetId="1"/>
|
||||
<sheet name="My Second Sheet" r:id="rId2" sheetId="2"/>
|
||||
</sheets>
|
||||
<definedNames>
|
||||
<definedName name="THE_GREAT_ANSWER">'My Sheeet with a , and '''!$U$16:$U$24,'My Sheeet with a , and '''!$V$28:$V$36</definedName>
|
||||
</definedNames>
|
||||
<calcPr calcId="124519" calcMode="auto" fullCalcOnLoad="1"/>
|
||||
</workbook>
|
2
source/tests/test_data/writer/expected/.rels
Normal file
2
source/tests/test_data/writer/expected/.rels
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Target="xl/workbook.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" /><Relationship Id="rId2" Target="docProps/core.xml" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" /><Relationship Id="rId3" Target="docProps/app.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" /></Relationships>
|
31
source/tests/test_data/writer/expected/[Content_Types].xml
Normal file
31
source/tests/test_data/writer/expected/[Content_Types].xml
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.theme+xml"
|
||||
PartName="/xl/theme/theme1.xml" />
|
||||
<Override
|
||||
ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
|
||||
PartName="/xl/styles.xml" />
|
||||
<Default ContentType="application/vnd.openxmlformats-package.relationships+xml"
|
||||
Extension="rels" />
|
||||
<Default ContentType="application/xml" Extension="xml" />
|
||||
<Override
|
||||
ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
|
||||
PartName="/xl/workbook.xml" />
|
||||
<Override
|
||||
ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"
|
||||
PartName="/docProps/app.xml" />
|
||||
<Override ContentType="application/vnd.openxmlformats-package.core-properties+xml"
|
||||
PartName="/docProps/core.xml" />
|
||||
<Override
|
||||
ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
|
||||
PartName="/xl/sharedStrings.xml" />
|
||||
<Override
|
||||
ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
||||
PartName="/xl/worksheets/sheet1.xml" />
|
||||
<Override
|
||||
ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
||||
PartName="/xl/worksheets/sheet2.xml" />
|
||||
<Override
|
||||
ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
||||
PartName="/xl/worksheets/sheet3.xml" />
|
||||
</Types>
|
2
source/tests/test_data/writer/expected/app.xml
Normal file
2
source/tests/test_data/writer/expected/app.xml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"><Application>Microsoft Excel</Application><DocSecurity>0</DocSecurity><ScaleCrop>false</ScaleCrop><Company /><LinksUpToDate>false</LinksUpToDate><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>12.0000</AppVersion><HeadingPairs><vt:vector baseType="variant" size="2"><vt:variant><vt:lpstr>Worksheets</vt:lpstr></vt:variant><vt:variant><vt:i4>3</vt:i4></vt:variant></vt:vector></HeadingPairs><TitlesOfParts><vt:vector baseType="lpstr" size="3"><vt:lpstr>Sheet</vt:lpstr><vt:lpstr>Sheet1</vt:lpstr><vt:lpstr>Sheet2</vt:lpstr></vt:vector></TitlesOfParts></Properties>
|
2
source/tests/test_data/writer/expected/core.xml
Normal file
2
source/tests/test_data/writer/expected/core.xml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:creator>TEST_USER</dc:creator><cp:lastModifiedBy>SOMEBODY</cp:lastModifiedBy><dcterms:created xsi:type="dcterms:W3CDTF">2010-04-01T20:30:00Z</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">2010-04-05T14:05:30Z</dcterms:modified></cp:coreProperties>
|
23
source/tests/test_data/writer/expected/decimal.xml
Normal file
23
source/tests/test_data/writer/expected/decimal.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<worksheet xml:space="preserve" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||
<sheetPr>
|
||||
<outlinePr summaryBelow="1" summaryRight="1" />
|
||||
</sheetPr>
|
||||
<dimension ref="A1:A1" />
|
||||
<sheetViews>
|
||||
<sheetView workbookViewId="0">
|
||||
<selection activeCell="A1" sqref="A1" />
|
||||
</sheetView>
|
||||
</sheetViews>
|
||||
<sheetFormatPr defaultRowHeight="15" />
|
||||
<cols>
|
||||
<col collapsed="0" max="1" min="1" width="9.10" />
|
||||
</cols>
|
||||
<sheetData>
|
||||
<row r="1" spans="1:1">
|
||||
<c r="A1" t="n">
|
||||
<v>3.14</v>
|
||||
</c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
10
source/tests/test_data/writer/expected/font.xml
Normal file
10
source/tests/test_data/writer/expected/font.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<fonts count="1">
|
||||
<font>
|
||||
<sz val="11"/>
|
||||
<color theme="1"/>
|
||||
<name val="Calibri"/>
|
||||
<family val="2"/>
|
||||
<scheme val="minor"/>
|
||||
</font>
|
||||
</fonts>
|
23
source/tests/test_data/writer/expected/long_number.xml
Normal file
23
source/tests/test_data/writer/expected/long_number.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<worksheet xml:space="preserve" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||
<sheetPr>
|
||||
<outlinePr summaryBelow="1" summaryRight="1" />
|
||||
</sheetPr>
|
||||
<dimension ref="A1:A1" />
|
||||
<sheetViews>
|
||||
<sheetView workbookViewId="0">
|
||||
<selection activeCell="A1" sqref="A1" />
|
||||
</sheetView>
|
||||
</sheetViews>
|
||||
<sheetFormatPr defaultRowHeight="15" />
|
||||
<cols>
|
||||
<col collapsed="0" max="1" min="1" width="9.10" />
|
||||
</cols>
|
||||
<sheetData>
|
||||
<row r="1" spans="1:1">
|
||||
<c r="A1" t="n">
|
||||
<v>9781231231230</v>
|
||||
</c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
2
source/tests/test_data/writer/expected/sharedStrings.xml
Normal file
2
source/tests/test_data/writer/expected/sharedStrings.xml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<sst uniqueCount="3" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><si><t>hello</t></si><si><t>world</t></si><si><t>nice</t></si></sst>
|
23
source/tests/test_data/writer/expected/sheet1.xml
Normal file
23
source/tests/test_data/writer/expected/sheet1.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<worksheet xml:space="preserve" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||
<sheetPr>
|
||||
<outlinePr summaryBelow="1" summaryRight="1" />
|
||||
</sheetPr>
|
||||
<dimension ref="A1:F42" />
|
||||
<sheetViews>
|
||||
<sheetView workbookViewId="0">
|
||||
<selection activeCell="A1" sqref="A1" />
|
||||
</sheetView>
|
||||
</sheetViews>
|
||||
<sheetFormatPr defaultRowHeight="15" />
|
||||
<cols>
|
||||
<col collapsed="0" max="6" min="6" width="9.10" />
|
||||
</cols>
|
||||
<sheetData>
|
||||
<row r="42" spans="1:6">
|
||||
<c r="F42" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
|
@ -0,0 +1 @@
|
|||
<worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xml:space="preserve" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetPr><outlinePr summaryRight="1" summaryBelow="1"></outlinePr></sheetPr><dimension ref="A1:F42"></dimension><sheetViews><sheetView workbookViewId="0"><selection sqref="A1" activeCell="A1"></selection></sheetView></sheetViews><sheetFormatPr defaultRowHeight="15"></sheetFormatPr><cols><col collapsed="0" min="6" max="6" width="9.10"></col></cols><sheetData><row spans="1:6" r="42"><c t="s" r="F42"><v>0</v></c></row></sheetData><autoFilter ref="A1:F1"></autoFilter></worksheet>
|
28
source/tests/test_data/writer/expected/sheet1_bool.xml
Normal file
28
source/tests/test_data/writer/expected/sheet1_bool.xml
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<worksheet xml:space="preserve" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||
<sheetPr>
|
||||
<outlinePr summaryBelow="1" summaryRight="1" />
|
||||
</sheetPr>
|
||||
<dimension ref="A1:F43" />
|
||||
<sheetViews>
|
||||
<sheetView workbookViewId="0">
|
||||
<selection activeCell="A1" sqref="A1" />
|
||||
</sheetView>
|
||||
</sheetViews>
|
||||
<sheetFormatPr defaultRowHeight="15" />
|
||||
<cols>
|
||||
<col collapsed="0" max="6" min="6" width="9.10" />
|
||||
</cols>
|
||||
<sheetData>
|
||||
<row r="42" spans="1:6">
|
||||
<c r="F42" t="b">
|
||||
<v>0</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="43" spans="1:6">
|
||||
<c r="F43" t="b">
|
||||
<v>1</v>
|
||||
</c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
33
source/tests/test_data/writer/expected/sheet1_formula.xml
Normal file
33
source/tests/test_data/writer/expected/sheet1_formula.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<worksheet xml:space="preserve" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||
<sheetPr>
|
||||
<outlinePr summaryBelow="1" summaryRight="1" />
|
||||
</sheetPr>
|
||||
<dimension ref="A1:F3" />
|
||||
<sheetViews>
|
||||
<sheetView workbookViewId="0">
|
||||
<selection activeCell="A1" sqref="A1" />
|
||||
</sheetView>
|
||||
</sheetViews>
|
||||
<sheetFormatPr defaultRowHeight="15" />
|
||||
<cols>
|
||||
<col collapsed="0" max="6" min="6" width="9.10" />
|
||||
</cols>
|
||||
<sheetData>
|
||||
<row r="1" spans="1:6">
|
||||
<c r="F1" t="n">
|
||||
<v>10</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="2" spans="1:6">
|
||||
<c r="F2" t="n">
|
||||
<v>32</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="3" spans="1:6">
|
||||
<c r="F3" t="f">
|
||||
<f>F1+F2</f><v />
|
||||
</c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user