This project has moved. For the latest updates, please go here.

Setting Alignment for a Vertically Merged Cells with rotated text.

Dec 4, 2012 at 11:55 AM
Edited Dec 5, 2012 at 12:45 PM

Hi guys, does setting alignment for vertically merged cells work?

When I set an alignment on horizontally merged cells then it works fine, however when I want to do the same with cells which were merged vertically nothing happens. Below, there is a sample code..

verticalTitle appears on the bottom of merged cells as default alignment is used.

Any suggestions?

Thanks

   using (ExcelRange verticalTitle = a_worksheet.Cells[fromRow,1,toRow,1])
            {
                verticalTitle.Merge = true;
                verticalTitle.Style.TextRotation = 90;
                verticalTitle.Style.Font.Size = 18;
                verticalTitle.Style.Font.Bold = true;
                verticalTitle.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                verticalTitle.Style.Fill.BackgroundColor.SetColor(systemColor);
                verticalTitle.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
                verticalTitle.Value = m_model.Name;
            }


Dec 4, 2012 at 12:05 PM
Edited Dec 5, 2012 at 12:46 PM

Ok, I think it is solved, I tested it a little bit and it occurs that the order of assignments is meaningful. So, if alignment is set before setting text rotation it works properly. Strange, but fortunately I found simple solution for what I want to achieve.

 

 

using (ExcelRange verticalTitle = a_worksheet.Cells[fromRow,1,toRow,1])
            {
                verticalTitle.Merge = true;
                verticalTitle.Style.Font.Size = 18;
                verticalTitle.Style.Font.Bold = true;
                verticalTitle.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                verticalTitle.Style.Fill.BackgroundColor.SetColor(systemColor);
                verticalTitle.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
                verticalTitle.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                verticalTitle.Style.TextRotation = 90;
                verticalTitle.Value = m_model.Name;
            }