xlnt icon indicating copy to clipboard operation
xlnt copied to clipboard

Applying a border to a merged cell doesn't wrap around it fully.

Open musshorn opened this issue 3 years ago • 2 comments

Demo:

#include "xlnt/xlnt.hpp"
int main()
{
    xlnt::workbook wb;
    
    auto ws = wb.active_sheet();
    auto cell = ws.cell("B2");
    
    xlnt::border border;
    xlnt::border::border_property border_property;
    
    border_property.style(xlnt::border_style::thin);
    
    border.side(xlnt::border_side::start, border_property); // left
    border.side(xlnt::border_side::end, border_property); // right
    border.side(xlnt::border_side::top, border_property); // top
    border.side(xlnt::border_side::bottom, border_property); // bottom
    
    cell.border(border);
    
    // Now do the same thing with a merged cell
    ws.merge_cells("B4:D4");
    cell = ws.cell("B4");
    
    cell.border(border);
    
    // Change order of operations
    cell = ws.cell("B6");
    cell.border(border);
    ws.merge_cells("B6:D6");
    
    wb.save("border.xlsx");
    
    return 0;
}

The expected behaviour is that it would take on the formatting properties of the first cell, that seems consistent with how excel behaves.

I believe you could change worksheet::merge_cells to detect if there's a formatting applied to the first cell and copy that across, but I'm not sure what the solution is if the cells are merged first then have a border applied.

musshorn avatar Nov 10 '21 04:11 musshorn

This is a tricky one. I will have to see how Excel and LibreOffice Calc handle this at the data level when formatting merged cells (or merging formatted cells). I can report back here if I think of a workaround or if I open a PR to do it automatically.

tfussell avatar Jan 09 '22 22:01 tfussell

Is there a solution to the problem?

HarryColin avatar Nov 21 '23 01:11 HarryColin