简体   繁体   中英

Using Excel with PhPExcel library

I have queries regarding the PhPExcel library for as I am stuck at a point and not getting how to move ahead. It will be really grateful if I could get help on how can I read, write, & save a .xlsm (mostly this, it has no macros but yeah many calculations) or .xlsx file by passing certain values from a web page and then retrieving the data out of it. The file is a workbook with like 3-4 excel sheets in it, all connected to one another, like the value passing from the web page goes on to sheet 1 but all the calculations & relevant values fetched to perform those calculations comes from sheet 2 and then the respective changes are made on sheet 1 again and the cells to be displayed on the web page are on sheet 1. To elaborate more it is like if I enter a value on the web page, it opens the designated excel file, reads it, writes the changes specified in it and then saves those changes. Then again it opens it, reads the required cells and displays them on the web page. The problem is it is taking a lot of time for reading the file and saving the changes passes from the website and also does not display the expected output and throw errors as shown below after the code.

`if (isset($_POST['submit'])) {
    if ($_POST['input'] == 0) { 
        echo 'The output equals to 0';
    } else {
        include 'C:\wamp64\www\website\excelvideo\PHPExcel-1.8\Classes\PHPExcel\IOFactory.php';

        $objPHPExcel = PHPExcel_IOFactory::load('C:\wamp64\www\website\excelvideo\401k.xlsx');

        $objPHPExcel->getActiveSheet()->setCellValue('C2', $_POST['input']);
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
        echo 'Data Saved';
        $objWriter->save('401k.xlsx');

        echo '<label for="output">Output is as follows:</label><br/>';

        $objPHPExcel = PHPExcel_IOFactory::load('C:\wamp64\www\website\excelvideo\401k.xlsx');
        echo $objPHPExcel->getActiveSheet()->getCell('C17')->getCalculatedValue().'<br />';`

error snippet

The error you are receiving is generated by an xdebug setting in your php.ini. How to disable that, or increase the limit is answered here: Increasing nesting function calls limit

Using Excel as a database solution is very bad practice indeed, because, like the error you received, you will soon run into issues like "memory limit exceeded" or even worse, a corrupted Excel file when multiple processes try to write to the same file at the same time. So i'd really look into a different storage solution. MySQL comes to mind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM