|
15 | 15 | /* |
16 | 16 | * According to the zval type written to the file |
17 | 17 | */ |
18 | | -void type_writer(zval *value, zend_long row, zend_long columns, xls_resource_t *res, zend_string *format) |
| 18 | +void type_writer(zval *value, zend_long row, zend_long columns, xls_resource_t *res, zend_string *format, lxw_format *format_handle) |
19 | 19 | { |
20 | 20 | lxw_format *value_format = NULL; |
21 | 21 |
|
22 | | - switch (Z_TYPE_P(value)) { |
23 | | - case IS_STRING: |
24 | | - worksheet_write_string(res->worksheet, row, columns, ZSTR_VAL(zval_get_string(value)), NULL); |
25 | | - break; |
26 | | - case IS_LONG: |
27 | | - if(format) { |
28 | | - value_format = workbook_add_format(res->workbook); |
29 | | - format_set_num_format(value_format, ZSTR_VAL(format)); |
30 | | - worksheet_write_number(res->worksheet, row, columns, zval_get_long(value), value_format); |
31 | | - } else { |
32 | | - worksheet_write_number(res->worksheet, row, columns, zval_get_long(value), NULL); |
33 | | - } |
34 | | - break; |
35 | | - case IS_DOUBLE: |
36 | | - if(format) { |
37 | | - value_format = workbook_add_format(res->workbook); |
38 | | - format_set_num_format(value_format, ZSTR_VAL(format)); |
39 | | - worksheet_write_number(res->worksheet, row, columns, zval_get_double(value), value_format); |
40 | | - } else { |
41 | | - worksheet_write_number(res->worksheet, row, columns, zval_get_double(value), NULL); |
42 | | - } |
43 | | - break; |
| 22 | + lxw_col_t lxw_col = (lxw_col_t)columns; |
| 23 | + lxw_row_t lxw_row = (lxw_row_t)row; |
| 24 | + |
| 25 | + zend_uchar value_type = Z_TYPE_P(value); |
| 26 | + |
| 27 | + if (value_type == IS_STRING) { |
| 28 | + worksheet_write_string(res->worksheet, lxw_row, lxw_col, ZSTR_VAL(zval_get_string(value)), format_handle); |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + if (value_type == IS_LONG) { |
| 33 | + if (format != NULL && format_handle == NULL) { |
| 34 | + value_format = workbook_add_format(res->workbook); |
| 35 | + |
| 36 | + format_set_num_format(value_format, ZSTR_VAL(format)); |
| 37 | + |
| 38 | + worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_long(value), value_format); |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + if (format == NULL && format_handle != NULL) { |
| 43 | + worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_long(value), format_handle); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + if(format != NULL && format_handle != NULL) { |
| 48 | + value_format = workbook_add_format(res->workbook); |
| 49 | + |
| 50 | + format_copy(value_format, format_handle); |
| 51 | + format_set_num_format(value_format, ZSTR_VAL(format)); |
| 52 | + |
| 53 | + worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_long(value), value_format); |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_long(value), NULL); |
44 | 58 | } |
| 59 | + |
| 60 | + if (value_type == IS_DOUBLE) { |
| 61 | + if (format != NULL && format_handle == NULL) { |
| 62 | + value_format = workbook_add_format(res->workbook); |
| 63 | + |
| 64 | + format_set_num_format(value_format, ZSTR_VAL(format)); |
| 65 | + |
| 66 | + worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_double(value), value_format); |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + if (format == NULL && format_handle != NULL) { |
| 71 | + worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_double(value), format_handle); |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + if(format != NULL && format_handle != NULL) { |
| 76 | + value_format = workbook_add_format(res->workbook); |
| 77 | + |
| 78 | + format_copy(value_format, format_handle); |
| 79 | + format_set_num_format(value_format, ZSTR_VAL(format)); |
| 80 | + |
| 81 | + worksheet_write_number(res->worksheet, lxw_row, lxw_col, zval_get_double(value), value_format); |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + worksheet_write_number(res->worksheet, row, columns, zval_get_double(value), NULL); |
| 86 | + return; |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +void format_copy(lxw_format *new_format, lxw_format *other_format) |
| 91 | +{ |
| 92 | + new_format->bold = other_format->bold; |
| 93 | + new_format->bg_color = other_format->bg_color; |
| 94 | + new_format->border_count = other_format->border_count; |
| 95 | + new_format->border_index = other_format->border_index; |
| 96 | + new_format->bottom = other_format->bottom; |
| 97 | + new_format->bottom_color = other_format->bottom_color; |
| 98 | + new_format->color_indexed = other_format->color_indexed; |
| 99 | + new_format->diag_border = other_format->diag_border; |
| 100 | + new_format->diag_color = other_format->diag_color; |
| 101 | + |
| 102 | + new_format->font_size = other_format->font_size; |
| 103 | + new_format->bold = other_format->bold; |
| 104 | + new_format->italic = other_format->italic; |
| 105 | + new_format->font_color = other_format->font_color; |
| 106 | + new_format->underline = other_format->underline; |
| 107 | + new_format->font_strikeout = other_format->font_strikeout; |
| 108 | + new_format->font_outline = other_format->font_outline; |
| 109 | + new_format->font_shadow = other_format->font_shadow; |
| 110 | + new_format->font_script = other_format->font_script; |
| 111 | + new_format->font_family = other_format->font_family; |
| 112 | + new_format->font_charset = other_format->font_charset; |
| 113 | + new_format->font_condense = other_format->font_condense; |
| 114 | + new_format->font_extend = other_format->font_extend; |
| 115 | + new_format->theme = other_format->theme; |
| 116 | + new_format->hyperlink = other_format->hyperlink; |
| 117 | + |
| 118 | + new_format->hidden = other_format->hidden; |
| 119 | + new_format->locked = other_format->locked; |
| 120 | + |
| 121 | + new_format->text_h_align = other_format->text_h_align; |
| 122 | + new_format->text_wrap = other_format->text_wrap; |
| 123 | + new_format->text_v_align = other_format->text_v_align; |
| 124 | + new_format->text_justlast = other_format->text_justlast; |
| 125 | + new_format->rotation = other_format->rotation; |
| 126 | + |
| 127 | + new_format->fg_color = other_format->fg_color; |
| 128 | + new_format->bg_color = other_format->bg_color; |
| 129 | + new_format->pattern = other_format->pattern; |
| 130 | + new_format->has_fill = other_format->has_fill; |
| 131 | + new_format->has_dxf_fill = other_format->has_dxf_fill; |
| 132 | + new_format->fill_index = other_format->fill_index; |
| 133 | + new_format->fill_count = other_format->fill_count; |
| 134 | + |
| 135 | + new_format->border_index = other_format->border_index; |
| 136 | + new_format->has_border = other_format->has_border; |
| 137 | + new_format->has_dxf_border = other_format->has_dxf_border; |
| 138 | + new_format->border_count = other_format->border_count; |
| 139 | + |
| 140 | + new_format->bottom = other_format->bottom; |
| 141 | + new_format->diag_border = other_format->diag_border; |
| 142 | + new_format->diag_type = other_format->diag_type; |
| 143 | + new_format->left = other_format->left; |
| 144 | + new_format->right = other_format->right; |
| 145 | + new_format->top = other_format->top; |
| 146 | + new_format->bottom_color = other_format->bottom_color; |
| 147 | + new_format->diag_color = other_format->diag_color; |
| 148 | + new_format->left_color = other_format->left_color; |
| 149 | + new_format->right_color = other_format->right_color; |
| 150 | + new_format->top_color = other_format->top_color; |
| 151 | + |
| 152 | + new_format->indent = other_format->indent; |
| 153 | + new_format->shrink = other_format->shrink; |
| 154 | + new_format->merge_range = other_format->merge_range; |
| 155 | + new_format->reading_order = other_format->reading_order; |
| 156 | + new_format->just_distrib = other_format->just_distrib; |
| 157 | + new_format->color_indexed = other_format->color_indexed; |
| 158 | + new_format->font_only = other_format->font_only; |
45 | 159 | } |
46 | 160 |
|
47 | 161 | void url_writer(zend_long row, zend_long columns, xls_resource_t *res, zend_string *url, lxw_format *format) |
|
0 commit comments