Skip to content

Commit

Permalink
Merge pull request #495 from HaiD84/fix_optional_format
Browse files Browse the repository at this point in the history
Fix pass explicit null to optional format argument
  • Loading branch information
viest authored Nov 18, 2023
2 parents cf7e193 + 6cd9720 commit c183ddf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
20 changes: 6 additions & 14 deletions kernel/excel.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,10 @@ PHP_METHOD(vtiful_xls, insertFormula)

WORKBOOK_NOT_INITIALIZED(obj);

if (argc == 3) {
formula_writer(formula, row, column, &obj->write_ptr, obj->format_ptr.format);
}

if (argc == 4 && format_handle != NULL) {
formula_writer(formula, row, column, &obj->write_ptr, zval_get_format(format_handle));
} else {
formula_writer(formula, row, column, &obj->write_ptr, obj->format_ptr.format);
}
}
/* }}} */
Expand Down Expand Up @@ -1008,12 +1006,10 @@ PHP_METHOD(vtiful_xls, mergeCells)

WORKBOOK_NOT_INITIALIZED(obj);

if (argc == 2) {
merge_cells(range, data, &obj->write_ptr, obj->format_ptr.format);
}

if (argc == 3 && format_handle != NULL) {
merge_cells(range, data, &obj->write_ptr, zval_get_format(format_handle));
} else {
merge_cells(range, data, &obj->write_ptr, obj->format_ptr.format);
}
}
/* }}} */
Expand Down Expand Up @@ -1043,9 +1039,7 @@ PHP_METHOD(vtiful_xls, setColumn)

if (argc == 3 && format_handle != NULL) {
set_column(range, width, &obj->write_ptr, zval_get_format(format_handle));
}

if (argc == 2) {
} else {
set_column(range, width, &obj->write_ptr, NULL);
}
}
Expand Down Expand Up @@ -1076,9 +1070,7 @@ PHP_METHOD(vtiful_xls, setRow)

if (argc == 3 && format_handle != NULL) {
set_row(range, height, &obj->write_ptr, zval_get_format(format_handle));
}

if (argc == 2) {
} else {
set_row(range, height, &obj->write_ptr, NULL);
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/011.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $boldStyle = $format->bold()->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([['viest', 21]])
->setColumn('A:A', 200, $boldStyle)
->setColumn('B:B', 200, null)
->output();

var_dump($filePath);
Expand Down
4 changes: 3 additions & 1 deletion tests/012.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ $boldStyle = $format->bold()->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
['wjx', 21],
['abc', 21]
])
->setRow('A1', 200, $boldStyle)
->setRow('A2:A3', 200, $boldStyle)
->setRow('A4:A4', 200, null)
->output();

var_dump($filePath);
Expand Down
4 changes: 3 additions & 1 deletion tests/014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ $excel = new \Vtiful\Kernel\Excel($config);
$freeFile = $excel->fileName("14.xlsx")
->header(['name', 'money']);

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

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

$filePath = $freeFile->output();

Expand Down
1 change: 1 addition & 0 deletions tests/016.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $excel = new \Vtiful\Kernel\Excel($config);

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

var_dump($filePath);
Expand Down

0 comments on commit c183ddf

Please sign in to comment.