Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Fix the problem of merging cells #762

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ after_script:
if [[ "$WITH_COVERAGE" == "true" ]]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/logs/coverage.clover
fi
fi
4 changes: 2 additions & 2 deletions src/Spout/Reader/ODS/SheetIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class SheetIterator implements IteratorInterface
const XML_ATTRIBUTE_TABLE_STYLE_NAME = 'table:style-name';
const XML_ATTRIBUTE_TABLE_DISPLAY = 'table:display';

/** @var string $filePath Path of the file to be read */
/** @var string Path of the file to be read */
protected $filePath;

/** @var \Box\Spout\Common\Manager\OptionsManagerInterface Reader's options manager */
protected $optionsManager;

/** @var InternalEntityFactory $entityFactory Factory to create entities */
/** @var InternalEntityFactory Factory to create entities */
protected $entityFactory;

/** @var XMLReader The XMLReader object that will help read sheet's XML data */
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Reader/XLSX/Manager/SharedStringsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SharedStringsManager
/** @var InternalEntityFactory Factory to create entities */
protected $entityFactory;

/** @var HelperFactory $helperFactory Factory to create helpers */
/** @var HelperFactory Factory to create helpers */
protected $helperFactory;

/** @var CachingStrategyFactory Factory to create shared strings caching strategies */
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Reader/XLSX/RowIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RowIterator implements IteratorInterface
/** @var string Path of the XLSX file being read */
protected $filePath;

/** @var string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml */
/** @var string Path of the sheet data XML file as in [Content_Types].xml */
protected $sheetDataXMLFilePath;

/** @var \Box\Spout\Reader\Wrapper\XMLReader The XMLReader object that will help read sheet's XML data */
Expand Down
20 changes: 20 additions & 0 deletions src/Spout/Writer/Common/Entity/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Sheet
/** @var SheetManager Sheet manager */
private $sheetManager;

/** @var merge cell */
private $mergeRanges;

/**
* @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
* @param string $associatedWorkbookId ID of the sheet's associated workbook
Expand Down Expand Up @@ -108,4 +111,21 @@ public function setIsVisible($isVisible)

return $this;
}

/**
* @return merge
*/
public function getMergeRanges()
{
return $this->mergeRanges;
}

/**
* @param $mergeRanges
* @return mixed
*/
public function setMergeRanges($mergeRanges)
{
return $this->mergeRanges = $mergeRanges;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
/** @var InternalEntityFactory Factory to create entities */
protected $entityFactory;

/** @var ManagerFactoryInterface $managerFactory Factory to create managers */
/** @var ManagerFactoryInterface Factory to create managers */
protected $managerFactory;

/** @var Worksheet The worksheet where data will be written to */
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Writer/ODS/Creator/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ManagerFactory implements ManagerFactoryInterface
/** @var InternalEntityFactory */
protected $entityFactory;

/** @var HelperFactory $helperFactory */
/** @var HelperFactory */
protected $helperFactory;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Writer/WriterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class WriterAbstract implements WriterInterface
/** @var GlobalFunctionsHelper Helper to work with global functions */
protected $globalFunctionsHelper;

/** @var HelperFactory $helperFactory */
/** @var HelperFactory */
protected $helperFactory;

/** @var OptionsManagerInterface Writer options manager */
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Writer/XLSX/Creator/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ManagerFactory implements ManagerFactoryInterface
/** @var InternalEntityFactory */
protected $entityFactory;

/** @var HelperFactory $helperFactory */
/** @var HelperFactory */
protected $helperFactory;

/**
Expand Down
11 changes: 11 additions & 0 deletions src/Spout/Writer/XLSX/Manager/WorksheetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ public function close(Worksheet $worksheet)
}

\fwrite($worksheetFilePointer, '</sheetData>');
// do something to merging cells
$mergeRanges = $worksheet->getExternalSheet()->getMergeRanges();
if (!empty($mergeRanges)) {
$startLine = '<mergeCells count="1">';
$rangeLine = '';
foreach ($mergeRanges as $key => $range) {
$rangeLine .= '<mergeCell ref="' . $range . '"/>';
}
$endLine = '</mergeCells>';
\fwrite($worksheetFilePointer, $startLine . $rangeLine . $endLine);
}
\fwrite($worksheetFilePointer, '</worksheet>');
\fclose($worksheetFilePointer);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Spout/Reader/CSV/SpoutTestStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class SpoutTestStream
const PATH_TO_CSV_RESOURCES = 'tests/resources/csv/';
const CSV_EXTENSION = '.csv';

/** @var int $position */
/** @var int */
private $position;

/** @var resource $fileHandle */
/** @var resource */
private $fileHandle;

/**
Expand Down