Skip to content

Commit a6ee092

Browse files
authored
Merge branch 'viest:master' into format_rotation
2 parents 89a557f + 2011ae9 commit a6ee092

19 files changed

+536
-136
lines changed

config.m4

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
1-
PHP_ARG_WITH(xlswriter, xlswriter support,
2-
[ --with-xlswriter Include xlswriter support], yes)
3-
4-
PHP_ARG_WITH(libxlsxwriter, system libxlsxwriter,
5-
[ --with-libxlsxwriter=DIR Use system libxlsxwriter], no, no)
6-
7-
PHP_ARG_WITH(libxlsxio, system libxlsxio,
8-
[ --with-libxlsxio=DIR Use system libxlsxio], no, no)
9-
10-
PHP_ARG_WITH(openssl, openssl MD5,
11-
[ --with-openssl=DIR Use openssl MD5], no, no)
12-
13-
PHP_ARG_ENABLE(reader, enable xlsx reader support,
14-
[ --enable-reader Enable xlsx reader?], yes, yes)
1+
PHP_ARG_WITH([xlswriter],
2+
[xlswriter support],
3+
[AS_HELP_STRING([--without-xlswriter],
4+
[Disable xlswriter support])],
5+
[yes])
6+
7+
PHP_ARG_WITH([libxlsxwriter],
8+
[system libxlsxwriter],
9+
[AS_HELP_STRING([[--with-libxlsxwriter[=DIR]]],
10+
[Use system libxlsxwriter])],
11+
[no],
12+
[no])
13+
14+
PHP_ARG_WITH([libxlsxio],
15+
[system libxlsxio],
16+
[AS_HELP_STRING([[--with-libxlsxio[=DIR]]],
17+
[Use system libxlsxio])],
18+
[no],
19+
[no])
20+
21+
PHP_ARG_WITH([openssl],
22+
[openssl MD5],
23+
[AS_HELP_STRING([[--with-openssl[=DIR]]],
24+
[Use openssl MD5])],
25+
[no],
26+
[no])
27+
28+
PHP_ARG_ENABLE([reader],
29+
[whether to enable the xlsx reader support],
30+
[AS_HELP_STRING([--disable-reader],
31+
[Disable xlsx reader])],
32+
[yes])
1533

1634
if test "$PHP_XLSWRITER" != "no"; then
1735
xls_writer_sources="

config.w32

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
ARG_WITH("xlswriter", "xlswriter support", "no");
44

