From 1aa4bf683c256ecd1a83e29e9f8e1655dddaf2f9 Mon Sep 17 00:00:00 2001 From: Dmitry Khayrutdinov Date: Mon, 9 Oct 2023 19:33:05 -0300 Subject: [PATCH] Set outline level for rows/columns --- include/help.h | 1 + include/xlswriter.h | 12 +- kernel/excel.c | 173 +++++++++++++----- kernel/help.c | 9 +- kernel/write.c | 14 +- tests/outline_level_column.phpt | 41 +++++ tests/outline_level_column_const_memory.phpt | 46 +++++ tests/outline_level_row.phpt | 50 +++++ tests/outline_level_row_const_memory.phpt | 75 ++++++++ ...on_limiting_to_a_single_or_range_cell.phpt | 4 + 10 files changed, 368 insertions(+), 57 deletions(-) create mode 100644 tests/outline_level_column.phpt create mode 100644 tests/outline_level_column_const_memory.phpt create mode 100644 tests/outline_level_row.phpt create mode 100644 tests/outline_level_row_const_memory.phpt diff --git a/include/help.h b/include/help.h index 931751e..6ecc2b1 100644 --- a/include/help.h +++ b/include/help.h @@ -18,5 +18,6 @@ unsigned int file_exists(const char *path); unsigned int directory_exists(const char *path); zend_long date_double_to_timestamp(double value); +lxw_row_col_options* default_row_col_options(); #endif //PHP_EXT_XLS_EXPORT_HELP_H diff --git a/include/xlswriter.h b/include/xlswriter.h index 5dcf4c3..93042d6 100644 --- a/include/xlswriter.h +++ b/include/xlswriter.h @@ -111,6 +111,7 @@ typedef struct _vtiful_xls_object { zend_long write_line; xls_resource_format_t format_ptr; xls_resource_formats_cache_t formats_cache_ptr; + lxw_row_col_options *row_options; zend_object zo; } xls_object; @@ -303,6 +304,11 @@ static inline void php_vtiful_close_resource(zend_object *obj) { zend_hash_destroy(intern->formats_cache_ptr.maps); } + if (intern->row_options != NULL) { + efree(intern->row_options); + intern->row_options = NULL; + } + #ifdef ENABLE_READER if (intern->read_ptr.sheet_t != NULL) { xlsxioread_sheet_close(intern->read_ptr.sheet_t); @@ -349,14 +355,14 @@ void printed_direction(xls_resource_write_t *res, unsigned int direction); void xls_file_path(zend_string *file_name, zval *dir_path, zval *file_path); void freeze_panes(xls_resource_write_t *res, zend_long row, zend_long column); void margins(xls_resource_write_t *res, double left, double right, double top, double bottom); -void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_format *format); +void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_format *format, lxw_row_col_options *user_options); void validation(xls_resource_write_t *res, zend_string *range, lxw_data_validation *validation); -void set_column(zend_string *range, double width, xls_resource_write_t *res, lxw_format *format); +void set_column(zend_string *range, double width, xls_resource_write_t *res, lxw_format *format, lxw_row_col_options *user_options); void merge_cells(zend_string *range, zval *value, xls_resource_write_t *res, lxw_format *format); void comment_writer(zend_string *comment, zend_long row, zend_long columns, xls_resource_write_t *res); void call_object_method(zval *object, const char *function_name, uint32_t param_count, zval *params, zval *ret_val); void chart_writer(zend_long row, zend_long columns, xls_resource_chart_t *chart_resource, xls_resource_write_t *res); -void worksheet_set_rows(lxw_row_t start, lxw_row_t end, double height, xls_resource_write_t *res, lxw_format *format); +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); void image_writer(zval *value, zend_long row, zend_long columns, double width, double height, xls_resource_write_t *res); void formula_writer(zend_string *value, zend_long row, zend_long columns, xls_resource_write_t *res, lxw_format *format); void type_writer(zval *value, zend_long row, zend_long columns, xls_resource_write_t *res, zend_string *format, lxw_format *format_handle); diff --git a/kernel/excel.c b/kernel/excel.c index c0ef9c9..475574b 100644 --- a/kernel/excel.c +++ b/kernel/excel.c @@ -43,6 +43,7 @@ PHP_VTIFUL_API zend_object *vtiful_xls_objects_new(zend_class_entry *ce) intern->format_ptr.format = NULL; intern->write_ptr.workbook = NULL; + intern->row_options = NULL; intern->formats_cache_ptr.maps = formats_cache_ht; @@ -187,16 +188,22 @@ ZEND_BEGIN_ARG_INFO_EX(xls_merge_cells_arginfo, 0, 0, 2) ZEND_ARG_INFO(0, format_handle) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(xls_set_column_arginfo, 0, 0, 3) - ZEND_ARG_INFO(0, format_handle) +ZEND_BEGIN_ARG_INFO_EX(xls_set_column_arginfo, 0, 0, 2) ZEND_ARG_INFO(0, range) ZEND_ARG_INFO(0, width) + ZEND_ARG_INFO(0, format_handle) + ZEND_ARG_INFO(0, level) + ZEND_ARG_INFO(0, collapsed) + ZEND_ARG_INFO(0, hidden) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(xls_set_row_arginfo, 0, 0, 3) - ZEND_ARG_INFO(0, format_handle) +ZEND_BEGIN_ARG_INFO_EX(xls_set_row_arginfo, 0, 0, 2) ZEND_ARG_INFO(0, range) ZEND_ARG_INFO(0, height) + ZEND_ARG_INFO(0, format_handle) + ZEND_ARG_INFO(0, level) + ZEND_ARG_INFO(0, collapsed) + ZEND_ARG_INFO(0, hidden) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(xls_set_curr_line_arginfo, 0, 0, 1) @@ -221,6 +228,12 @@ ZEND_BEGIN_ARG_INFO_EX(xls_set_global_format, 0, 0, 1) ZEND_ARG_INFO(0, format_handle) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(xls_set_default_row_options_arginfo, 0, 0, 0) + ZEND_ARG_INFO(0, level) + ZEND_ARG_INFO(0, collapsed) + ZEND_ARG_INFO(0, hidden) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(xls_open_file_arginfo, 0, 0, 1) ZEND_ARG_INFO(0, zs_file_name) ZEND_END_ARG_INFO() @@ -655,6 +668,11 @@ PHP_METHOD(vtiful_xls, data) continue; } + if (obj->row_options != NULL) { + WORKSHEET_WRITER_EXCEPTION( + worksheet_set_row_opt(obj->write_ptr.worksheet, SHEET_CURRENT_LINE(obj), LXW_DEF_ROW_HEIGHT, NULL, obj->row_options)); + } + column_index = 0; ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(data_r_value), index, key, data) { @@ -1020,64 +1038,92 @@ PHP_METHOD(vtiful_xls, mergeCells) } /* }}} */ -/** {{{ \Vtiful\Kernel\Excel::setColumn(resource $format, string $range [, int $width]) +/** {{{ \Vtiful\Kernel\Excel::setColumn(string $range, float $width, resource $format = null, int $level = 0, bool $collapsed = false, bool $hidden = false) */ PHP_METHOD(vtiful_xls, setColumn) { zval *format_handle = NULL; zend_string *range = NULL; - + zend_long level = 0; + zend_bool collapsed = 0; + zend_bool hidden = 0; double width = 0; - int argc = ZEND_NUM_ARGS(); - ZEND_PARSE_PARAMETERS_START(2, 3) + ZEND_PARSE_PARAMETERS_START(2, 6) Z_PARAM_STR(range) Z_PARAM_DOUBLE(width) Z_PARAM_OPTIONAL Z_PARAM_RESOURCE_OR_NULL(format_handle) + Z_PARAM_LONG_OR_NULL(level, _dummy) + Z_PARAM_BOOL_OR_NULL(collapsed, _dummy) + Z_PARAM_BOOL_OR_NULL(hidden, _dummy) ZEND_PARSE_PARAMETERS_END(); ZVAL_COPY(return_value, getThis()); + if (level < 0 || level > 7) { + LXW_WARN_FORMAT1("outline level must be in 0..7 range, '%d' given.", level); + level = 0; + } + xls_object *obj = Z_XLS_P(getThis()); WORKBOOK_NOT_INITIALIZED(obj); - if (argc == 3 && format_handle != NULL) { - set_column(range, width, &obj->write_ptr, zval_get_format(format_handle)); + lxw_row_col_options* options = default_row_col_options(); + options->level = level; + options->collapsed = collapsed; + options->hidden = hidden; + + if (format_handle != NULL) { + set_column(range, width, &obj->write_ptr, zval_get_format(format_handle), options); } else { - set_column(range, width, &obj->write_ptr, NULL); + set_column(range, width, &obj->write_ptr, NULL, options); } } /* }}} */ -/** {{{ \Vtiful\Kernel\Excel::setRow(resource $format, string $range [, int $heitght]) +/** {{{ \Vtiful\Kernel\Excel::setRow(string $range, float $height, resource $format = null, int $level = 0, bool $collapsed = false, bool $hidden = false) */ PHP_METHOD(vtiful_xls, setRow) { zval *format_handle = NULL; zend_string *range = NULL; - + zend_long level = 0; + zend_bool collapsed = 0; + zend_bool hidden = 0; double height = 0; - int argc = ZEND_NUM_ARGS(); - ZEND_PARSE_PARAMETERS_START(2, 3) + ZEND_PARSE_PARAMETERS_START(2, 6) Z_PARAM_STR(range) Z_PARAM_DOUBLE(height) Z_PARAM_OPTIONAL Z_PARAM_RESOURCE_OR_NULL(format_handle) + Z_PARAM_LONG_OR_NULL(level, _dummy) + Z_PARAM_BOOL_OR_NULL(collapsed, _dummy) + Z_PARAM_BOOL_OR_NULL(hidden, _dummy) ZEND_PARSE_PARAMETERS_END(); ZVAL_COPY(return_value, getThis()); + if (level < 0 || level > 7) { + LXW_WARN_FORMAT1("outline level must be in 0..7 range, '%d' given.", level); + level = 0; + } + xls_object *obj = Z_XLS_P(getThis()); WORKBOOK_NOT_INITIALIZED(obj); - if (argc == 3 && format_handle != NULL) { - set_row(range, height, &obj->write_ptr, zval_get_format(format_handle)); + lxw_row_col_options* options = default_row_col_options(); + options->level = level; + options->collapsed = collapsed; + options->hidden = hidden; + + if (format_handle != NULL) { + set_row(range, height, &obj->write_ptr, zval_get_format(format_handle), options); } else { - set_row(range, height, &obj->write_ptr, NULL); + set_row(range, height, &obj->write_ptr, NULL, options); } } /* }}} */ @@ -1140,6 +1186,39 @@ PHP_METHOD(vtiful_xls, defaultFormat) } /* }}} */ +/** {{{ \Vtiful\Kernel\Excel::defaultRowOptions(int $level = 0, bool $collapsed = false, bool $hidden = false) + */ +PHP_METHOD(vtiful_xls, defaultRowOptions) +{ + zend_long level = 0; + zend_bool collapsed = 0; + zend_bool hidden = 0; + + ZEND_PARSE_PARAMETERS_START(0, 3) + Z_PARAM_OPTIONAL + Z_PARAM_LONG_OR_NULL(level, _dummy) + Z_PARAM_BOOL_OR_NULL(collapsed, _dummy) + Z_PARAM_BOOL_OR_NULL(hidden, _dummy) + ZEND_PARSE_PARAMETERS_END(); + + ZVAL_COPY(return_value, getThis()); + + if (level < 0 || level > 7) { + LXW_WARN_FORMAT1("outline level must be in 0..7 range, '%d' given.", level); + level = 0; + } + + xls_object *obj = Z_XLS_P(getThis()); + + if (obj->row_options == NULL) { + obj->row_options = default_row_col_options(); + } + obj->row_options->level = level; + obj->row_options->collapsed = collapsed; + obj->row_options->hidden = hidden; +} +/* }}} */ + /** {{{ \Vtiful\Kernel\Excel::freezePanes(int $row, int $column) */ PHP_METHOD(vtiful_xls, freezePanes) @@ -1697,34 +1776,36 @@ PHP_METHOD(vtiful_xls, nextCellCallback) /** {{{ xls_methods */ zend_function_entry xls_methods[] = { - PHP_ME(vtiful_xls, __construct, xls_construct_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, close, xls_close_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, fileName, xls_file_name_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, addSheet, xls_file_add_sheet, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, existSheet, xls_file_exist_sheet, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, checkoutSheet, xls_file_checkout_sheet, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, activateSheet, xls_file_activate_sheet, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, constMemory, xls_const_memory_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, header, xls_header_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, data, xls_data_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, output, xls_output_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, getHandle, xls_get_handle_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, autoFilter, xls_auto_filter_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, insertText, xls_insert_text_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, insertRichText, xls_insert_rtext_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, insertDate, xls_insert_date_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, insertChart, xls_insert_chart_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, insertUrl, xls_insert_url_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, insertImage, xls_insert_image_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, insertFormula, xls_insert_formula_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, insertComment, xls_insert_comment_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, showComment, xls_show_comment_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, mergeCells, xls_merge_cells_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, setColumn, xls_set_column_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, setRow, xls_set_row_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, getCurrentLine, xls_get_curr_line_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, setCurrentLine, xls_set_curr_line_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, defaultFormat, xls_set_global_format, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, __construct, xls_construct_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, close, xls_close_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, fileName, xls_file_name_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, addSheet, xls_file_add_sheet, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, existSheet, xls_file_exist_sheet, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, checkoutSheet, xls_file_checkout_sheet, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, activateSheet, xls_file_activate_sheet, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, constMemory, xls_const_memory_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, header, xls_header_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, data, xls_data_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, output, xls_output_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, getHandle, xls_get_handle_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, autoFilter, xls_auto_filter_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, insertText, xls_insert_text_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, insertRichText, xls_insert_rtext_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, insertDate, xls_insert_date_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, insertChart, xls_insert_chart_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, insertUrl, xls_insert_url_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, insertImage, xls_insert_image_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, insertFormula, xls_insert_formula_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, insertComment, xls_insert_comment_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, showComment, xls_show_comment_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, mergeCells, xls_merge_cells_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, setColumn, xls_set_column_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, setRow, xls_set_row_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, getCurrentLine, xls_get_curr_line_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, setCurrentLine, xls_set_curr_line_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, defaultFormat, xls_set_global_format, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, defaultRowOptions, xls_set_default_row_options_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, freezePanes, xls_freeze_panes_arginfo, ZEND_ACC_PUBLIC) PHP_ME(vtiful_xls, protection, xls_protection_arginfo, ZEND_ACC_PUBLIC) diff --git a/kernel/help.c b/kernel/help.c index 1f389f8..832a518 100644 --- a/kernel/help.c +++ b/kernel/help.c @@ -104,4 +104,11 @@ unsigned int file_exists(const char *path) { zval_ptr_dtor(&file_exists); return XLSWRITER_TRUE; } -/* }}} */ \ No newline at end of file +/* }}} */ + +lxw_row_col_options* default_row_col_options() { + size_t obj_size = sizeof(lxw_row_col_options); + void *obj = emalloc(obj_size); + memset(obj, 0, obj_size); + return obj; +} \ No newline at end of file diff --git a/kernel/write.c b/kernel/write.c index 0887502..734a5b8 100644 --- a/kernel/write.c +++ b/kernel/write.c @@ -296,9 +296,9 @@ void merge_cells(zend_string *range, zval *value, xls_resource_write_t *res, lxw /* * Set column format */ -void set_column(zend_string *range, double width, xls_resource_write_t *res, lxw_format *format) +void set_column(zend_string *range, double width, xls_resource_write_t *res, lxw_format *format, lxw_row_col_options *user_options) { - int error = worksheet_set_column(res->worksheet, COLS(ZSTR_VAL(range)), width, format); + int error = worksheet_set_column_opt(res->worksheet, COLS(ZSTR_VAL(range)), width, format, user_options); // Cells that have been placed cannot be modified using optimization mode WORKSHEET_INDEX_OUT_OF_CHANGE_IN_OPTIMIZE_EXCEPTION(res, error) @@ -310,14 +310,14 @@ void set_column(zend_string *range, double width, xls_resource_write_t *res, lxw /* * Set row format */ -void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_format *format) +void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_format *format, lxw_row_col_options *user_options) { char *rows = ZSTR_VAL(range); if (strchr(rows, ':')) { - worksheet_set_rows(ROWS(rows), height, res, format); + worksheet_set_rows(ROWS(rows), height, res, format, user_options); } else { - int error = worksheet_set_row(res->worksheet, ROW(rows), height, format); + int error = worksheet_set_row_opt(res->worksheet, ROW(rows), height, format, user_options); // Cells that have been placed cannot be modified using optimization mode WORKSHEET_INDEX_OUT_OF_CHANGE_IN_OPTIMIZE_EXCEPTION(res, error) @@ -344,10 +344,10 @@ void validation(xls_resource_write_t *res, zend_string *range, lxw_data_validati /* * Set rows format */ -void worksheet_set_rows(lxw_row_t start, lxw_row_t end, double height, xls_resource_write_t *res, lxw_format *format) +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) { while (1) { - worksheet_set_row(res->worksheet, end, height, format); + worksheet_set_row_opt(res->worksheet, end, height, format, user_options); if (end == start) break; end--; diff --git a/tests/outline_level_column.phpt b/tests/outline_level_column.phpt new file mode 100644 index 0000000..1731f4f --- /dev/null +++ b/tests/outline_level_column.phpt @@ -0,0 +1,41 @@ +--TEST-- +Check for vtiful presence +--SKIPIF-- + +--FILE-- + './tests']; +$excel = new \Vtiful\Kernel\Excel($config); + +$excel->fileName('outline_level_column.xlsx'); + +$format = new \Vtiful\Kernel\Format($excel->getHandle()); +$boldStyle = $format->bold()->toResource(); + +$filePath = $excel + ->header(['Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Total', 'hidden column I']) + ->data([ + ['North', 50, 20, 15, 25, 65, 80, 255], + ['South', 10, 20, 30, 50, 50, 50, 210], + ['East', 45, 75, 50, 15, 75, 100, 360], + ['West', 15, 15, 55, 35, 20, 50, 190], + ]) + ->insertText(5, 7, 1015, '', $boldStyle) + ->setRow('A1', 15, $boldStyle) + ->setColumn('A:A', 10, $boldStyle) + ->setColumn('B:G', 10, null, 1) + ->setColumn('H:H', 10, null, 0, true) + ->setColumn('I:I', 10, null, null, false, true) + ->output(); + +var_dump($filePath); +?> +--CLEAN-- + +--EXPECT-- +string(33) "./tests/outline_level_column.xlsx" diff --git a/tests/outline_level_column_const_memory.phpt b/tests/outline_level_column_const_memory.phpt new file mode 100644 index 0000000..8b91986 --- /dev/null +++ b/tests/outline_level_column_const_memory.phpt @@ -0,0 +1,46 @@ +--TEST-- +Check for vtiful presence +--SKIPIF-- + +--FILE-- + './tests']; +$excel = new \Vtiful\Kernel\Excel($config); + +$excel->constMemory('outline_level_column_const_memory.xlsx'); + +$format = new \Vtiful\Kernel\Format($excel->getHandle()); +$defaultStyle = $format->toResource(); + +$format = new \Vtiful\Kernel\Format($excel->getHandle()); +$boldStyle = $format->bold()->toResource(); + +$filePath = $excel + ->defaultFormat($boldStyle) + ->header(['Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Total', 'hidden column I']) + ->defaultFormat($defaultStyle) + ->data([ + ['North', 50, 20, 15, 25, 65, 80, 255], + ['South', 10, 20, 30, 50, 50, 50, 210], + ['East', 45, 75, 50, 15, 75, 100, 360], + ['West', 15, 15, 55, 35, 20, 50, 190], + ]) + ->insertText(5, 7, 1015, '', $boldStyle) + ->setColumn('A:A', 10, $boldStyle) + ->setColumn('B:G', 10, null, 1) + ->setColumn('H:H', 10, null, 0, true) + ->setColumn('I:I', 10, null, null, false, true) + ->output(); + +var_dump($filePath); +?> +--CLEAN-- + +--EXPECT-- +string(46) "./tests/outline_level_column_const_memory.xlsx" diff --git a/tests/outline_level_row.phpt b/tests/outline_level_row.phpt new file mode 100644 index 0000000..0ce161f --- /dev/null +++ b/tests/outline_level_row.phpt @@ -0,0 +1,50 @@ +--TEST-- +Check for vtiful presence +--SKIPIF-- + +--FILE-- + './tests']; +$excel = new \Vtiful\Kernel\Excel($config); + +$excel->fileName('outline_level_row.xlsx'); + +$format = new \Vtiful\Kernel\Format($excel->getHandle()); +$boldStyle = $format->bold()->toResource(); + +$filePath = $excel + ->header(['Region', 'Sales']) + ->data([ + ['North', 1000], // row 2 + ['North', 1200], + ['North', 900], + ['North', 1200], + ['North Total', 4300], // row 6 + ['South', 400], // row 7 + ['South', 600], + ['South', 500], + ['South', 600], + ['South Total', 2100], // row 11 + ['Grand Total', 6400], // row 12 + ['hidden row', 0], + ]) + ->setRow('A1', 15, $boldStyle) + ->setRow('A2:A5', 15, null, 2, false, true) + ->setRow('A6', 15, $boldStyle, 1, true) + ->setRow('A7:A10', 15, null, 2) + ->setRow('A11', 15, $boldStyle, 1) + ->setRow('A12', 15, $boldStyle, 0) + ->setRow('A13', 15, $boldStyle, null, null, true) + ->output(); + +var_dump($filePath); +?> +--CLEAN-- + +--EXPECT-- +string(30) "./tests/outline_level_row.xlsx" diff --git a/tests/outline_level_row_const_memory.phpt b/tests/outline_level_row_const_memory.phpt new file mode 100644 index 0000000..fb0cf4d --- /dev/null +++ b/tests/outline_level_row_const_memory.phpt @@ -0,0 +1,75 @@ +--TEST-- +Check for vtiful presence +--SKIPIF-- + +--FILE-- + './tests']; +$excel = new \Vtiful\Kernel\Excel($config); + +$excel->constMemory('outline_level_row_const_memory.xlsx'); + +$format = new \Vtiful\Kernel\Format($excel->getHandle()); +$defaultStyle = $format->toResource(); + +$format = new \Vtiful\Kernel\Format($excel->getHandle()); +$boldStyle = $format->bold()->toResource(); + +$filePath = $excel + ->defaultFormat($boldStyle) + ->header(['Region', 'Sales']) + + ->defaultFormat($defaultStyle) + ->defaultRowOptions(2, false, true) + ->data([ + ['North', 1000], + ['North', 1200], + ['North', 900], + ['North', 1200], + ]) + + ->defaultFormat($boldStyle) + ->defaultRowOptions(1, true) + ->data([ + ['North Total', 4300], + ]) + + ->defaultFormat($defaultStyle) + ->defaultRowOptions(2) + ->data([ + ['South', 400], + ['South', 600], + ['South', 500], + ['South', 600], + ]) + + ->defaultFormat($boldStyle) + ->defaultRowOptions(1) + ->data([ + ['South Total', 2100], + ]) + + ->defaultRowOptions(0) + ->data([ + ['Grand Total', 6400], + ]) + + ->defaultRowOptions(null, null, true) + ->data([ + ['hidden row', 0], + ]) + + ->output(); + +var_dump($filePath); +?> +--CLEAN-- + +--EXPECT-- +string(43) "./tests/outline_level_row_const_memory.xlsx" diff --git a/tests/validation_limiting_to_a_single_or_range_cell.phpt b/tests/validation_limiting_to_a_single_or_range_cell.phpt index ed56dcb..27966fa 100644 --- a/tests/validation_limiting_to_a_single_or_range_cell.phpt +++ b/tests/validation_limiting_to_a_single_or_range_cell.phpt @@ -18,6 +18,10 @@ $filePath = $excel->fileName('tutorial.xlsx') var_dump($validation, $filePath); ?> +--CLEAN-- + --EXPECT-- object(Vtiful\Kernel\Validation)#1 (0) { }