Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

Single cell print area #130

Closed
char101 opened this issue Jan 22, 2013 · 2 comments
Closed

Single cell print area #130

char101 opened this issue Jan 22, 2013 · 2 comments

Comments

@char101
Copy link

char101 commented Jan 22, 2013

Hi,

I have found a case when an excel file that opens fine in excel viewer and libreoffice but does not open in phpexcel. The problem is that the file has a single cell printarea:

worksheet$O$8

I have fixed it by the following patch

diff --git a/PHPExcel/Reader/Excel5.php b/PHPExcel/Reader/Excel5.php
index 79cd7b0..fd41b97 100755
--- a/PHPExcel/Reader/Excel5.php
+++ b/PHPExcel/Reader/Excel5.php
@@ -973,8 +973,13 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
                        }
                    }
                    if ($docSheet = $this->_phpExcel->getSheetByName($sheetName)) {
-                       $docSheet->getPageSetup()->setPrintArea(implode(',', $extractedRanges)); // C7:J66,A1:IV2
+                       $printArea = implode(',', $extractedRanges);
+                       if (false === strpos($printArea, ':')) {
+                           $printArea = "$printArea:$printArea";
+                       }
+                       $docSheet->getPageSetup()->setPrintArea($printArea); // C7:J66,A1:IV2
                    }
                    break;

                case pack('C', 0x07):
diff --git a/PHPExcel/Reader/Excel2007.php b/PHPExcel/Reader/Excel2007.php
index 1b3a67e..88f1049 100755
--- a/PHPExcel/Reader/Excel2007.php
+++ b/PHPExcel/Reader/Excel2007.php
@@ -1562,7 +1562,11 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE
                                                    $rangeSet = isset($range[1]) ? $range[1] : $range[0];
                                                    $newRangeSets[] = str_replace('$', '', $rangeSet);
                                                }
-                                               $docSheet->getPageSetup()->setPrintArea(implode(',',$newRangeSets));
+                                               $printArea = implode(',',$newRangeSets);
+                                               if (false === strpos($printArea, ':')) {
+                                                   $printArea = "$printArea:$printArea";
+                                               }
+                                               $docSheet->getPageSetup()->setPrintArea($printArea);
                                                break;

                                            default:
@MarkBaker
Copy link
Member

Looking at this now. The code you've updated won't work if there are multiple cell ranges, and one of them is single cell range, so modifying it to work in that sitution; but thanks for bringing it to our attention

@char101
Copy link
Author

char101 commented Jan 23, 2013

Thanks for the bugfix.

@Progi1984 Progi1984 added this to the 1.8.0 milestone Aug 14, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants