removeRow does not work

Topics: Developer Forum, User Forum
Nov 27, 2009 at 8:33 AM

Hello all,

I have a problem with the function removeRow().

I trying to remove a row from an excel with 500 rows and 100 columns. This excel worksheet will be created in 22 seconds, but the excution time for remove one Row seems to be endless.

Here is my code:

$startTime = mktime();

require_once APPLICATION_EXTERN_PATH . '/phpexcel/Classes/PHPExcel.php';
require_once APPLICATION_EXTERN_PATH . '/phpexcel/Classes/PHPExcel/IOFactory.php';

$objPHPExcel = new PHPExcel( );

for( $j = 1; $j < 500; $j++)
{
        for( $i = 1; $i < 100; $i++ )
        {
                $objPHPExcel->getActiveSheet()->setCellValue( PHPExcel_Cell::stringFromColumnIndex($i).$j, "its a funny string {$i}{$j}" );
        }
}

$objPHPExcel->getActiveSheet()->removeRow(399);

echo memory_get_peak_usage() . "<br>";
echo memory_get_usage() . "<br>";
echo ( mktime() - $startTime ) . " s";

I use the phpexcel version 29536

Can anybody help me please?

greets Mike

Developer
Jan 22, 2010 at 8:29 AM

Actually, your example is working:

The signature for removeRow:

/**
* Delete a row, updating all possible related data
*
* @param int $pRow Remove starting with this one
* @param int $pNumRows Number of rows to remove
* @throws Exception
* @return PHPExcel_Worksheet
*/

public function removeRow($pRow = 1, $pNumRows = 1)

You have this:

$objPHPExcel->getActiveSheet()->removeRow(399);

So what you are doing is to remove 1 row starting from row 399 (which amount to removing just row 399). The output looks correct: