I am trying to center text with the MVC lib ClosedXML but it only works when the cell has a background color set and I want to set the alignment without it:
var workbook = new XLWorkbook("c:\\temp\\file.xlsx");
var worksheet = workbook.Worksheet("Sheet");
worksheet .Cell(1, 1).Style.Fill.BackgroundColor = XLColor.White; // without this line it doe not work
worksheet.Cell(1, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
This works for me:
worksheet.Cell(1, 1).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
but as far as I know it's just a wrapper around ...Horizontal = XLAlignmentHorizontalValues.Center
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