xlnt/include/xlnt/cell/cell.hpp

175 lines
5.7 KiB
C++
Raw Normal View History

2014-06-06 04:19:31 +08:00
// Copyright (c) 2014 Thomas Fussell
// Copyright (c) 2010-2014 openpyxl
//
// 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, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
2014-05-21 22:20:30 +08:00
#pragma once
#include <memory>
2014-05-21 22:20:30 +08:00
#include <string>
#include <unordered_map>
2014-06-06 04:19:31 +08:00
#include "../styles/style.hpp"
#include "../common/types.hpp"
2014-05-22 05:48:51 +08:00
2014-05-21 22:20:30 +08:00
namespace xlnt {
class cell_reference;
2014-06-11 05:12:15 +08:00
class relationship;
2014-05-21 22:20:30 +08:00
class worksheet;
2014-05-31 06:42:25 +08:00
2014-06-07 23:49:19 +08:00
struct date;
struct datetime;
struct time;
2014-05-31 06:42:25 +08:00
namespace detail {
struct cell_impl;
2014-05-31 06:42:25 +08:00
} // namespace detail
2014-05-21 22:20:30 +08:00
typedef std::string comment;
/// <summary>
/// Describes cell associated properties.
/// </summary>
/// <remarks>
/// Properties of interest include style, type, value, and address.
/// The Cell class is required to know its value and type, display options,
/// and any other features of an Excel cell.Utilities for referencing
/// cells using Excel's 'A1' column/row nomenclature are also provided.
/// </remarks>
class cell
{
2014-06-11 05:12:15 +08:00
public:
2014-05-21 22:20:30 +08:00
enum class type
{
null,
2014-06-11 05:12:15 +08:00
numeric,
string,
formula,
boolean,
error
2014-05-21 22:20:30 +08:00
};
2014-05-31 06:42:25 +08:00
2014-05-21 22:20:30 +08:00
static const std::unordered_map<std::string, int> ErrorCodes;
static std::string check_string(const std::string &value);
static std::string check_numeric(const std::string &value);
static std::string check_error(const std::string &value);
cell();
cell(worksheet ws, const cell_reference &reference, const std::string &initial_value = std::string());
2014-05-21 22:20:30 +08:00
2014-06-11 06:36:31 +08:00
std::string get_internal_value_string() const;
long double get_internal_value_numeric() const;
2014-05-21 22:20:30 +08:00
std::string get_column() const;
2014-05-22 05:48:51 +08:00
row_t get_row() const;
2014-05-21 22:20:30 +08:00
std::string to_string() const;
void set_explicit_value(const std::string &value, type data_type);
2014-05-31 06:42:25 +08:00
void set_explicit_value(int value, type data_type);
void set_explicit_value(double value, type data_type);
void set_explicit_value(const date &value, type data_type);
void set_explicit_value(const time &value, type data_type);
void set_explicit_value(const datetime &value, type data_type);
2014-05-21 22:20:30 +08:00
type data_type_for_value(const std::string &value);
2014-05-22 05:48:51 +08:00
bool is_merged() const;
void set_merged(bool merged);
2014-05-21 22:20:30 +08:00
2014-06-11 05:12:15 +08:00
relationship get_hyperlink() const;
2014-05-21 22:20:30 +08:00
void set_hyperlink(const std::string &value);
2014-06-11 05:12:15 +08:00
bool has_hyperlink() const;
2014-05-21 22:20:30 +08:00
void set_number_format(const std::string &format_code);
bool has_style() const;
style &get_style();
const style &get_style() const;
type get_data_type() const;
cell_reference get_reference() const;
bool is_date() const;
2014-05-22 05:48:51 +08:00
//std::pair<int, int> get_anchor() const;
2014-05-21 22:20:30 +08:00
comment get_comment() const;
void set_comment(comment comment);
2014-05-31 06:42:25 +08:00
std::string get_formula() const;
void set_formula(const std::string &formula);
std::string get_error() const;
void set_error(const std::string &error);
void set_null();
2014-05-21 22:20:30 +08:00
cell &operator=(const cell &rhs);
cell &operator=(bool value);
cell &operator=(int value);
cell &operator=(double value);
2014-06-05 06:42:17 +08:00
cell &operator=(long int value);
2014-06-11 05:12:15 +08:00
cell &operator=(long long value);
2014-06-05 06:42:17 +08:00
cell &operator=(long double value);
2014-05-21 22:20:30 +08:00
cell &operator=(const std::string &value);
cell &operator=(const char *value);
2014-05-31 06:42:25 +08:00
cell &operator=(const date &value);
cell &operator=(const time &value);
cell &operator=(const datetime &value);
2014-05-21 22:20:30 +08:00
2014-06-14 03:05:24 +08:00
bool operator==(const cell &comparand) const;
2014-05-21 22:20:30 +08:00
bool operator==(std::nullptr_t) const;
bool operator==(bool comparand) const;
bool operator==(int comparand) const;
bool operator==(double comparand) const;
bool operator==(const std::string &comparand) const;
bool operator==(const char *comparand) const;
2014-05-31 06:42:25 +08:00
bool operator==(const date &comparand) const;
bool operator==(const time &comparand) const;
bool operator==(const datetime &comparand) const;
2014-05-21 22:20:30 +08:00
friend bool operator==(std::nullptr_t, const cell &cell);
friend bool operator==(bool comparand, const cell &cell);
friend bool operator==(int comparand, const cell &cell);
friend bool operator==(double comparand, const cell &cell);
friend bool operator==(const std::string &comparand, const cell &cell);
friend bool operator==(const char *comparand, const cell &cell);
2014-05-31 06:42:25 +08:00
friend bool operator==(const date &comparand, const cell &cell);
friend bool operator==(const time &comparand, const cell &cell);
friend bool operator==(const datetime &comparand, const cell &cell);
2014-05-21 22:20:30 +08:00
private:
friend class worksheet;
2014-05-31 06:42:25 +08:00
cell(detail::cell_impl *d);
detail::cell_impl *d_;
2014-05-21 22:20:30 +08:00
};
inline std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell)
{
return stream << cell.to_string();
}
} // namespace xlnt