Skip to content

Commit c183ddf

Browse files
authored
Merge pull request #495 from HaiD84/fix_optional_format
Fix pass explicit null to optional format argument
2 parents cf7e193 + 6cd9720 commit c183ddf

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

kernel/excel.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -919,12 +919,10 @@ PHP_METHOD(vtiful_xls, insertFormula)
919919

920920
WORKBOOK_NOT_INITIALIZED(obj);
921921

922-
if (argc == 3) {
923-
formula_writer(formula, row, column, &obj->write_ptr, obj->format_ptr.format);
924-
}
925-
926922
if (argc == 4 && format_handle != NULL) {
927923
formula_writer(formula, row, column, &obj->write_ptr, zval_get_format(format_handle));
924+
} else {
925+
formula_writer(formula, row, column, &obj->write_ptr, obj->format_ptr.format);
928926
}
929927
}
930928
/* }}} */
@@ -1008,12 +1006,10 @@ PHP_METHOD(vtiful_xls, mergeCells)
10081006

10091007
WORKBOOK_NOT_INITIALIZED(obj);
10101008

1011-
if (argc == 2) {
1012-
merge_cells(range, data, &obj->write_ptr, obj->format_ptr.format);
1013-
}
1014-
10151009
if (argc == 3 && format_handle != NULL) {
10161010
merge_cells(range, data, &obj->write_ptr, zval_get_format(format_handle));
1011+
} else {
1012+
merge_cells(range, data, &obj->write_ptr, obj->format_ptr.format);
10171013
}
10181014
}
10191015
/* }}} */
@@ -1043,9 +1039,7 @@ PHP_METHOD(vtiful_xls, setColumn)
10431039

10441040
if (argc == 3 && format_handle != NULL) {
10451041
set_column(range, width, &obj->write_ptr, zval_get_format(format_handle));
1046-
}
1047-
1048-
if (argc == 2) {
1042+
} else {
10491043
set_column(range, width, &obj->write_ptr, NULL);
10501044
}
10511045
}
@@ -1076,9 +1070,7 @@ PHP_METHOD(vtiful_xls, setRow)
10761070

10771071
if (argc == 3 && format_handle != NULL) {
10781072
set_row(range, height, &obj->write_ptr, zval_get_format(format_handle));
1079-
}
1080-
1081-
if (argc == 2) {
1073+
} else {
10821074
set_row(range, height, &obj->write_ptr, NULL);
10831075
}
10841076
}

tests/011.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ $boldStyle = $format->bold()->toResource();
1616
$filePath = $fileObject->header(['name', 'age'])
1717
->data([['viest', 21]])
1818
->setColumn('A:A', 200, $boldStyle)
19+
->setColumn('B:B', 200, null)
1920
->output();
2021

2122
var_dump($filePath);

tests/012.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ $boldStyle = $format->bold()->toResource();
1616
$filePath = $fileObject->header(['name', 'age'])
1717
->data([
1818
['viest', 21],
19-
['wjx', 21]
19+
['wjx', 21],
20+
['abc', 21]
2021
])
2122
->setRow('A1', 200, $boldStyle)
2223
->setRow('A2:A3', 200, $boldStyle)
24+
->setRow('A4:A4', 200, null)
2325
->output();
2426

2527
var_dump($filePath);

tests/014.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ $excel = new \Vtiful\Kernel\Excel($config);
1010
$freeFile = $excel->fileName("14.xlsx")
1111
->header(['name', 'money']);
1212

13-
for($index = 1; $index < 10; $index++) {
13+
for($index = 1; $index <= 10; $index++) {
1414
$freeFile->insertText($index, 0, 'vikin');
1515
$freeFile->insertText($index, 1, 10);
1616
}
1717

1818
$freeFile->insertText(12, 0, "Total");
1919
$freeFile->insertFormula(12, 1, '=SUM(B2:B11)');
20+
$freeFile->insertText(13, 0, "Total (default format)");
21+
$freeFile->insertFormula(13, 1, '=SUM(B2:B11)', null);
2022

2123
$filePath = $freeFile->output();
2224

tests/016.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ $excel = new \Vtiful\Kernel\Excel($config);
99

1010
$filePath = $excel->fileName("16.xlsx")
1111
->mergeCells('A1:C1', 'Merge cells')
12+
->mergeCells('A2:C2', 'Merge cells, explicit null (default) format', null)
1213
->output();
1314

1415
var_dump($filePath);

0 commit comments

Comments
 (0)