PHPExcel:如何正确使用insertNewRowBefore函数?

PHPExcel:如何正确使用insertNewRowBefore函数?,php,function,phpexcel,Php,Function,Phpexcel,我想在第$insert_行后面添加$x行 这就是功能: // Get the Excel file I want to work on: function get_excel_file(){ // Need to define this to change a global variable inside a function global $objPHPExcel; // Define an Exel Object to read files from:

我想在第$insert_行后面添加$x行

这就是功能:

// Get the Excel file I want to work on:  
function get_excel_file(){

    // Need to define this to change a global variable inside a function
    global $objPHPExcel; 

    // Define an Exel Object to read files from: 
    $objPHPExcel = PHPExcel_IOFactory::load('keywords.xlsx');

}


// Inserts new rows: Gets the number of rows to insers them before the second variable
function insert_rows( $objPHPExcel, $insert_here, $num_rows  ){ 

    echo $num_rows, $insert_here;

    $objPHPExcel->getActiveSheet()->insertNewRowBefore( $insert_here, $num_rows ); 

}
调用函数时,我得到了变量的良好响应。所以我肯定不是因为变量


有什么问题吗?Excel文件看起来完全一样,没有插入新行

之后是否再次保存该文件?我不想问这样一个愚蠢的问题,但令人惊讶的是,很多人认为PHPExcel正在直接编辑加载的文件,并自动保存您所做的一切。。。。。事实并非如此。我不知道我必须保存。您确实需要保存,就像您需要保存MS Excel本身中的任何更改一样,否则您所做的只是在请求期间修改“内存中”模型。我储蓄也有困难。如果您可以在空闲时间查看:)保存文件非常简单,大多数示例都可以做到:
objWriter=PHPExcel\u IOFactory::createWriter($objPHPExcel,'Excel2007')$objWriter->save('filename.xlsx')