xlnt
xlnt copied to clipboard
Applying a border to a merged cell doesn't wrap around it fully.
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.
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.
Is there a solution to the problem?