Browse Source

Merge pull request #365 from guiqibusixin/master

data validation can be applied to a single cell or a range of cells
viest 4 years ago
parent
commit
69c68a2791
2 changed files with 32 additions and 1 deletions
  1. 7 1
      kernel/write.c
  2. 25 0
      tests/validation_limiting_to_a_single_or_range_cell.phpt

+ 7 - 1
kernel/write.c

@@ -306,7 +306,13 @@ void set_row(zend_string *range, double height, xls_resource_write_t *res, lxw_f
  */
 void validation(xls_resource_write_t *res, zend_string *range, lxw_data_validation *validation)
 {
-    worksheet_data_validation_cell(res->worksheet, CELL(ZSTR_VAL(range)), validation);
+    char *rangeStr = ZSTR_VAL(range);
+        
+    if (strchr(rangeStr, ':')) {
+	    worksheet_data_validation_range(res->worksheet, RANGE(rangeStr), validation);
+    } else {
+	    worksheet_data_validation_cell(res->worksheet, CELL(rangeStr), validation);
+    }
 }
 
 /*

+ 25 - 0
tests/validation_limiting_to_a_single_or_range_cell.phpt

@@ -0,0 +1,25 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+--FILE--
+<?php
+$config = ['path' => './tests'];
+
+$validation = new \Vtiful\Kernel\Validation();
+$validation->validationType(\Vtiful\Kernel\Validation::TYPE_LIST)
+    ->valueList(['wjx', 'viest']);
+
+$excel    = new \Vtiful\Kernel\Excel($config);
+$filePath = $excel->fileName('tutorial.xlsx')
+    ->validation('A1', $validation->toResource())
+    ->validation('B1:B1048576', $validation->toResource())
+    ->output();
+
+var_dump($validation, $filePath);
+?>
+--EXPECT--
+object(Vtiful\Kernel\Validation)#1 (0) {
+}
+string(21) "./tests/tutorial.xlsx"
+