diff --git a/include/xlswriter.h b/include/xlswriter.h index 57756a6..8655674 100644 --- a/include/xlswriter.h +++ b/include/xlswriter.h @@ -307,6 +307,7 @@ void comment_show(xls_resource_write_t *res); void hide_worksheet(xls_resource_write_t *res); void first_worksheet(xls_resource_write_t *res); void zoom(xls_resource_write_t *res, zend_long zoom); +void paper(xls_resource_write_t *res, zend_long type); void gridlines(xls_resource_write_t *res, zend_long option); void auto_filter(zend_string *range, xls_resource_write_t *res); void protection(xls_resource_write_t *res, zend_string *password); @@ -314,6 +315,7 @@ void format_copy(lxw_format *new_format, lxw_format *other_format); 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 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); diff --git a/kernel/excel.c b/kernel/excel.c index 1ead914..2f9e238 100644 --- a/kernel/excel.c +++ b/kernel/excel.c @@ -186,6 +186,17 @@ ZEND_BEGIN_ARG_INFO_EX(xls_set_row_arginfo, 0, 0, 3) ZEND_ARG_INFO(0, height) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(xls_set_paper_arginfo, 0, 0, 1) + ZEND_ARG_INFO(0, paper) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(xls_set_margins_arginfo, 0, 0, 4) + ZEND_ARG_INFO(0, left) + ZEND_ARG_INFO(0, right) + ZEND_ARG_INFO(0, top) + ZEND_ARG_INFO(0, bottom) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(xls_set_global_format, 0, 0, 1) ZEND_ARG_INFO(0, format_handle) ZEND_END_ARG_INFO() @@ -972,6 +983,47 @@ PHP_METHOD(vtiful_xls, setRow) } /* }}} */ +/** {{{ \Vtiful\Kernel\Excel::setPaper(int $paper) + */ +PHP_METHOD(vtiful_xls, setPaper) +{ + zend_long type = 0; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(type) + ZEND_PARSE_PARAMETERS_END(); + + ZVAL_COPY(return_value, getThis()); + + xls_object *obj = Z_XLS_P(getThis()); + + paper(&obj->write_ptr, type); +} +/* }}} */ + +/** {{{ \Vtiful\Kernel\Excel::setMargins(double|null $left, double|null $right, double|null $top, double|null $bottom) + */ +PHP_METHOD(vtiful_xls, setMargins) +{ + double left = 0.7, right = 0.7, top = 0.75, bottom = 0.75; + + ZEND_PARSE_PARAMETERS_START(0, 4) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE_OR_NULL(left, _dummy) + Z_PARAM_DOUBLE_OR_NULL(right, _dummy) + Z_PARAM_DOUBLE_OR_NULL(top, _dummy) + Z_PARAM_DOUBLE_OR_NULL(bottom, _dummy) + ZEND_PARSE_PARAMETERS_END(); + + ZVAL_COPY(return_value, getThis()); + + xls_object *obj = Z_XLS_P(getThis()); + + // units: inches to cm + margins(&obj->write_ptr, left / 2.54, right / 2.54, top / 2.54, bottom / 2.54); +} +/* }}} */ + /** {{{ \Vtiful\Kernel\Excel::defaultFormat(resource $format) */ PHP_METHOD(vtiful_xls, defaultFormat) @@ -1149,10 +1201,9 @@ PHP_METHOD(vtiful_xls, protection) } /* }}} */ - -/** {{{ \Vtiful\Kernel\Excel::setPrintedPortrait() +/** {{{ \Vtiful\Kernel\Excel::setPortrait() */ -PHP_METHOD(vtiful_xls, setPrintedPortrait) +PHP_METHOD(vtiful_xls, setPortrait) { ZVAL_COPY(return_value, getThis()); @@ -1165,9 +1216,9 @@ PHP_METHOD(vtiful_xls, setPrintedPortrait) /* }}} */ -/** {{{ \Vtiful\Kernel\Excel::setPrintedLandscape() +/** {{{ \Vtiful\Kernel\Excel::setLandscape() */ -PHP_METHOD(vtiful_xls, setPrintedLandscape) +PHP_METHOD(vtiful_xls, setLandscape) { ZVAL_COPY(return_value, getThis()); @@ -1561,8 +1612,10 @@ zend_function_entry xls_methods[] = { PHP_ME(vtiful_xls, zoom, xls_sheet_zoom_arginfo, ZEND_ACC_PUBLIC) PHP_ME(vtiful_xls, gridline, xls_sheet_gridline_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, setPrintedPortrait, xls_set_printed_portrait_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(vtiful_xls, setPrintedLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, setPaper, xls_set_paper_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, setMargins, xls_set_margins_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, setPortrait, xls_set_printed_portrait_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(vtiful_xls, setLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC) PHP_ME(vtiful_xls, setCurrentSheetHide, xls_hide_sheet_arginfo, ZEND_ACC_PUBLIC) PHP_ME(vtiful_xls, setCurrentSheetIsFirst, xls_first_sheet_arginfo, ZEND_ACC_PUBLIC) @@ -1619,6 +1672,47 @@ VTIFUL_STARTUP_FUNCTION(excel) { REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "GRIDLINES_SHOW_PRINT", LXW_SHOW_PRINT_GRIDLINES) REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "GRIDLINES_SHOW_SCREEN", LXW_SHOW_SCREEN_GRIDLINES) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_DEFAULT", 0) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_LETTER", 1) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_LETTER_SMALL", 2) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_TABLOID", 3) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_LEDGER", 4) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_LEGAL", 5) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_STATEMENT", 6) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_EXECUTIVE", 7) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_A3", 8) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_A4", 9) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_A4_SMALL", 10) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_A5", 11) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_B4", 12) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_B5", 13) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_FOLIO", 14) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_QUARTO", 15) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_NOTE", 18) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_9", 19) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_10", 20) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_11", 21) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_12", 22) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_14", 23) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_C_SIZE_SHEET", 24) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_D_SIZE_SHEET", 25) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_E_SIZE_SHEET", 26) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_DL", 27) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_C3", 28) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_C4", 29) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_C5", 30) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_C6", 31) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_C65", 32) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_B4", 33) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_B5", 34) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_B6", 35) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_1", 36) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_MONARCH", 37) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_ENVELOPE_2", 38) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_FANFOLD", 39) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_GERMAN_STD_FANFOLD", 40) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, "PAPER_GERMAN_LEGAL_FANFOLD", 41) + REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, V_XLS_CONST_READ_TYPE_INT, READ_TYPE_INT); REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, V_XLS_CONST_READ_TYPE_DOUBLE, READ_TYPE_DOUBLE); REGISTER_CLASS_CONST_LONG(vtiful_xls_ce, V_XLS_CONST_READ_TYPE_STRING, READ_TYPE_STRING); diff --git a/kernel/write.c b/kernel/write.c index 2f2bc4e..28fcabc 100644 --- a/kernel/write.c +++ b/kernel/write.c @@ -392,6 +392,22 @@ void first_worksheet(xls_resource_write_t *res) worksheet_set_first_sheet(res->worksheet); } +/* + * Paper format + */ +void paper(xls_resource_write_t *res, zend_long type) +{ + worksheet_set_paper(res->worksheet, type); +} + +/* + * Set margins + */ +void margins(xls_resource_write_t *res, double left, double right, double top, double bottom) +{ + worksheet_set_margins(res->worksheet, left, right, top, bottom); +} + /* * Call finalization code and close file. */ diff --git a/tests/margins.phpt b/tests/margins.phpt new file mode 100644 index 0000000..69865f4 --- /dev/null +++ b/tests/margins.phpt @@ -0,0 +1,31 @@ +--TEST-- +Check for vtiful presence +--SKIPIF-- + +--FILE-- + './tests' +]; + +$fileObject = new \Vtiful\Kernel\Excel($config); +$fileObject = $fileObject->fileName('tutorial.xlsx'); + +$filePath = $fileObject->header(['name', 'age']) + ->data([ + ['viest', 21], + ['wjx', 21] + ]) + ->setPaper(\Vtiful\Kernel\Excel::PAPER_A3) + ->setLandscape() + ->setMargins(1, 1, 2, 2) + ->output(); + +var_dump($filePath); +?> +--CLEAN-- + +--EXPECT-- +string(21) "./tests/tutorial.xlsx" diff --git a/tests/paper.phpt b/tests/paper.phpt new file mode 100644 index 0000000..fb410aa --- /dev/null +++ b/tests/paper.phpt @@ -0,0 +1,30 @@ +--TEST-- +Check for vtiful presence +--SKIPIF-- + +--FILE-- + './tests' +]; + +$fileObject = new \Vtiful\Kernel\Excel($config); +$fileObject = $fileObject->fileName('tutorial.xlsx'); + +$filePath = $fileObject->header(['name', 'age']) + ->data([ + ['viest', 21], + ['wjx', 21] + ]) + ->setPaper(\Vtiful\Kernel\Excel::PAPER_A3) + ->setLandscape() + ->output(); + +var_dump($filePath); +?> +--CLEAN-- + +--EXPECT-- +string(21) "./tests/tutorial.xlsx" diff --git a/tests/printed.phpt b/tests/printed.phpt index c6d5240..065f569 100644 --- a/tests/printed.phpt +++ b/tests/printed.phpt @@ -8,7 +8,7 @@ try { $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); - $excel->setPrintedPortrait(); + $excel->setPortrait(); } catch (\Exception $exception) { var_dump($exception->getCode()); var_dump($exception->getMessage()); @@ -18,7 +18,7 @@ $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $excel->fileName('printed_portrait.xlsx', 'sheet1') - ->setPrintedPortrait() + ->setPortrait() ->output(); var_dump($excel); @@ -27,7 +27,7 @@ $config = ['path' => './tests']; $excel = new \Vtiful\Kernel\Excel($config); $excel->fileName('printed_landscape.xlsx', 'sheet1') - ->setPrintedLandscape() + ->setLandscape() ->output(); var_dump($excel); diff --git a/tests/protection_password.phpt b/tests/protection_password.phpt new file mode 100644 index 0000000..ccf25be --- /dev/null +++ b/tests/protection_password.phpt @@ -0,0 +1,29 @@ +--TEST-- +Check for vtiful presence +--SKIPIF-- + +--FILE-- + './tests' +]; + +$fileObject = new \Vtiful\Kernel\Excel($config); +$fileObject = $fileObject->fileName('tutorial.xlsx'); + +$filePath = $fileObject->header(['name', 'age']) + ->data([ + ['viest', 21], + ['wjx', 21] + ]) + ->protection('password') + ->output(); + +var_dump($filePath); +?> +--CLEAN-- + +--EXPECT-- +string(21) "./tests/tutorial.xlsx"