PHPExcel: How to save the loaded file after changes has made on it?

三世轮回 提交于 2019-12-24 12:41:23

问题


I have made some changes on a file using PHP and realized nothing was changes after running the code (with no any errors).

I understood that I have to save the file right after I change stuff in it.

When using the 'save' function, I get:

( ! ) Fatal error: Call to undefined method PHPExcel_Worksheet::save() in C:\wamp\www\PHPExcel\excel_fun.php on line 32

this is my function and the way I am calling it:

function save_file(){

    global $objPHPExcel;

    $objPHPExcel->getActiveSheet()->save('keywords.xlsx');

}
save_file();

I tried using $objPHPExcel->save('keywords.xlsx'); too without any success

get the same error:

( ! ) Fatal error: Call to undefined method PHPExcel::save() in C:\wamp\www\PHPExcel\excel_fun.php on line 32

so what is the right way to do it?


回答1:


It's pretty straightforward to save the file, most of the examples do it.

You don't save the individual worksheet (you don't save individual worksheets in MS Excel either), you save the whole spreadsheet (PHPExcel object):

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('keywords.xlsx'); 


来源:https://stackoverflow.com/questions/32317742/phpexcel-how-to-save-the-loaded-file-after-changes-has-made-on-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!