Skip to content

Commit 87afea5

Browse files
authored
Merge pull request #441 from viest/dev
Feat: print scale
2 parents 9bd9d25 + 3ebc68f commit 87afea5

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

include/xlswriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ void first_worksheet(xls_resource_write_t *res);
331331
void zoom(xls_resource_write_t *res, zend_long zoom);
332332
void paper(xls_resource_write_t *res, zend_long type);
333333
void gridlines(xls_resource_write_t *res, zend_long option);
334+
void printed_scale(xls_resource_write_t *res, zend_long scale);
334335
void auto_filter(zend_string *range, xls_resource_write_t *res);
335336
void protection(xls_resource_write_t *res, zend_string *password);
336337
void format_copy(lxw_format *new_format, lxw_format *other_format);

kernel/excel.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ ZEND_END_ARG_INFO()
303303
ZEND_BEGIN_ARG_INFO_EX(xls_set_printed_landscape_arginfo, 0, 0, 0)
304304
ZEND_END_ARG_INFO()
305305

306+
ZEND_BEGIN_ARG_INFO_EX(xls_set_printed_scale_arginfo, 0, 0, 0)
307+
ZEND_ARG_INFO(0, scale)
308+
ZEND_END_ARG_INFO()
309+
306310
ZEND_BEGIN_ARG_INFO_EX(xls_hide_sheet_arginfo, 0, 0, 0)
307311
ZEND_END_ARG_INFO()
308312

@@ -1312,7 +1316,6 @@ PHP_METHOD(vtiful_xls, setPortrait)
13121316
}
13131317
/* }}} */
13141318

1315-
13161319
/** {{{ \Vtiful\Kernel\Excel::setLandscape()
13171320
*/
13181321
PHP_METHOD(vtiful_xls, setLandscape)
@@ -1327,6 +1330,26 @@ PHP_METHOD(vtiful_xls, setLandscape)
13271330
}
13281331
/* }}} */
13291332

1333+
/** {{{ \Vtiful\Kernel\Excel::setPrintScale(int $scale)
1334+
*/
1335+
PHP_METHOD(vtiful_xls, setPrintScale)
1336+
{
1337+
zend_long scale = 10;
1338+
1339+
ZEND_PARSE_PARAMETERS_START(1, 1)
1340+
Z_PARAM_LONG(scale)
1341+
ZEND_PARSE_PARAMETERS_END();
1342+
1343+
ZVAL_COPY(return_value, getThis());
1344+
1345+
xls_object* obj = Z_XLS_P(getThis());
1346+
1347+
WORKBOOK_NOT_INITIALIZED(obj);
1348+
1349+
printed_scale(&obj->write_ptr, scale);
1350+
}
1351+
/* }}} */
1352+
13301353
/** {{{ \Vtiful\Kernel\Excel::setCurrentSheetHide()
13311354
*/
13321355
PHP_METHOD(vtiful_xls, setCurrentSheetHide)
@@ -1712,10 +1735,11 @@ zend_function_entry xls_methods[] = {
17121735
PHP_ME(vtiful_xls, zoom, xls_sheet_zoom_arginfo, ZEND_ACC_PUBLIC)
17131736
PHP_ME(vtiful_xls, gridline, xls_sheet_gridline_arginfo, ZEND_ACC_PUBLIC)
17141737

1715-
PHP_ME(vtiful_xls, setPaper, xls_set_paper_arginfo, ZEND_ACC_PUBLIC)
1716-
PHP_ME(vtiful_xls, setMargins, xls_set_margins_arginfo, ZEND_ACC_PUBLIC)
1717-
PHP_ME(vtiful_xls, setPortrait, xls_set_printed_portrait_arginfo, ZEND_ACC_PUBLIC)
1718-
PHP_ME(vtiful_xls, setLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC)
1738+
PHP_ME(vtiful_xls, setPaper, xls_set_paper_arginfo, ZEND_ACC_PUBLIC)
1739+
PHP_ME(vtiful_xls, setMargins, xls_set_margins_arginfo, ZEND_ACC_PUBLIC)
1740+
PHP_ME(vtiful_xls, setPortrait, xls_set_printed_portrait_arginfo, ZEND_ACC_PUBLIC)
1741+
PHP_ME(vtiful_xls, setLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC)
1742+
PHP_ME(vtiful_xls, setPrintScale, xls_set_printed_scale_arginfo, ZEND_ACC_PUBLIC)
17191743

17201744
PHP_ME(vtiful_xls, setCurrentSheetHide, xls_hide_sheet_arginfo, ZEND_ACC_PUBLIC)
17211745
PHP_ME(vtiful_xls, setCurrentSheetIsFirst, xls_first_sheet_arginfo, ZEND_ACC_PUBLIC)

kernel/write.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,22 @@ void printed_direction(xls_resource_write_t *res, unsigned int direction)
425425
worksheet_set_landscape(res->worksheet);
426426
}
427427

428+
/*
429+
* Set the worksheet printed scale
430+
*/
431+
void printed_scale(xls_resource_write_t *res, zend_long scale)
432+
{
433+
if (scale < 10) {
434+
scale = 10;
435+
}
436+
437+
if (scale > 400) {
438+
scale = 400;
439+
}
440+
441+
worksheet_set_print_scale(res->worksheet, scale);
442+
}
443+
428444
/*
429445
* Hide worksheet
430446
*/

tests/printed.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,22 @@ $excel->fileName('printed_landscape.xlsx', 'sheet1')
3030
->setLandscape()
3131
->output();
3232

33+
var_dump($excel);
34+
35+
$config = ['path' => './tests'];
36+
$excel = new \Vtiful\Kernel\Excel($config);
37+
38+
$excel->fileName('printed_scale.xlsx', 'sheet1')
39+
->setPrintScale(180)
40+
->output();
41+
3342
var_dump($excel);
3443
?>
3544
--CLEAN--
3645
<?php
3746
@unlink(__DIR__ . '/printed_portrait.xlsx');
3847
@unlink(__DIR__ . '/printed_landscape.xlsx');
48+
@unlink(__DIR__ . '/printed_scale.xlsx');
3949
?>
4050
--EXPECT--
4151
int(130)
@@ -62,3 +72,15 @@ object(Vtiful\Kernel\Excel)#1 (3) {
6272
["read_row_type":"Vtiful\Kernel\Excel":private]=>
6373
NULL
6474
}
75+
object(Vtiful\Kernel\Excel)#3 (3) {
76+
["config":"Vtiful\Kernel\Excel":private]=>
77+
array(1) {
78+
["path"]=>
79+
string(7) "./tests"
80+
}
81+
["fileName":"Vtiful\Kernel\Excel":private]=>
82+
string(26) "./tests/printed_scale.xlsx"
83+
["read_row_type":"Vtiful\Kernel\Excel":private]=>
84+
NULL
85+
}
86+

0 commit comments

Comments
 (0)