spout
spout copied to clipboard
Propose of the way of cell merging in Writer
We can add list of ranges for merging cells to classes based on WorksheetInterface
in this way
ranges = [Range(), Range()]
where Range - class with 4 ints: x, y of top left cell and x, y of bottom right cell
Then we can handle it in such way:
- XLSX - add section
<mergeCells><mergeCell ref="A1:A2"/></mergeCells>
in sheet - ODS - modify
addRow
to check this ranges,- if cell is the first cell of range - add attributes
table:number-columns-spanned="2" table:number-rows-spanned="2"
- if cell in the first row of range - skip
- if cell in another rows - add element
<table:covered-table-cell table:number-columns-repeated="2"/>
insted of all cells in this row from this range
- if cell is the first cell of range - add attributes
- CSV - throw exception
Unsupported
We can make pull request, if you approve this idea. Also we will be glad to see any additional ideas and comments
related to #303 #350
Would be very interested in this.
It is a very important functionality! Hopefully it can be implemented very soon, or how can we do that?
+1 Is such functionality planned?
is there any update on this?
hey guys. We need this. Its make this lib more awesome than other.
Hello, please implement this function XLSX "mergeCells". Thank you
@adrilo are there any plans for this functionality? The author seemed to be willing to write the implementation himself, or might already have something prepared (this was 2 years ago though)
There are no plans for this functionality at the moment. But Pull Requests are always welcomed!
I desperately needed this feature too so I forked the project and made some maybe dirty hacks
Firstly I get merge ranges just as planty array of strings i.e.
['A1:C1','A1:A5',...]
Modified Box\Spout\Writer\Common\Entity\Sheet class by adding mergeRanges param and get/set methods so I could set merge ranges for sheet
$sheet = $writer->getCurrentSheet(); $sheet->setMergeRanges($mergeRanges);
Modified close function in Box\Spout\Writer\XLSX\Manager\WorksheetManager like
if (!\is_resource($worksheetFilePointer)) {
return;
}
\fwrite($worksheetFilePointer, '</sheetData>');
$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);`
I use this awesome lib only for xlsx export and only for one sheet and it works for me fine so far :)
It's already 2021, and this feature is still not implemented.
+1
+1
XLSX merge cell feature added in https://github.com/openspout/openspout/pull/21