[英]C# and ExcelLibrary How to Right Align cells
有誰知道如何使傳遞給工作表的內容正確對齊?
如果你想對齊一個單元格使用
worksheet.Cells[y, x].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight;
如果要對齊多個
worksheet.get_Range("A1", "A30").Style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight;
如果您不能使用 Microsoft.Office.Interop.Excel 那么我不確定但您可以嘗試使用 ExcelCellStyle
ExcelCellStyle titleStyle = workbook.Styles.AddStyle("WorksheetTitleStyle");
// align the text
titleStyle.Alignment.HorizontalAlignment = ExcelCellHorizontalAlignmentType.right;
titleStyle.Alignment.VerticalAlignment = ExcelCellVerticalAlignmentType.Center;
您可能會在這里找到更多信息: 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;
}
如果要右對齊工作表中的特定部分
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.