Unable to delete rows

Apr 12, 2011 at 8:17 PM

I have a file with several worksheets that I'm trying to delete rows from and I'm failing for some reason.

I get these errors:

Fatal error: Uncaught exception 'Exception' with message 'Invalid cell coordinate R8 C6' in /home/vaidas/babax/PHPExcel/Cell.php:508
Stack trace:
#0 /home/vaidas/babax/PHPExcel/ReferenceHelper.php(598): PHPExcel_Cell::coordinateFromString('R8 C6')
#1 /home/vaidas/babax/PHPExcel/ReferenceHelper.php(570): PHPExcel_ReferenceHelper->_updateSingleCellReference('R8 C6', 'A4', 0, -3)
#2 /home/vaidas/babax/PHPExcel/ReferenceHelper.php(511): PHPExcel_ReferenceHelper->_updateCellRange('K7:R8 C6:R6 C7:...', 'A4', 0, -3)
#3 /home/vaidas/babax/PHPExcel/ReferenceHelper.php(306): PHPExcel_ReferenceHelper->updateCellReference('K7:R8 C6:R6 C7:...', 'A4', 0, -3)
#4 /home/vaidas/babax/PHPExcel/Worksheet.php(1792): PHPExcel_ReferenceHelper->insertNewBefore('A4', 0, -3, Object(PHPExcel_Worksheet))
#5 /home/vaidas/babax/index.php(32): PHPExcel_Worksheet->removeRow(1, 3)
#6 {main}
  thrown in /home/vaidas/babax/PHPExcel/Cell.php on line 508

My code is as follows:
include('PHPExcel.php');
$file_name = 'MySheet2.xls';
$sheet_name = 'MySheet';

class MyFilter implements PHPExcel_Reader_IReadFilter
{
    public function readCell($column, $row, $worksheetName = '')
    {
        if (
             $worksheetName = 'MySheet' &&
             //in_array($column, $columns) &&
             $row<28
           )
        {
            return true;
        }
    }
}

$file_type = PHPExcel_IOFactory::identify($file_name);
$reader = PHPExcel_IOFactory::createReader($file_type);
$reader->setReadFilter(new MyFilter);

$document = $reader->load($file_name);
$document->setActiveSheetIndexByName($sheet_name);
$sheet = $document->getActiveSheet();
$sheet->removeRow(1,3);

$writer = new PHPExcel_Writer_HTML($document);
$writer->setSheetIndex(1);
echo $writer->generateStyles(true);
echo $writer->generateSheetData();
Coordinator
Apr 19, 2011 at 9:31 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.