Skip to content

Commit 69c68a2

Browse files
authored
Merge pull request #365 from guiqibusixin/master
data validation can be applied to a single cell or a range of cells
2 parents afb5dab + c3f24e2 commit 69c68a2

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

kernel/write.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,13 @@ void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_f
306306
*/
307307
void validation(xls_resource_write_t *res, zend_string *range, lxw_data_validation *validation)
308308
{
309-
worksheet_data_validation_cell(res->worksheet, CELL(ZSTR_VAL(range)), validation);
309+
char *rangeStr = ZSTR_VAL(range);
310+
311+
if (strchr(rangeStr, ':')) {
312+
worksheet_data_validation_range(res->worksheet, RANGE(rangeStr), validation);
313+
} else {
314+
worksheet_data_validation_cell(res->worksheet, CELL(rangeStr), validation);
315+
}
310316
}
311317

312318
/*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$config = ['path' => './tests'];
8+
9+
$validation = new \Vtiful\Kernel\Validation();
10+
$validation->validationType(\Vtiful\Kernel\Validation::TYPE_LIST)
11+
->valueList(['wjx', 'viest']);
12+
13+
$excel = new \Vtiful\Kernel\Excel($config);
14+
$filePath = $excel->fileName('tutorial.xlsx')
15+
->validation('A1', $validation->toResource())
16+
->validation('B1:B1048576', $validation->toResource())
17+
->output();
18+
19+
var_dump($validation, $filePath);
20+
?>
21+
--EXPECT--
22+
object(Vtiful\Kernel\Validation)#1 (0) {
23+
}
24+
string(21) "./tests/tutorial.xlsx"
25+

0 commit comments

Comments
 (0)