Reputation: 771
This is how to merge cell using ClosedXML based on the documentation.
worksheet.Range("B2:D3").Row(1).Merge();
My problem is my column count is dynamic, I can't set column letter value to merge because i will based the merging of cell on my gridview column count.
Anyone who can help me to merge cell using closedXML?
Upvotes: 7
Views: 23454
Reputation: 91
I do it this way
int row = 1;
int col = 1;
worksheet.Range(worksheet.Cell(row, col++), worksheet.Cell(row, col++)).Merge();
Upvotes: 9
Reputation: 41
Have you tried the code below?
worksheet.Cell("A1").Value = "Title";
var range = worksheet.Range("A1:F1");
range.Merge().Style.Font.SetBold().Font.FontSize = 16;
It works for me.
Upvotes: 0
Reputation: 4849
Build up the range as a variable based on your column count and pass the variable to the Range
method. You don't need to HAVE to pass a hard coded value.
Upvotes: 1