mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-17 12:10:19 +00:00
ecbd702628
Phpstan hasn't identified any errors in Samples in a long time. But, as it turns out, one particular error is suppressed: ``` Variable $helper might not be defined. ``` This error would be generated by almost all samples, and the errors that it suppresses will become problematic if we move to Level 10. We are not yet committed to doing that, but it is pretty easy to write a script to change the samples so that error no longer happens, and there isn't really any reason to delay doing so. The results of that script constitute this PR.
33 lines
1.1 KiB
PHP
33 lines
1.1 KiB
PHP
<?php
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
require __DIR__ . '/../Header.php';
|
|
/** @var PhpOffice\PhpSpreadsheet\Helper\Sample $helper */
|
|
$helper->log('Returns the Discount Rate for a security.');
|
|
|
|
// Create new PhpSpreadsheet object
|
|
$spreadsheet = new Spreadsheet();
|
|
$worksheet = $spreadsheet->getActiveSheet();
|
|
|
|
// Add some data
|
|
$arguments = [
|
|
['Settlement Date', DateHelper::getDateValue('01-Apr-2016')],
|
|
['Maturity Date', DateHelper::getDateValue('31-Mar-2021')],
|
|
['Par Value', 95.00],
|
|
['Redemption Value', 100.00],
|
|
];
|
|
|
|
// Some basic formatting for the data
|
|
$worksheet->fromArray($arguments, null, 'A1');
|
|
$worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
|
|
$worksheet->getStyle('B3:B4')->getNumberFormat()->setFormatCode('$#,##0.00');
|
|
|
|
// Now the formula
|
|
$worksheet->setCellValue('B7', '=DISC(B1, B2, B3, B4)');
|
|
$worksheet->getStyle('B7')->getNumberFormat()->setFormatCode('0.00%');
|
|
|
|
$helper->log($worksheet->getCell('B7')->getValue());
|
|
$helper->log('DISC() Result is ' . $worksheet->getCell('B7')->getFormattedValue());
|