Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Issue with merging cells in OfficeOpenXml worksheet

As you can see in the picture, ShiftLeaders row is merged, however, from the 4th to 7th row the values are dynamic(If there are more data more rows will be filled). Because of that, I can’t be sure what row to assign on setters and merge those two rows. The current way is displaying the table correctly, the problem is with setters and operators rows which can’t be merged. Any help is appreciated!

First column is ok:

ws.Cells["A3:C3"].Value = "Shift Leaders";
ws.Cells["A3:C3"].Merge = true;

Setters row is not merging:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ws.Cells[largestLeaders + 4, 2].Value = "Setters";
ws.Cells[largestLeaders + 4, 2].Merge = true;

As well as Operators row:

ws.Cells[largestSetters + 4 + largestLeaders + 2, 2].Value = "Operators";
ws.Cells[largestSetters + 4 + largestLeaders + 2, 2].Merge = true;

enter image description here

>Solution :

it looks like you are using single cell instead of cell range. try with range:

int n = largestLeaders + 4;
string range = $"A{n}:C{n}";
ws.Cells[range].Value = "Setters";
ws.Cells[range].Merge = true;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading