Пример #1
0
    void test_number_format()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell("A1");

        xlnt::number_format format("dd--hh--mm");
        cell.number_format(format);

        xlnt_assert(cell.has_format());
        xlnt_assert(cell.format().number_format_applied());
        xlnt_assert_equals(cell.number_format().format_string(), "dd--hh--mm");
    }
Пример #2
0
number_format number_format::from_builtin_id(std::size_t builtin_id)
{
    if (builtin_formats().find(builtin_id) == builtin_formats().end())
    {
        throw invalid_parameter(); //("unknown id: " + std::to_string(builtin_id));
    }

    auto format_string = builtin_formats().at(builtin_id);
    return number_format(format_string, builtin_id);
}
Пример #3
0
    void test_insert_time()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell(xlnt::cell_reference(1, 1));

        cell.value(xlnt::time(1, 3));
        xlnt_assert(cell.data_type() == xlnt::cell::type::number);
        xlnt_assert_delta(cell.value<long double>(), 0.04375L, 1E-9);
        xlnt_assert(cell.is_date());
        xlnt_assert(cell.number_format().format_string() == "h:mm:ss");
    }
Пример #4
0
    void test_insert_date()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell(xlnt::cell_reference(1, 1));

        cell.value(xlnt::date(2010, 7, 13));
        xlnt_assert(cell.data_type() == xlnt::cell::type::number);
        xlnt_assert(cell.value<long double>() == 40372.L);
        xlnt_assert(cell.is_date());
        xlnt_assert(cell.number_format().format_string() == "yyyy-mm-dd");
    }
Пример #5
0
    void test_timedelta()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell(xlnt::cell_reference(1, 1));

        cell.value(xlnt::timedelta(1, 3, 0, 0, 0));

        xlnt_assert(cell.value<long double>() == 1.125);
        xlnt_assert(cell.data_type() == xlnt::cell::type::number);
        xlnt_assert(!cell.is_date());
        xlnt_assert(cell.number_format().format_string() == "[hh]:mm:ss");
    }
Пример #6
0
    void test_insert_datetime()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell(xlnt::cell_reference(1, 1));

        cell.value(xlnt::datetime(2010, 7, 13, 6, 37, 41));

        xlnt_assert(cell.data_type() == xlnt::cell::type::number);
        xlnt_assert_delta(cell.value<long double>(), 40372.27616898148L, 1E-9);
        xlnt_assert(cell.is_date());
        xlnt_assert(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss");
    }
Пример #7
0
// func Object tm_str(Object a)
Object tm_str(Object a) {
    char buf[100];
    memset(buf, 0, sizeof(buf));
    switch (TM_TYPE(a)) {
    case TYPE_STR:
        return a;
    case TYPE_NUM: {
        char s[20];
        double v = GET_NUM(a);
        number_format(s, a);
        return string_new(s);
    }
    case TYPE_LIST: {
        Object str = string_new("");

        str = string_append_char(str, '[');
        int i, l = LIST_LEN(a);
        for (i = 0; i < l; i++) {
            Object obj = GET_LIST(a)->nodes[i];
            /* reference to self in list */
            if (obj_equals(a, obj)) {
                str = string_append_sz(str, "[...]");
            } else if (obj.type == TYPE_STR) {
                str = string_append_char(str, '"');
                str = string_append_obj(str, obj);
                str = string_append_char(str, '"');
            } else {
                str = string_append_obj(str, obj);
            }
            if (i != l - 1) {
                str = string_append_char(str, ',');
            }
        }
        str = string_append_char(str, ']');
        return str;
    }
    case TYPE_DICT:
        sprintf(buf, "<dict at %p>", GET_DICT(a));
        return string_new(buf);
    case TYPE_FUNCTION:
        function_format(buf, a);
        return string_new(buf);
    case TYPE_NONE:
        return sz_to_string("None");
    case TYPE_DATA:
        return GET_DATA(a)->str(GET_DATA(a));
    default:
        tm_raise("str: not supported type %d", a.type);
    }
    return string_alloc("", 0);
}
Пример #8
0
    void test_style()
    {
        xlnt::workbook wb;
        auto ws = wb.active_sheet();
        auto cell = ws.cell("A1");

        xlnt_assert(!cell.has_style());

        auto test_style = wb.create_style("test_style");
        test_style.number_format(xlnt::number_format::date_ddmmyyyy(), true);

        cell.style(test_style);
        xlnt_assert(cell.has_style());
        xlnt_assert_equals(cell.style().number_format(), xlnt::number_format::date_ddmmyyyy());
        xlnt_assert_equals(cell.style(), test_style);

        auto other_style = wb.create_style("other_style");
        other_style.number_format(xlnt::number_format::date_time2(), true);

        cell.style("other_style");
        xlnt_assert_equals(cell.style().number_format(), xlnt::number_format::date_time2());
        xlnt_assert_equals(cell.style(), other_style);

        auto last_style = wb.create_style("last_style");
        last_style.number_format(xlnt::number_format::percentage(), true);

        cell.style(last_style);
        xlnt_assert_equals(cell.style().number_format(), xlnt::number_format::percentage());
        xlnt_assert_equals(cell.style(), last_style);

        xlnt_assert_throws(cell.style("doesn't exist"), xlnt::key_not_found);

        cell.clear_style();

        xlnt_assert(!cell.has_style());
        xlnt_assert_throws(cell.style(), xlnt::invalid_attribute);
    }