OCT2DEC.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. require __DIR__ . '/../../Header.php';
  4. $category = 'Engineering';
  5. $functionName = 'OCT2DEC';
  6. $description = 'Converts an octal number to decimal';
  7. $helper->titles($category, $functionName, $description);
  8. // Create new PhpSpreadsheet object
  9. $spreadsheet = new Spreadsheet();
  10. $worksheet = $spreadsheet->getActiveSheet();
  11. // Add some data
  12. $testData = [
  13. [3],
  14. [7],
  15. [42],
  16. [70],
  17. [72],
  18. [77],
  19. [100],
  20. [127],
  21. [177],
  22. [456],
  23. [4567],
  24. [7777700001],
  25. [7777776543],
  26. ];
  27. $testDataCount = count($testData);
  28. $worksheet->fromArray($testData, null, 'A1', true);
  29. for ($row = 1; $row <= $testDataCount; ++$row) {
  30. $worksheet->setCellValue('B' . $row, '=OCT2DEC(A' . $row . ')');
  31. }
  32. // Test the formulae
  33. for ($row = 1; $row <= $testDataCount; ++$row) {
  34. $helper->log(sprintf(
  35. '(B%d): Octal %s is decimal %s',
  36. $row,
  37. $worksheet->getCell('A' . $row)->getValue(),
  38. $worksheet->getCell('B' . $row)->getCalculatedValue(),
  39. ));
  40. }