55
if (PHP_XLSWRITER != "no") {
6-
76
if (
87
CHECK_HEADER_ADD_INCLUDE("minizip/zip.h", "CFLAGS_XLSWRITER", configure_module_dirname + "\\library\\libxlsxwriter\\third_party;" + PHP_EXTRA_INCLUDES) &&
98
CHECK_HEADER_ADD_INCLUDE("xlsxwriter.h", "CFLAGS_XLSWRITER", configure_module_dirname + "\\library\\libxlsxwriter\\include;" + PHP_EXTRA_INCLUDES) &&

include/help.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
unsigned int file_exists(const char *path);
1919
unsigned int directory_exists(const char *path);
2020
zend_long date_double_to_timestamp(double value);
21+
lxw_row_col_options* default_row_col_options();
2122

2223
#endif //PHP_EXT_XLS_EXPORT_HELP_H

include/xlswriter.h

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ typedef struct {
8888
lxw_format *format;
8989
} xls_resource_format_t;
9090

91+
typedef struct {
92+
HashTable *maps;
93+
} xls_resource_formats_cache_t;
94+
9195
typedef struct {
9296
lxw_data_validation *validation;
9397
} xls_resource_validation_t;
@@ -102,11 +106,13 @@ typedef struct {
102106
} xls_resource_rich_string_t;
103107

104108
typedef struct _vtiful_xls_object {
105-
xls_resource_read_t read_ptr;
106-
xls_resource_write_t write_ptr;
107-
zend_long write_line;
108-
xls_resource_format_t format_ptr;
109-
zend_object zo;
109+
xls_resource_read_t read_ptr;
110+
xls_resource_write_t write_ptr;
111+
zend_long write_line;
112+
xls_resource_format_t format_ptr;
113+
xls_resource_formats_cache_t formats_cache_ptr;
114+
lxw_row_col_options *row_options;
115+
zend_object zo;
110116
} xls_object;
111117

112118
typedef struct _vtiful_format_object {
@@ -294,6 +300,15 @@ static inline void php_vtiful_close_resource(zend_object *obj) {
294300
intern->format_ptr.format = NULL;
295301
}
296302

303+
if (intern->formats_cache_ptr.maps != NULL) {
304+
zend_hash_destroy(intern->formats_cache_ptr.maps);
305+
}
306+
307+
if (intern->row_options != NULL) {
308+
efree(intern->row_options);
309+
intern->row_options = NULL;
310+
}
311+
297312
#ifdef ENABLE_READER
298313
if (intern->read_ptr.sheet_t != NULL) {
299314
xlsxioread_sheet_close(intern->read_ptr.sheet_t);
@@ -340,14 +355,14 @@ void printed_direction(xls_resource_write_t *res, unsigned int direction);
340355
void xls_file_path(zend_string *file_name, zval *dir_path, zval *file_path);
341356
void freeze_panes(xls_resource_write_t *res, zend_long row, zend_long column);
342357
void margins(xls_resource_write_t *res, double left, double right, double top, double bottom);
343-
void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_format *format);
358+
void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_format *format, lxw_row_col_options *user_options);
344359
void validation(xls_resource_write_t *res, zend_string *range, lxw_data_validation *validation);
345-
void set_column(zend_string *range, double width, xls_resource_write_t *res, lxw_format *format);
360+
void set_column(zend_string *range, double width, xls_resource_write_t *res, lxw_format *format, lxw_row_col_options *user_options);
346361
void merge_cells(zend_string *range, zval *value, xls_resource_write_t *res, lxw_format *format);
347362
void comment_writer(zend_string *comment, zend_long row, zend_long columns, xls_resource_write_t *res);
348363
void call_object_method(zval *object, const char *function_name, uint32_t param_count, zval *params, zval *ret_val);
349364
void chart_writer(zend_long row, zend_long columns, xls_resource_chart_t *chart_resource, xls_resource_write_t *res);
350-
void worksheet_set_rows(lxw_row_t start, lxw_row_t end, double height, xls_resource_write_t *res, lxw_format *format);
365+
void worksheet_set_rows(lxw_row_t start, lxw_row_t end, double height, xls_resource_write_t *res, lxw_format *format, lxw_row_col_options *user_options);
351366
void image_writer(zval *value, zend_long row, zend_long columns, double width, double height, xls_resource_write_t *res);
352367
void formula_writer(zend_string *value, zend_long row, zend_long columns, xls_resource_write_t *res, lxw_format *format);
353368
void type_writer(zval *value, zend_long row, zend_long columns, xls_resource_write_t *res, zend_string *format, lxw_format *format_handle);
@@ -361,4 +376,6 @@ lxw_datetime timestamp_to_datetime(zend_long timestamp);
361376
zend_string* char_join_to_zend_str(const char *left, const char *right);
362377
zend_string* str_pick_up(zend_string *left, const char *right, size_t len);
363378

379+
lxw_format* object_format(xls_object *obj, zend_string *format, lxw_format *format_handle);
380+
364381
#endif

kernel/common.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void call_object_method(zval *object, const char *function_name, uint32_t param_
8888
}
8989
/* }}} */
9090

91+
/* {{{ */
9192
lxw_datetime timestamp_to_datetime(zend_long timestamp)
9293
{
9394
int yearLocal = php_idate('Y', timestamp, 0);
@@ -102,4 +103,53 @@ lxw_datetime timestamp_to_datetime(zend_long timestamp)
102103
};
103104

104105
return datetime;
105-
}
106+
}
107+
/* }}} */
108+
109+
/* {{{ */
110+
lxw_format* object_format(xls_object *obj, zend_string *format, lxw_format *format_handle)
111+
{
112+
if (format == NULL && format_handle == NULL) {
113+
return NULL;
114+
}
115+
116+
if (format != NULL && format_handle != NULL) {
117+
zend_string *_format_key = strpprintf(0, "%p|%s", format_handle, format->val);
118+
119+
void *exit_format = zend_hash_str_find_ptr(obj->formats_cache_ptr.maps, ZEND_STRL(_format_key->val));
120+
121+
if (exit_format != NULL) {
122+
zend_string_release(_format_key);
123+
124+
return (lxw_format *)exit_format;
125+
}
126+
127+
lxw_format *new_format = workbook_add_format((&obj->write_ptr)->workbook);
128+
format_copy(new_format, format_handle);
129+
format_set_num_format(new_format, ZSTR_VAL(format));
130+
131+
zend_hash_str_add_ptr(obj->formats_cache_ptr.maps, ZEND_STRL(_format_key->val), new_format);
132+
133+
zend_string_release(_format_key);
134+
135+
return new_format;
136+
}
137+
138+
if (format != NULL) {
139+
void *exit_format = zend_hash_str_find_ptr(obj->formats_cache_ptr.maps, ZEND_STRL(format->val));
140+
141+
if (exit_format != NULL) {
142+
return (lxw_format *)exit_format;
143+
}
144+
145+
lxw_format *new_format = workbook_add_format((&obj->write_ptr)->workbook);
146+
format_set_num_format(new_format, ZSTR_VAL(format));
147+
148+
zend_hash_str_add_ptr(obj->formats_cache_ptr.maps, ZEND_STRL(format->val), new_format);
149+
150+
return new_format;
151+
}
152+
153+
return format_handle;
154+
}
155+
/* }}} */

0 commit comments

Comments
 (0)