DISC.php 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateHelper;
  3. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  4. require __DIR__ . '/../../Header.php';
  5. $helper->log('Returns the the Discount Rate for a security.');
  6. // Create new PhpSpreadsheet object
  7. $spreadsheet = new Spreadsheet();
  8. $worksheet = $spreadsheet->getActiveSheet();
  9. // Add some data
  10. $arguments = [
  11. ['Settlement Date', DateHelper::getDateValue('01-Apr-2016')],
  12. ['Maturity Date', DateHelper::getDateValue('31-Mar-2021')],
  13. ['Par Value', 95.00],
  14. ['Redemption Value', 100.00],
  15. ];
  16. // Some basic formatting for the data
  17. $worksheet->fromArray($arguments, null, 'A1');
  18. $worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
  19. $worksheet->getStyle('B3:B4')->getNumberFormat()->setFormatCode('$#,##0.00');
  20. // Now the formula
  21. $worksheet->setCellValue('B7', '=DISC(B1, B2, B3, B4)');
  22. $worksheet->getStyle('B7')->getNumberFormat()->setFormatCode('0.00%');
  23. $helper->log($worksheet->getCell('B7')->getValue());
  24. $helper->log('DISC() Result is ' . $worksheet->getCell('B7')->getFormattedValue());