Exemplo n.º 1
0
    void test_formula3()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell(xlnt::cell_reference(1, 1));

        xlnt_assert(!cell.has_formula());
        xlnt_assert_throws_nothing(cell.formula(""));
        xlnt_assert(!cell.has_formula());
        cell.formula("=42");
        xlnt_assert(cell.has_formula());
        xlnt_assert_equals(cell.formula(), "42");
        cell.clear_formula();
        xlnt_assert(!cell.has_formula());
    }
Exemplo n.º 2
0
 void test_read_cell_formulae()
 {
     xlnt::workbook wb;
     auto ws = wb.get_active_sheet();
     auto path = PathHelper::GetDataDirectory("/reader/worksheet_formula.xml");
     std::ifstream ws_stream(path);
     xlnt::read_worksheet(ws, ws_stream, { "string", "string2" }, {}, {});
     
     auto b1 = ws.get_cell("B1");
     TS_ASSERT(b1.has_formula());
     TS_ASSERT_EQUALS(b1.get_formula(), "CONCATENATE(A1,A2)");
     
     auto a6 = ws.get_cell("A6");
     TS_ASSERT(a6.has_formula());
     TS_ASSERT_EQUALS(a6.get_formula(), "SUM(A4:A5)");
 }
Exemplo n.º 3
0
    void test_formula2()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell(xlnt::cell_reference(1, 1));

        cell.value("=if(A1<4;-1;1)", true);
        xlnt_assert(cell.data_type() == xlnt::cell::type::number);
        xlnt_assert(cell.has_formula());
    }
Exemplo n.º 4
0
    void test_not_formula()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell(xlnt::cell_reference(1, 1));

        cell.value("=", true);
        xlnt_assert(cell.data_type() == xlnt::cell::type::shared_string);
        xlnt_assert(cell.value<std::string>() == "=");
        xlnt_assert(!cell.has_formula());
    }
Exemplo n.º 5
0
inline T tformula<T>::operator()(
		const game_logic::map_formula_callable& variables) const
{
	if(has_formula()) {
		const T& result = execute(variables);
		LOG_GUI_D << "Formula: execute '" << formula_
			<< "' result '" << result
			<< "'.\n";
		return result;
	} else {
		return value_;
	}
}
Exemplo n.º 6
0
	/**
	 * Returns the value, can only be used if the data is no formula.
	 *
	 * Another option would be to cache the output of the formula in value_
	 * and always allow this function. But for now decided that the caller
	 * needs to do the caching. It might be changed later.
	 */
	T operator()() const
	{
		assert(!has_formula());
		return value_;
	}
Exemplo n.º 7
0
bool cell::garbage_collectible() const
{
    return !(get_data_type() != type::null || is_merged() || has_comment() || has_formula() || has_style());
}