Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with formulas #7

Open
wolverine4277 opened this issue Sep 16, 2024 · 0 comments
Open

Problem with formulas #7

wolverine4277 opened this issue Sep 16, 2024 · 0 comments

Comments

@wolverine4277
Copy link

wolverine4277 commented Sep 16, 2024

Hi, I'm using your library with PHP v7.4.33 and have a problem assigning formulas to cells.

// Create a new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set some values in A1 to A5 for demonstration
$objPHPExcel->getActiveSheet()->setCellValue('A1', 10);
$objPHPExcel->getActiveSheet()->setCellValue('A2', 20);
$objPHPExcel->getActiveSheet()->setCellValue('A3', 30);
$objPHPExcel->getActiveSheet()->setCellValue('A4', 40);
$objPHPExcel->getActiveSheet()->setCellValue('A5', 50);

// Set the formula in a specific cell (e.g., B1)
$objPHPExcel->getActiveSheet()->setCellValue('B1', '=AVERAGE(A1:A5)');
//$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1, '=AVERAGE(A1:A5)'); // Same result as above line

// Save the spreadsheet to a file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setPreCalculateFormulas(false); 
$objWriter->save('example.xlsx');

I understand that this code results in an excel with the formula =AVERAGE(A1:A5) in cell B1 but instead of that the cell B1 have a the text =AVERAGE(A1:A5), not the formula that shows the value 30.

I try with and old versión of the library (version 1.8.0, 2014-03-02) and the same code work fine.
I miss something new to configure in this version?
I need to update to PHP 7.4.33 and I appreciate any help!
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant