'Merge must be set on a range of cells.'

Topics: Developer Forum, Project Management Forum, User Forum
Jul 6, 2011 at 6:54 PM
Edited Jul 6, 2011 at 6:55 PM

I am trying to upload a preexisting Excel file. My goal is to change the values of a bunch of cells in the spreadsheet, and potentially insert and delete rows.

In just trying to load the sheet, I get the following error:

 

18:43:58 Create new PHPExcel object 18:43:58 Load Excel2007 template file�
Fatal error: Uncaught exception 'Exception' with message 'Merge must be set on a range of cells.' in 
'Classes/PHPExcel/Worksheet.php:1441 Stack trace: #0 /Classes/PHPExcel/Reader/Excel5.php(4100): PHPExcel_Worksheet->mergeCells('B20') 
#1 /Classes/PHPExcel/Reader/Excel5.php(801): PHPExcel_Reader_Excel5->_readMergedCells() #2 /Tests/27imagesexcel5.php(44): PHPExcel_Reader_Excel5->load('CCC.xls') 
#3 {main} thrown in�Classes/PHPExcel/Worksheet.php�on line�1441

 

 

[FYI: complete server path deleted]

I'm using the following code, from the 27imagesexcel5.php file, to load the excel file:

 

<?php
/**
 * PHPExcel
 *
 * Copyright (C) 2006 - 2011 PHPExcel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category   PHPExcel
 * @package    PHPExcel
 * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
 * @version    1.7.6, 2011-02-27
 */

/** Error reporting */
error_reporting(E_ALL);

date_default_timezone_set('Europe/London');

/** PHPExcel */
require_once '../Classes/PHPExcel.php';


// Create new PHPExcel object
echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();

// Read from Excel5 (.xls) template
echo date('H:i:s') . " Load Excel2007 template file\n";
$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("templates/CCC.xls");

// Export to Excel2007 (.xlsx)
echo date('H:i:s') . " Write to Excel5 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));

// Export to Excel5 (.xls)
echo date('H:i:s') . " Write to Excel5 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));


// Echo memory peak usage
echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";

// Echo done
echo date('H:i:s') . " Done writing files.\r\n";

 

My server is running PHP 5.2.17. I'm being hosted on MediaTemple and I'm running Mac OS 10.6 (if that has anything to do with it...). The original file trying to be changed was saved in Excel in Office for Mac 2011, and it contains one image at the top and a line of merged cells at the bottom.

 

Thanks for any help!

Mar 28, 2012 at 8:14 AM
Edited Mar 30, 2012 at 3:34 AM

you need check your code, if mergeCells('B20:B20) in your code, it doesn't work for read