Skip to content

Commit 822ec31

Browse files
authored
Merge pull request #333 from viest/printed
Feat: printed
2 parents 005aaf7 + cb1fdbc commit 822ec31

File tree

6 files changed

+152
-9
lines changed

6 files changed

+152
-9
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22
<img height="214" src="resource/logo_now.png"/>
33
</div>
44

5+
<div align=center>
6+
<a href="https://github.com/viest/php-ext-xlswriter/releases"><img src="https://img.shields.io/github/release/viest/php-ext-excel-export.svg"/></a>
7+
</div>
8+
9+
<div align=center>
10+
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/badge/platform-macos%20%7C%20linux%20%7C%20windows-brightgreen.svg"/></a>
11+
</div>
12+
513
<div align=center>
614
<a href="https://travis-ci.com/viest/php-ext-xlswriter"><img src="https://travis-ci.com/viest/php-ext-xlswriter.svg?branch=master"/></a>
715
<a href="https://ci.appveyor.com/project/viest/php-ext-excel-export/branch/master"><img src="https://ci.appveyor.com/api/projects/status/w4cfjo9e4gsrs6rn/branch/master?svg=true"/></a>
8-
<a href="https://github.com/viest/php-ext-xlswriter/releases"><img src="https://img.shields.io/github/release/viest/php-ext-excel-export.svg"/></a>
16+
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fviest%2Fphp-ext-xlswriter?ref=badge_shield"><img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fviest%2Fphp-ext-xlswriter.svg?type=shield"/></a>
917
</div>
1018

1119
<div align=center>
1220
<a href="https://opencollective.com/php-ext-xlswriter"><img src="https://opencollective.com/php-ext-xlswriter/all/badge.svg?label=financial+contributors"/></a>
1321
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/badge/PHP-%3E%3D%207.0-brightgreen.svg"/></a>
1422
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/github/contributors/viest/php-ext-excel-export.svg"/></a>
15-
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/badge/platform-macos%20%7C%20linux%20%7C%20windows-brightgreen.svg"/></a>
1623
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/badge/license-BSD-green.svg"/></a>
1724
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/github/issues/viest/php-ext-excel-export.svg"/></a>
18-
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fviest%2Fphp-ext-xlswriter?ref=badge_shield"><img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fviest%2Fphp-ext-xlswriter.svg?type=shield"/></a>
25+
<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fviest%2Fphp-ext-xlswriter&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false"/></a>
1926
</div>
2027

2128
## Why use xlswriter
@@ -138,4 +145,4 @@ BSD License
138145

139146
## Stargazers over time
140147

