xlnt/include/xlnt/cell/cell.hpp

152 lines
4.5 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-07-26 04:39:25 +08:00
class comment;
2014-06-11 05:12:15 +08:00
class relationship;
2014-07-26 04:39:25 +08:00
class value;
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-07-20 04:59:05 +08:00
struct timedelta;
2014-06-07 23:49:19 +08:00
2014-05-31 06:42:25 +08:00
namespace detail {
struct cell_impl;
2014-05-31 06:42:25 +08:00
} // namespace detail
2014-07-20 02:43:48 +08:00
2014-05-21 22:20:30 +08:00
/// <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
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();
2014-07-26 04:39:25 +08:00
cell(worksheet ws, const cell_reference &reference);
cell(worksheet ws, const cell_reference &reference, const value &initial_value);
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
2014-07-25 05:31:46 +08:00
std::string to_string() const;
2014-05-21 22:20:30 +08:00
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;
void set_style(const style &s);
2014-07-26 04:39:25 +08:00
std::pair<int, int> get_anchor() const;
bool garbage_collectible() const;
2014-05-21 22:20:30 +08:00
cell_reference get_reference() const;
bool is_date() const;
comment get_comment() const;
void set_comment(const comment &comment);
2014-07-20 02:43:48 +08:00
void clear_comment();
2014-07-25 05:31:46 +08:00
bool has_comment() const;
2014-05-31 06:42:25 +08:00
std::string get_formula() const;
void set_formula(const std::string &formula);
2014-07-25 05:31:46 +08:00
void clear_formula();
bool has_formula() const;
2014-05-31 06:42:25 +08:00
std::string get_error() const;
void set_error(const std::string &error);
2014-05-21 22:20:30 +08:00
2014-07-20 02:43:48 +08:00
cell offset(row_t row, column_t column);
worksheet get_parent();
2014-07-26 04:39:25 +08:00
const worksheet get_parent() const;
value &get_value();
const value &get_value() const;
void set_value(bool b);
void set_value(int i);
void set_value(double d);
void set_value(long double d);
void set_value(long long int i);
void set_value(const date &d);
void set_value(const datetime &d);
void set_value(const time &t);
void set_value(const timedelta &t);
void set_value(const char *s);
void set_value(const std::string &s);
void set_value(const value &v);
2014-07-20 02:43:48 +08:00
2014-05-21 22:20:30 +08:00
cell &operator=(const cell &rhs);
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;
2014-05-31 06:42:25 +08:00
2014-05-21 22:20:30 +08:00
friend bool operator==(std::nullptr_t, const cell &cell);
2014-07-25 05:31:46 +08:00
friend bool operator<(cell left, cell right);
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