COMPLEX.php 1013 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. require __DIR__ . '/../../Header.php';
  4. $category = 'Engineering';
  5. $functionName = 'COMPLEX';
  6. $description = 'Converts real and imaginary coefficients into a complex number of the form x + yi or x + yj';
  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, 4],
  14. [3, 4, '"j"'],
  15. [3.5, 4.75],
  16. [0, 1],
  17. [1, 0],
  18. [0, -1],
  19. [0, 2],
  20. [2, 0],
  21. ];
  22. $testDataCount = count($testData);
  23. for ($row = 1; $row <= $testDataCount; ++$row) {
  24. $worksheet->setCellValue('A' . $row, '=COMPLEX(' . implode(',', $testData[$row - 1]) . ')');
  25. }
  26. for ($row = 1; $row <= $testDataCount; ++$row) {
  27. $helper->log(sprintf(
  28. '(A%d): Formula %s result is %s',
  29. $row,
  30. $worksheet->getCell('A' . $row)->getValue(),
  31. $worksheet->getCell('A' . $row)->getCalculatedValue()
  32. ));
  33. }