141-
[![Stargazers over time](https://starchart.cc/viest/php-ext-xlswriter.svg)](https://starchart.cc/viest/php-ext-xlswriter)
148+
[![Stargazers over time](https://starchart.cc/viest/php-ext-xlswriter.svg)](https://starchart.cc/viest/php-ext-xlswriter)

README_zh.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22
<img height="214" src="resource/logo_now.png"/>
33
</div>
44

5+
<div align=center>
6+
<a href="https://github.com/viest/php-ext-xlswriter/releases"><img src="https://img.shields.io/github/release/viest/php-ext-excel-export.svg"/></a>
7+
</div>
8+
9+
<div align=center>
10+
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/badge/platform-macos%20%7C%20linux%20%7C%20windows-brightgreen.svg"/></a>
11+
</div>
12+
513
<div align=center>
614
<a href="https://travis-ci.com/viest/php-ext-xlswriter"><img src="https://travis-ci.com/viest/php-ext-xlswriter.svg?branch=master"/></a>
715
<a href="https://ci.appveyor.com/project/viest/php-ext-excel-export/branch/master"><img src="https://ci.appveyor.com/api/projects/status/w4cfjo9e4gsrs6rn/branch/master?svg=true"/></a>
8-
<a href="https://github.com/viest/php-ext-xlswriter/releases"><img src="https://img.shields.io/github/release/viest/php-ext-excel-export.svg"/></a>
16+
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fviest%2Fphp-ext-xlswriter?ref=badge_shield"><img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fviest%2Fphp-ext-xlswriter.svg?type=shield"/></a>
917
</div>
1018

1119
<div align=center>
1220
<a href="https://opencollective.com/php-ext-xlswriter"><img src="https://opencollective.com/php-ext-xlswriter/all/badge.svg?label=financial+contributors"/></a>
1321
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/badge/PHP-%3E%3D%207.0-brightgreen.svg"/></a>
1422
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/github/contributors/viest/php-ext-excel-export.svg"/></a>
15-
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/badge/platform-macos%20%7C%20linux%20%7C%20windows-brightgreen.svg"/></a>
1623
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/badge/license-BSD-green.svg"/></a>
1724
<a href="https://github.com/viest/php-ext-xlswriter"><img src="https://img.shields.io/github/issues/viest/php-ext-excel-export.svg"/></a>
18-
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fviest%2Fphp-ext-xlswriter?ref=badge_shield"><img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fviest%2Fphp-ext-xlswriter.svg?type=shield"/></a>
25+
<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fviest%2Fphp-ext-xlswriter&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false"/></a>
1926
</div>
2027

2128
## 为什么使用xlswriter
@@ -125,4 +132,4 @@ BSD license
125132

126133
## Stargazers over time
127134

128-
[![Stargazers over time](https://starchart.cc/viest/php-ext-xlswriter.svg)](https://starchart.cc/viest/php-ext-xlswriter)
135+
[![Stargazers over time](https://starchart.cc/viest/php-ext-xlswriter.svg)](https://starchart.cc/viest/php-ext-xlswriter)

include/xlswriter.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ enum xlswriter_boolean {
6868
XLSWRITER_TRUE
6969
};
7070

71+
enum xlswirter_printed_direction {
72+
XLSWRITER_PRINTED_LANDSCAPE,
73+
XLSWRITER_PRINTED_PORTRAIT,
74+
};
75+
7176
typedef struct {
7277
lxw_workbook *workbook;
7378
lxw_worksheet *worksheet;
@@ -124,12 +129,20 @@ static inline chart_object *php_vtiful_chart_fetch_object(zend_object *obj) {
124129

125130
#define WORKBOOK_NOT_INITIALIZED(xls_object_t) \
126131
do { \
127-
if(obj->write_ptr.workbook == NULL) { \
132+
if(xls_object_t->write_ptr.workbook == NULL) { \
128133
zend_throw_exception(vtiful_exception_ce, "Please create a file first, use the filename method", 130); \
129134
return; \
130135
} \
131136
} while(0);
132137

138+
#define WORKSHEET_NOT_INITIALIZED(xls_object_t) \
139+
do { \
140+
if (xls_object_t->write_ptr.worksheet == NULL) { \
141+
zend_throw_exception(vtiful_exception_ce, "worksheet not initialized", 200); \
142+
return; \
143+
} \
144+
} while(0);
145+
133146
#define WORKSHEET_INDEX_OUT_OF_CHANGE_IN_OPTIMIZE_EXCEPTION(xls_resource_write_t, error) \
134147
do { \
135148
if(xls_resource_write_t->worksheet->optimize && error == LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE) { \
@@ -214,6 +227,7 @@ void gridlines(xls_resource_write_t *res, zend_long option);
214227
void auto_filter(zend_string *range, xls_resource_write_t *res);
215228
void protection(xls_resource_write_t *res, zend_string *password);
216229
void format_copy(lxw_format *new_format, lxw_format *other_format);
230+
void printed_direction(xls_resource_write_t *res, unsigned int direction);
217231
void xls_file_path(zend_string *file_name, zval *dir_path, zval *file_path);
218232
void freeze_panes(xls_resource_write_t *res, zend_long row, zend_long column);
219233
void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_format *format);

kernel/excel.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ ZEND_END_ARG_INFO()
266266
ZEND_BEGIN_ARG_INFO_EX(xls_protection_arginfo, 0, 0, 0)
267267
ZEND_ARG_INFO(0, password)
268268
ZEND_END_ARG_INFO()
269+
270+
ZEND_BEGIN_ARG_INFO_EX(xls_set_printed_portrait_arginfo, 0, 0, 0)
271+
ZEND_END_ARG_INFO()
272+
273+
ZEND_BEGIN_ARG_INFO_EX(xls_set_printed_landscape_arginfo, 0, 0, 0)
274+
ZEND_END_ARG_INFO()
269275
/* }}} */
270276

271277
/** {{{ \Vtiful\Kernel\Excel::__construct(array $config)
@@ -1102,6 +1108,36 @@ PHP_METHOD(vtiful_xls, protection)
11021108
}
11031109
/* }}} */
11041110

1111+
1112+
/** {{{ \Vtiful\Kernel\Excel::setPrintedPortrait()
1113+
*/
1114+
PHP_METHOD(vtiful_xls, setPrintedPortrait)
1115+
{
1116+
ZVAL_COPY(return_value, getThis());
1117+
1118+
xls_object* obj = Z_XLS_P(getThis());
1119+
1120+
WORKBOOK_NOT_INITIALIZED(obj);
1121+
1122+
printed_direction(&obj->write_ptr, XLSWRITER_PRINTED_PORTRAIT);
1123+
}
1124+
/* }}} */
1125+
1126+
1127+
/** {{{ \Vtiful\Kernel\Excel::setPrintedLandscape()
1128+
*/
1129+
PHP_METHOD(vtiful_xls, setPrintedLandscape)
1130+
{
1131+
ZVAL_COPY(return_value, getThis());
1132+
1133+
xls_object* obj = Z_XLS_P(getThis());
1134+
1135+
WORKBOOK_NOT_INITIALIZED(obj);
1136+
1137+
printed_direction(&obj->write_ptr, XLSWRITER_PRINTED_LANDSCAPE);
1138+
}
1139+
/* }}} */
1140+
11051141
#ifdef ENABLE_READER
11061142

11071143
/** {{{ \Vtiful\Kernel\Excel::openFile()
@@ -1435,6 +1471,9 @@ zend_function_entry xls_methods[] = {
14351471
PHP_ME(vtiful_xls, stringFromColumnIndex, xls_string_to_index, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
14361472
PHP_ME(vtiful_xls, timestampFromDateDouble, xls_string_to_index, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
14371473

1474+
PHP_ME(vtiful_xls, setPrintedPortrait, xls_set_printed_portrait_arginfo, ZEND_ACC_PUBLIC)
1475+
PHP_ME(vtiful_xls, setPrintedLandscape, xls_set_printed_landscape_arginfo, ZEND_ACC_PUBLIC)
1476+
14381477
#ifdef ENABLE_READER
14391478
PHP_ME(vtiful_xls, openFile, xls_open_file_arginfo, ZEND_ACC_PUBLIC)
14401479
PHP_ME(vtiful_xls, openSheet, xls_open_sheet_arginfo, ZEND_ACC_PUBLIC)

kernel/write.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,18 @@ void protection(xls_resource_write_t *res, zend_string *password)
351351
}
352352
}
353353

354+
/*
355+
* Set the worksheet printed direction
356+
*/
357+
void printed_direction(xls_resource_write_t *res, unsigned int direction)
358+
{
359+
if (direction == XLSWRITER_PRINTED_PORTRAIT) {
360+
worksheet_set_portrait(res->worksheet);
361+
}
362+
363+
worksheet_set_landscape(res->worksheet);
364+
}
365+
354366
/*
355367
* Call finalization code and close file.
356368
*/

tests/printed.phpt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
try {
8+
$config = ['path' => './tests'];
9+
$excel = new \Vtiful\Kernel\Excel($config);
10+
11+
$excel->setPrintedPortrait();
12+
} catch (\Exception $exception) {
13+
var_dump($exception->getCode());
14+
var_dump($exception->getMessage());
15+
}
16+
17+
$config = ['path' => './tests'];
18+
$excel = new \Vtiful\Kernel\Excel($config);
19+
20+
$excel->fileName('printed_portrait.xlsx', 'sheet1')
21+
->setPrintedPortrait()
22+
->output();
23+
24+
var_dump($excel);
25+
26+
$config = ['path' => './tests'];
27+
$excel = new \Vtiful\Kernel\Excel($config);
28+
29+
$excel->fileName('printed_landscape.xlsx', 'sheet1')
30+
->setPrintedLandscape()
31+
->output();
32+
33+
var_dump($excel);
34+
?>
35+
--CLEAN--
36+
<?php
37+
@unlink(__DIR__ . '/printed_portrait.xlsx');
38+
@unlink(__DIR__ . '/printed_landscape.xlsx');
39+
?>
40+
--EXPECT--
41+
int(130)
42+
string(51) "Please create a file first, use the filename method"
43+
object(Vtiful\Kernel\Excel)#3 (3) {
44+
["config":"Vtiful\Kernel\Excel":private]=>
45+
array(1) {
46+
["path"]=>
47+
string(7) "./tests"
48+
}
49+
["fileName":"Vtiful\Kernel\Excel":private]=>
50+
string(29) "./tests/printed_portrait.xlsx"
51+
["read_row_type":"Vtiful\Kernel\Excel":private]=>
52+
NULL
53+
}
54+
object(Vtiful\Kernel\Excel)#1 (3) {
55+
["config":"Vtiful\Kernel\Excel":private]=>
56+
array(1) {
57+
["path"]=>
58+
string(7) "./tests"
59+
}
60+
["fileName":"Vtiful\Kernel\Excel":private]=>
61+
string(30) "./tests/printed_landscape.xlsx"
62+
["read_row_type":"Vtiful\Kernel\Excel":private]=>
63+
NULL
64+
}

0 commit comments

Comments
 (0)