سؤال

Does anybody know how to make it so that the content passed to the sheet will right align?

هل كانت مفيدة؟

المحلول

If you want to align one cell use

worksheet.Cells[y, x].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight;

If you want to align more than one

worksheet.get_Range("A1", "A30").Style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight;

If you can not use Microsoft.Office.Interop.Excel then I am not really sure but you can try to use ExcelCellStyle

ExcelCellStyle titleStyle = workbook.Styles.AddStyle("WorksheetTitleStyle");
// align the text
titleStyle.Alignment.HorizontalAlignment = ExcelCellHorizontalAlignmentType.right;
titleStyle.Alignment.VerticalAlignment = ExcelCellVerticalAlignmentType.Center;

you might find more here: http://www.winnovative-software.com/ExcelLibDemo/RangesAndCells.aspx

نصائح أخرى

using ClosedXML.Excel;

 using (ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook())
  {
    var ws = wb.Worksheets.Add("WorkSheetName");
    ws.Range(firstCellRow, firstCellColumn, lastCellRow, lastCellColumn).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right;
  }

if you want to right allign specific portion in worksheet

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top