diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index cdcfb684..1eed5ced 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -871,11 +871,11 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * * @param string $pColumn Numeric column coordinate of the cell * @param string $pRow Numeric row coordinate of the cell - * @param mixed $pValue Value of the cell + * @param mixed $pValue Value of the cell * @param bool $returnCell Return the worksheet (false, default) or the cell (true) * @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified */ - public function setCellValueByColumnAndRow($pColumn = 0, $pRow = 0, $pValue = null, $returnCell = false) + public function setCellValueByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $returnCell = false) { $cell = $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); $cell->setValue($pValue); @@ -906,11 +906,11 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * * @param string $pColumn Numeric column coordinate of the cell * @param string $pRow Numeric row coordinate of the cell - * @param mixed $pValue Value of the cell + * @param mixed $pValue Value of the cell * @param string $pDataType Explicit data type * @return PHPExcel_Worksheet */ - public function setCellValueExplicitByColumnAndRow($pColumn = 0, $pRow = 0, $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING) + public function setCellValueExplicitByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING) { return $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow)->setValueExplicit($pValue, $pDataType); } @@ -992,7 +992,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @param string $pRow Numeric row coordinate of the cell * @return PHPExcel_Cell Cell that was found */ - public function getCellByColumnAndRow($pColumn = 0, $pRow = 0) + public function getCellByColumnAndRow($pColumn = 0, $pRow = 1) { $columnLetter = PHPExcel_Cell::stringFromColumnIndex($pColumn); $coordinate = $columnLetter . $pRow; @@ -1066,7 +1066,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @param string $pRow Numeric row coordinate of the cell * @return boolean */ - public function cellExistsByColumnAndRow($pColumn = 0, $pRow = 0) + public function cellExistsByColumnAndRow($pColumn = 0, $pRow = 1) { return $this->cellExists(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); } @@ -1077,7 +1077,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @param int $pRow Numeric index of the row * @return PHPExcel_Worksheet_RowDimension */ - public function getRowDimension($pRow = 0) + public function getRowDimension($pRow = 1) { // Found $found = null; @@ -1253,7 +1253,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @param int $pRow Numeric row coordinate of the cell * @return PHPExcel_Style */ - public function getStyleByColumnAndRow($pColumn = 0, $pRow = 0) + public function getStyleByColumnAndRow($pColumn = 0, $pRow = 1) { return $this->getStyle(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); } @@ -1384,13 +1384,13 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable /** * Set break on a cell by using numeric cell coordinates * - * @param int $pColumn Numeric column coordinate of the cell - * @param int $pRow Numeric row coordinate of the cell - * @param int $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*) + * @param integer $pColumn Numeric column coordinate of the cell + * @param integer $pRow Numeric row coordinate of the cell + * @param integer $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*) * @throws Exception * @return PHPExcel_Worksheet */ - public function setBreakByColumnAndRow($pColumn = 0, $pRow = 0, $pBreak = PHPExcel_Worksheet::BREAK_NONE) + public function setBreakByColumnAndRow($pColumn = 0, $pRow = 1, $pBreak = PHPExcel_Worksheet::BREAK_NONE) { return $this->setBreak(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow, $pBreak); } @@ -1454,7 +1454,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @throws Exception * @return PHPExcel_Worksheet */ - public function mergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 0, $pColumn2 = 0, $pRow2 = 0) + public function mergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1) { $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; return $this->mergeCells($cellRange); @@ -1495,7 +1495,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @throws Exception * @return PHPExcel_Worksheet */ - public function unmergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 0, $pColumn2 = 0, $pRow2 = 0) + public function unmergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1) { $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; return $this->unmergeCells($cellRange); @@ -1558,7 +1558,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @throws Exception * @return PHPExcel_Worksheet */ - public function protectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 0, $pColumn2 = 0, $pRow2 = 0, $pPassword = '', $pAlreadyHashed = false) + public function protectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false) { $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; return $this->protectCells($cellRange, $pPassword, $pAlreadyHashed); @@ -1596,7 +1596,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @throws Exception * @return PHPExcel_Worksheet */ - public function unprotectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 0, $pColumn2 = 0, $pRow2 = 0, $pPassword = '', $pAlreadyHashed = false) + public function unprotectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false) { $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; return $this->unprotectCells($cellRange, $pPassword, $pAlreadyHashed); @@ -1653,7 +1653,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @throws Exception * @return PHPExcel_Worksheet */ - public function setAutoFilterByColumnAndRow($pColumn1 = 0, $pRow1 = 0, $pColumn2 = 0, $pRow2 = 0) + public function setAutoFilterByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1) { return $this->setAutoFilter( PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 @@ -1711,7 +1711,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @throws Exception * @return PHPExcel_Worksheet */ - public function freezePaneByColumnAndRow($pColumn = 0, $pRow = 0) + public function freezePaneByColumnAndRow($pColumn = 0, $pRow = 1) { return $this->freezePane(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); } @@ -1979,7 +1979,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @param int $pRow Numeric row coordinate of the cell * @return PHPExcel_Comment */ - public function getCommentByColumnAndRow($pColumn = 0, $pRow = 0) + public function getCommentByColumnAndRow($pColumn = 0, $pRow = 1) { return $this->getComment(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); } @@ -2068,7 +2068,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable * @throws Exception * @return PHPExcel_Worksheet */ - public function setSelectedCellByColumnAndRow($pColumn = 0, $pRow = 0) + public function setSelectedCellByColumnAndRow($pColumn = 0, $pRow = 1) { return $this->setSelectedCells(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); } diff --git a/Classes/PHPExcel/Writer/Excel2007/Worksheet.php b/Classes/PHPExcel/Writer/Excel2007/Worksheet.php index e32357b9..73cb5ca5 100644 --- a/Classes/PHPExcel/Writer/Excel2007/Worksheet.php +++ b/Classes/PHPExcel/Writer/Excel2007/Worksheet.php @@ -198,10 +198,10 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ // sheetViews $objWriter->startElement('sheetViews'); - // Sheet selected? - $sheetSelected = false; - if ($this->getParentWriter()->getPHPExcel()->getIndex($pSheet) == $this->getParentWriter()->getPHPExcel()->getActiveSheetIndex()) - $sheetSelected = true; + // Sheet selected? + $sheetSelected = false; + if ($this->getParentWriter()->getPHPExcel()->getIndex($pSheet) == $this->getParentWriter()->getPHPExcel()->getActiveSheetIndex()) + $sheetSelected = true; // sheetView @@ -209,13 +209,13 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ $objWriter->writeAttribute('tabSelected', $sheetSelected ? '1' : '0'); $objWriter->writeAttribute('workbookViewId', '0'); - // Zoom scales - if ($pSheet->getSheetView()->getZoomScale() != 100) { - $objWriter->writeAttribute('zoomScale', $pSheet->getSheetView()->getZoomScale()); - } - if ($pSheet->getSheetView()->getZoomScaleNormal() != 100) { - $objWriter->writeAttribute('zoomScaleNormal', $pSheet->getSheetView()->getZoomScaleNormal()); - } + // Zoom scales + if ($pSheet->getSheetView()->getZoomScale() != 100) { + $objWriter->writeAttribute('zoomScale', $pSheet->getSheetView()->getZoomScale()); + } + if ($pSheet->getSheetView()->getZoomScaleNormal() != 100) { + $objWriter->writeAttribute('zoomScaleNormal', $pSheet->getSheetView()->getZoomScaleNormal()); + } // Gridlines if ($pSheet->getShowGridlines()) { @@ -236,31 +236,50 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ $objWriter->writeAttribute('rightToLeft', 'true'); } - // Pane - if ($pSheet->getFreezePane() != '') { - // Calculate freeze coordinates - $xSplit = 0; - $ySplit = 0; - $topLeftCell = $pSheet->getFreezePane(); + $activeCell = $pSheet->getActiveCell(); - list($xSplit, $ySplit) = PHPExcel_Cell::coordinateFromString($pSheet->getFreezePane()); + // Pane + $pane = ''; + $topLeftCell = $pSheet->getFreezePane(); + if (($topLeftCell != '') && ($topLeftCell != 'A1')) { + $activeCell = $topLeftCell; + // Calculate freeze coordinates + $xSplit = $ySplit = 0; + + list($xSplit, $ySplit) = PHPExcel_Cell::coordinateFromString($topLeftCell); $xSplit = PHPExcel_Cell::columnIndexFromString($xSplit); // pane + $pane = 'topRight'; $objWriter->startElement('pane'); - $objWriter->writeAttribute('xSplit', $xSplit - 1); - $objWriter->writeAttribute('ySplit', $ySplit - 1); + if ($xSplit > 1) + $objWriter->writeAttribute('xSplit', $xSplit - 1); + if ($ySplit > 1) { + $objWriter->writeAttribute('ySplit', $ySplit - 1); + $pane = ($xSplit > 1) ? 'bottomRight' : 'bottomLeft'; + } $objWriter->writeAttribute('topLeftCell', $topLeftCell); - $objWriter->writeAttribute('activePane', 'bottomRight'); + $objWriter->writeAttribute('activePane', $pane); $objWriter->writeAttribute('state', 'frozen'); $objWriter->endElement(); + + if (($xSplit > 1) && ($ySplit > 1)) { + // Write additional selections if more than two panes (ie both an X and a Y split) + $objWriter->startElement('selection'); $objWriter->writeAttribute('pane', 'topRight'); $objWriter->endElement(); + $objWriter->startElement('selection'); $objWriter->writeAttribute('pane', 'bottomLeft'); $objWriter->endElement(); + } } // Selection - $objWriter->startElement('selection'); - $objWriter->writeAttribute('activeCell', $pSheet->getActiveCell()); - $objWriter->writeAttribute('sqref', $pSheet->getSelectedCells()); - $objWriter->endElement(); + if ($pane != '') { + // Only need to write selection element if we have a split pane + // We cheat a little by over-riding the active cell selection, setting it to the split cell + $objWriter->startElement('selection'); + $objWriter->writeAttribute('pane', $pane); + $objWriter->writeAttribute('activeCell', $activeCell); + $objWriter->writeAttribute('sqref', $activeCell); + $objWriter->endElement(); + } $objWriter->endElement(); @@ -282,14 +301,14 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ // Default row height if ($pSheet->getDefaultRowDimension()->getRowHeight() >= 0) { $objWriter->writeAttribute('customHeight', 'true'); - $objWriter->writeAttribute('defaultRowHeight', PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultRowDimension()->getRowHeight())); + $objWriter->writeAttribute('defaultRowHeight', PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultRowDimension()->getRowHeight())); } else { - $objWriter->writeAttribute('defaultRowHeight', '12.75'); + $objWriter->writeAttribute('defaultRowHeight', '12.75'); } // Default column width if ($pSheet->getDefaultColumnDimension()->getWidth() >= 0) { - $objWriter->writeAttribute('defaultColWidth', PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultColumnDimension()->getWidth())); + $objWriter->writeAttribute('defaultColWidth', PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultColumnDimension()->getWidth())); } // Outline level - row @@ -299,7 +318,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ $outlineLevelRow = $dimension->getOutlineLevel(); } } - $objWriter->writeAttribute('outlineLevelRow', (int)$outlineLevelRow); + $objWriter->writeAttribute('outlineLevelRow', (int)$outlineLevelRow); // Outline level - column $outlineLevelCol = 0; @@ -308,7 +327,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ $outlineLevelCol = $dimension->getOutlineLevel(); } } - $objWriter->writeAttribute('outlineLevelCol', (int)$outlineLevelCol); + $objWriter->writeAttribute('outlineLevelCol', (int)$outlineLevelCol); $objWriter->endElement(); } @@ -456,23 +475,23 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ $objWriter->writeAttribute('text', $conditional->getText()); } - if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT - && $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT - && !is_null($conditional->getText())) { - $objWriter->writeElement('formula', 'NOT(ISERROR(SEARCH("' . $conditional->getText() . '",' . $cellCoordinate . ')))'); - } else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT - && $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_BEGINSWITH - && !is_null($conditional->getText())) { - $objWriter->writeElement('formula', 'LEFT(' . $cellCoordinate . ',' . strlen($conditional->getText()) . ')="' . $conditional->getText() . '"'); - } else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT - && $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_ENDSWITH - && !is_null($conditional->getText())) { - $objWriter->writeElement('formula', 'RIGHT(' . $cellCoordinate . ',' . strlen($conditional->getText()) . ')="' . $conditional->getText() . '"'); - } else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT - && $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_NOTCONTAINS - && !is_null($conditional->getText())) { - $objWriter->writeElement('formula', 'ISERROR(SEARCH("' . $conditional->getText() . '",' . $cellCoordinate . '))'); - } else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CELLIS + if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT + && $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT + && !is_null($conditional->getText())) { + $objWriter->writeElement('formula', 'NOT(ISERROR(SEARCH("' . $conditional->getText() . '",' . $cellCoordinate . ')))'); + } else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT + && $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_BEGINSWITH + && !is_null($conditional->getText())) { + $objWriter->writeElement('formula', 'LEFT(' . $cellCoordinate . ',' . strlen($conditional->getText()) . ')="' . $conditional->getText() . '"'); + } else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT + && $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_ENDSWITH + && !is_null($conditional->getText())) { + $objWriter->writeElement('formula', 'RIGHT(' . $cellCoordinate . ',' . strlen($conditional->getText()) . ')="' . $conditional->getText() . '"'); + } else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT + && $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_NOTCONTAINS + && !is_null($conditional->getText())) { + $objWriter->writeElement('formula', 'ISERROR(SEARCH("' . $conditional->getText() . '",' . $cellCoordinate . '))'); + } else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CELLIS || $conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT || $conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_EXPRESSION) { foreach ($conditional->getConditions() as $formula) { @@ -726,20 +745,20 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ $objWriter->writeAttribute('orientation', $pSheet->getPageSetup()->getOrientation()); if (!is_null($pSheet->getPageSetup()->getScale())) { - $objWriter->writeAttribute('scale', $pSheet->getPageSetup()->getScale()); + $objWriter->writeAttribute('scale', $pSheet->getPageSetup()->getScale()); } if (!is_null($pSheet->getPageSetup()->getFitToHeight())) { - $objWriter->writeAttribute('fitToHeight', $pSheet->getPageSetup()->getFitToHeight()); + $objWriter->writeAttribute('fitToHeight', $pSheet->getPageSetup()->getFitToHeight()); } else { - $objWriter->writeAttribute('fitToHeight', '0'); + $objWriter->writeAttribute('fitToHeight', '0'); } if (!is_null($pSheet->getPageSetup()->getFitToWidth())) { - $objWriter->writeAttribute('fitToWidth', $pSheet->getPageSetup()->getFitToWidth()); + $objWriter->writeAttribute('fitToWidth', $pSheet->getPageSetup()->getFitToWidth()); } else { - $objWriter->writeAttribute('fitToWidth', '0'); + $objWriter->writeAttribute('fitToWidth', '0'); } if (!is_null($pSheet->getPageSetup()->getFirstPageNumber())) { - $objWriter->writeAttribute('firstPageNumber', $pSheet->getPageSetup()->getFirstPageNumber()); + $objWriter->writeAttribute('firstPageNumber', $pSheet->getPageSetup()->getFirstPageNumber()); $objWriter->writeAttribute('useFirstPageNumber', '1'); } @@ -864,7 +883,7 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ $rowDimension = $pSheet->getRowDimension($currentRow); // Write current row? - $writeCurrentRow = isset($cellsByRow[$currentRow]) || + $writeCurrentRow = isset($cellsByRow[$currentRow]) || $rowDimension->getRowHeight() >= 0 || $rowDimension->getVisible() == false || $rowDimension->getCollapsed() == true || diff --git a/changelog.txt b/changelog.txt index 4a4015ec..71538080 100644 --- a/changelog.txt +++ b/changelog.txt @@ -54,7 +54,10 @@ Fixed in SVN: - Bugfix: (MBaker) Work item 14980 - Images not getting copyied with the ->clone function - Bugfix: (MBaker) Work item 11576 - AdvancedValueBinder.php: String sometimes becomes a date when it shouldn't - Bugfix: (MBaker) Fix Excel5 Writer so that it only writes column dimensions for columns that are actually used rather than the full range (A to IV) +- Bugfix: (MBaker) The freezePaneByColumnAndRow() method row argument should default to 1 rather than 0. + Default row argument for all __ByColumnAndRow() methods should be 1 - General: (MBaker) Improved performance (speed), for building the Shared Strings table in the Excel2007 Writer. +- General: (MBaker) Enhanced SheetViews element structures in the Excel2007 Writer for frozen panes.