Class: XlsxWriter::Workbook::Properties
- Inherits:
-
Object
- Object
- XlsxWriter::Workbook::Properties
- Defined in:
- ext/xlsxwriter/workbook_properties.c,
ext/xlsxwriter/workbook_properties.c
Overview
The class defines accessors for workbook properties.
Setting standard workbook text properties:
wb_properties.title = title
wb_properties.subject = subjet
wb_properties. =
wb_properties.manager = manager
wb_properties.company = company
wb_properties.category = category
wb_properties.keywords = keywords
wb_properties.comments = comments
wb_properties.status = status
You can see the properties under Office Button -> Prepare -> Properties in Excel.
Instance Method Summary collapse
-
#[]=(property) ⇒ Object
Sets a document
property
(both custom and standard). -
#initialize(workbook) ⇒ Object
constructor
:nodoc:.
Constructor Details
#initialize(workbook) ⇒ Object
:nodoc:
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'ext/xlsxwriter/workbook_properties.c', line 10
VALUE
workbook_properties_init_(VALUE self, VALUE workbook) {
struct workbook *wb_ptr;
rb_iv_set(self, "@workbook", workbook);
TypedData_Get_Struct(workbook, struct workbook, &workbook_type, wb_ptr);
if (!wb_ptr->properties) {
wb_ptr->properties = calloc(1, sizeof(lxw_doc_properties));
}
if (rb_block_given_p()) {
rb_yield(self);
}
return self;
}
|
Instance Method Details
#[]=(property) ⇒ Object
Sets a document property
(both custom and standard). Property type is automatically deduced from the value
.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'ext/xlsxwriter/workbook_properties.c', line 29
VALUE
workbook_properties_set_(VALUE self, VALUE key, VALUE value) {
char *key_cstr = NULL;
switch (TYPE(key)) {
case T_STRING:
key_cstr = StringValueCStr(key);
break;
case T_SYMBOL:
key = rb_sym2str(key);
key_cstr = StringValueCStr(key);
break;
default:
rb_raise(rb_eArgError, "Wrong type of key: %"PRIsVALUE, rb_obj_class(key));
}
struct workbook *wb_ptr;
TypedData_Get_Struct(rb_iv_get(self, "@workbook"), struct workbook, &workbook_type, wb_ptr);
lxw_doc_properties *props = wb_ptr->properties;
if (!props) {
rb_raise(rb_eRuntimeError, "Workbook properties are already freed.");
}
#define HANDLE_PROP(prop) { \
if (!strcmp(#prop, key_cstr)) { \
props->prop = ruby_strdup(StringValueCStr(value)); \
return value; \
} \
}
HANDLE_PROP(title);
HANDLE_PROP(subject);
HANDLE_PROP(author);
HANDLE_PROP(manager);
HANDLE_PROP(company);
HANDLE_PROP(category);
HANDLE_PROP(keywords);
HANDLE_PROP(comments);
HANDLE_PROP(status);
HANDLE_PROP(hyperlink_base);
#undef HANDLE_PROP
// Not a standard property.
switch (TYPE(value)) {
case T_NIL:
break;
case T_STRING:
workbook_set_custom_property_string(wb_ptr->workbook, key_cstr, StringValueCStr(value));
break;
case T_FLOAT: case T_RATIONAL:
workbook_set_custom_property_number(wb_ptr->workbook, key_cstr, NUM2DBL(value));
break;
case T_FIXNUM: case T_BIGNUM:
workbook_set_custom_property_integer(wb_ptr->workbook, key_cstr, NUM2INT(value));
break;
case T_TRUE: case T_FALSE:
workbook_set_custom_property_boolean(wb_ptr->workbook, key_cstr, value != Qfalse);
break;
case T_DATA:
if (rb_obj_class(value) == rb_cTime) {
lxw_datetime datetime = value_to_lxw_datetime(value);
workbook_set_custom_property_datetime(wb_ptr->workbook, key_cstr, &datetime);
} else {
rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE
" (must be string, numeric, true, false, nil or time)",
rb_obj_class(value));
}
break;
}
return value;
}
|