COUPNUM.php 1.0 KB

123456789101112131415161718192021222324252627282930
  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 number of coupons payable, between a security\'s settlement date and maturity date,');
  6. $helper->log('rounded up to the nearest whole coupon.');
  7. // Create new PhpSpreadsheet object
  8. $spreadsheet = new Spreadsheet();
  9. $worksheet = $spreadsheet->getActiveSheet();
  10. // Add some data
  11. $arguments = [
  12. ['Settlement Date', DateHelper::getDateValue('01-Jan-2011')],
  13. ['Maturity Date', DateHelper::getDateValue('25-Oct-2012')],
  14. ['Frequency', 4],
  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. // Now the formula
  20. $worksheet->setCellValue('B6', '=COUPNUM(B1, B2, B3)');
  21. $helper->log($worksheet->getCell('B6')->getValue());
  22. $helper->log('COUPNUM() Result is ' . $worksheet->getCell('B6')->getFormattedValue());