Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.9.4

Bug #8967 Excel XP crashes when generated worksheet have many cell merges
Submitted: 2006-10-11 12:53 UTC
From: paladin80 at gmail dot com Assigned:
Status: Verified Package: Spreadsheet_Excel_Writer (version 0.9.1)
PHP Version: 5.0.4 OS: win XP
Roadmaps: (Not assigned)    
Subscription  


 [2006-10-11 12:53 UTC] paladin80 at gmail dot com (Serghei V. Burtsev)
Description: ------------ Excel XP crashes when generated worsheet have many column merges. Merges are become bugous when spreadsheet have about 400 of them. When count of merges is more than 700, Excel XP crushes. Test script: --------------- <?php include_once "Spreadsheet/Excel/Writer.php"; $xls =& new Spreadsheet_Excel_Writer(); $xls->send("table.xls"); $sheet =& $xls->addWorksheet('table'); for($i=0; $i<40; $i++){//change to $i<100 to get excel crush for($j=0;$j<20;$j+=2){ $sheet->setMerge($i, $j, $i, $j+1); } } $xls->close(); ?> Expected result: ---------------- A blank table, each cell must have colspan=2 and rowspan=1. Actual result: -------------- A blank table, each cell have colspan=2, but many cells from column "M" have rowspan=2. When I extend the table up to 100 rows, I get the excel crush.

Comments

 [2006-10-11 13:48 UTC] paladin80 at gmail dot com
Just avoided problem by using mergeCells() instead of setMerge().
 [2006-10-13 12:25 UTC] mj (Martin Jansen)
Spam
 [2006-10-13 12:25 UTC] mj (Martin Jansen)
Err, no spam. Sorry.
 [2008-11-06 14:04 UTC] mek7 (Matej Kurpel)
Man, thank you, you have saved me a lot of headache. It was indeed sufficient to replace "setMerge" with "mergeCells". Very confusing bug...
 [2009-10-14 14:29 UTC] sunny (Sanyasi Rao)
Thanks Serghei! You have saved me a lot of time by giving the solution.
 [2010-04-06 16:58 UTC] progi1984 (Franck Lefevre)
-Status: Open +Status: Verified
 [2010-09-07 15:27 UTC] thinklinux (Tihomir Valkanov)
Thanks. You save me a lot of time really!!! Interesting bug :)
 [2011-08-05 15:25 UTC] traxonja (Trax Phreak)
Thank you man! Although, this merge function does not merge properly on my Excel 2007. I have to re-merge cells in Excel when the document is open.
 [2011-08-05 17:30 UTC] traxonja (Trax Phreak)
Ok, I fixed this bug. Well, actually it is not a fix of the original problem, but it does the trick: In Worksheet.php find the function: "function setMerge($first_row, $first_col, $last_row, $last_col)" and add this code: if(count($this->_merged_ranges) >= 255) { $this->_storeMergedCells(); $this->_merged_ranges = array(); } just above the line: $this->_merged_ranges[] = array($first_row, $first_col, $last_row, $last_col); ----- Regards, Muris
 [2011-10-13 21:52 UTC] sbrow (Scott Brow)
mergeCells may avoid the blatent Excel error on open when there are too many merges but as others have mentioned it does not render exactly the same - it can cause a document to look very different from one merged with setMerge. I used traxonja's solution above so I could still use setMerge - it's working great - thanks!