Categories > OpenTBS with XLSX >

mergeCells

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Eduardo Sereno
Date: 2011-09-06
Time: 20:01

mergeCells

Is it possible to merge Cells in tbs/opentbs?

When I was working with PHPExcel the was a method that merges several cells into one:
$workbook = new PHPExcel;
$sheet = $workbook->getActiveSheet();
$sheet->setCellValue('A1','A pretty long sentence that deserves to be in a merged cell');
$sheet->mergeCells('A1:C1');

Is there any simple way to do the same with tbs?

Thanks in advance. Best regards to everyone

Edu
By: Skrol29
Date: 2011-09-07
Time: 00:35

Re: mergeCells

Hi Edourado,

There is no simple way to merge cells with OpenTBS because it's quite out of the range of a template system.

Nevertheless, the information of merged cells into a, Excel Sheet is saved at the end of the sheet, in an XML element like this :
    <mergeCells count="1">
        <mergeCell ref="B3:C3"/>
    </mergeCells>
So if you don't succeed in trying with a template solution, you can try to edit the XML contents.
By: Vladimir
Date: 2012-11-06
Time: 07:02

Re: mergeCells

I have written some code to resolve this issue.

You can find my decision here https://github.com/VladimirRybakov/OpenTBS
By: Skrol29
Date: 2012-11-08
Time: 00:36

Re: mergeCells

Hi Vladimir,

Thanks for sharing this. Where is the code which perform the change?
By: Vladimir
Date: 2012-11-08
Time: 06:14

Re: mergeCells

Hi

All changes was made in tbs_plugin_opentbs.php You can see changes here https://github.com/VladimirRybakov/OpenTBS/compare/542aff6682...51e1fac6c4
By: Skrol29
Date: 2012-11-14
Time: 00:47

Re: mergeCells

Thank you very much for your contribution.
It look very interesting. I will look into you code and see if it can be integrated in the next version.

Sorry to be long to reply sometimes.
Regards,
By: John Lawler
Date: 2013-05-08
Time: 00:56

Re: mergeCells

Hello, I'm looking to be able to define *horizontally* merged cells that will appear in a dynamic row position (depending on the number of rows merged in the main table above) and I think what you guys were discussing here would probably be the solution to the problem.

Skrol, I see you've released a couple of versions of OpenTBS since this thread, but I'm not sure whether the new "ope=mergecell" function is really implementing this (since it refers to Word and only *vertically* merging).

If mergecell does not address horizontal merges in Excel, do you still plan to do anything with this?  It's frustrating that cell formatting (e.g., borders, fill color, etc.) *does* easily follow in the row I intend it to (based on the template and rows being duplicated above), but that merging won't.

Just thought I'd check in to see if you could address the first question and then indicate if you plan to do any official support similar what I assume Vladimir's patch does.
By: John Lawler
Date: 2013-05-08
Time: 01:00

Re: mergeCells

Skrol, as another small point, you mention that we could edit the XML in the actual document to achieve this, and for my immediate purposes (I need to get a couple of Excel templates done ASAP), I might be able to fairly easily just do this in a more manual fashion.  You indicated that we should edit this section of XML:

<mergeCells count="1">
  <mergeCell ref="B3:C3"/>
</mergeCells>

(for example) -- could you briefly explain (or point me to some documentation that does) how we would do this, e.g., while merging an XLSX workbook in OpenTBS?  Is there some simple way I can get the string that contains that <mergeCells> block in it and replace it with my own calculated difference?

Thanks.
By: Skrol29
Date: 2013-05-09
Time: 23:30

Re: mergeCells

> If mergecell does not address horizontal merges in Excel, do you still plan to do anything with this?

Cells merge in Excel (vertical or horizontal) are too complicated to manage by OpenTBS for now because it is defined with the coordinated of the cells (with the XML entity you've noticed above).
IN the template, the <mergeCells> element contain the coordinates of merged cells with their coordinates in the template. Those coordinates become totally wrong after OpenTBS has deleted or added cells.
And it is too complicated to follow the position of cells after the TBS has merged.

You can try to edit <mergeCells> yourself. This entity is placed at the end of the XML of the sheet. The XML of the sheet can be edited using $TBS->Source after you've selected the sheet (with OPENTBS_SELECT_SHEET).
By: John Lawler
Date: 2013-05-09
Time: 23:51

Re: mergeCells

Thanks for the reply re. using $TBS->Source, Skrol, I'll look into that next time I feel this requirement.