COUPDAYBS.php 968 B

1234567891011121314151617181920212223242526272829
  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 days from the beginning of a coupon\'s period to the settlement date.');
  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-Jan-2011')],
  12. ['Maturity Date', DateHelper::getDateValue('25-Oct-2012')],
  13. ['Frequency', 4],
  14. ];
  15. // Some basic formatting for the data
  16. $worksheet->fromArray($arguments, null, 'A1');
  17. $worksheet->getStyle('B1:B2')->getNumberFormat()->setFormatCode('dd-mmm-yyyy');
  18. // Now the formula
  19. $worksheet->setCellValue('B6', '=COUPDAYBS(B1, B2, B3)');
  20. $helper->log($worksheet->getCell('B6')->getValue());
  21. $helper->log('COUPDAYBS() Result is ' . $worksheet->getCell('B6')->getFormattedValue());