When using the OpenXML SDK to apply a border to a merged cell range, the border is only showing up for the first (top left) cell in the merge range. I have absolutely no idea and this is driving me crazy. Using the productivity tool I can't find any meaningful difference in what I have and something that works as expected. This is my generated XML for the stylesheet:
<x:borders count="2" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<x:border>
<x:left />
<x:right />
<x:top />
<x:bottom />
<x:diagonal />
</x:border>
<x:border>
<x:left />
<x:right />
<x:top />
<x:bottom style="thick">
<x:color auto="1" />
</x:bottom>
<x:diagonal />
</x:border>
</x:borders>
<x:cellXfs xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<x:xf fontId="0" />
<x:xf fontId="1" fillId="2" applyFont="1" applyFill="1" />
<x:xf borderId="1" applyBorder="1" />
</x:cellXfs>
I've tried everything, applying the merge before the border, after, etc.
Right-click the merged cell B1:D1, select "paste special -> formulas" You should see the merged cell being 0. Type Col1 in the merged cell. You should now see all B2, C2, D2 to be Col1, i.e. now you can reference the merged cell as you expect it to be.
Select the cell with the formatting you want to copy. Select Home > Format Painter. Drag to select the cell or range you want to apply the formatting to. Release the mouse button and the formatting should now be applied.
I've figured this out. I was under the impression that if you apply a style to the top left cell in a group of merged cells, then said style will apply to the whole merge. I swear I read some documentation that said that, but this is apparently not the case. What worked is that I applied the border style to each cell in the merge range, not just the first.
It seems weird to me that the way I initially had it is even allowed then, considering the generated output is impossible to reproduce other than through the OpenXML SDK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With