spout icon indicating copy to clipboard operation
spout copied to clipboard

Propose of the way of cell merging in Writer

Open vlad-khramov opened this issue 7 years ago • 13 comments

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
  • 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

vlad-khramov avatar Jan 18 '18 13:01 vlad-khramov

Would be very interested in this.

benfrancisiwgc avatar Feb 06 '18 17:02 benfrancisiwgc

It is a very important functionality! Hopefully it can be implemented very soon, or how can we do that?

anderblackhawk avatar Apr 19 '18 19:04 anderblackhawk

+1 Is such functionality planned?

dmitrymenshikov avatar Jul 13 '18 10:07 dmitrymenshikov

is there any update on this?

ardabeyazoglu avatar Sep 19 '19 16:09 ardabeyazoglu

hey guys. We need this. Its make this lib more awesome than other.

xCEZAREx avatar Oct 11 '19 12:10 xCEZAREx

Hello, please implement this function XLSX "mergeCells". Thank you

kareljedlicka avatar Jan 15 '20 10:01 kareljedlicka

@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)

quamis avatar Apr 01 '20 07:04 quamis

There are no plans for this functionality at the moment. But Pull Requests are always welcomed!

adrilo avatar Apr 07 '20 12:04 adrilo

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 :)

akteur13 avatar Apr 28 '20 16:04 akteur13

It's already 2021, and this feature is still not implemented.

apuppy avatar May 13 '21 08:05 apuppy

+1

jadamec avatar Oct 10 '21 14:10 jadamec

+1

elnurxf avatar Mar 09 '22 10:03 elnurxf

XLSX merge cell feature added in https://github.com/openspout/openspout/pull/21

Slamdunk avatar Mar 10 '22 08:03 Slamdunk