有谁知道如何使传递给工作表的内容正确对齐?
问问题
13423 次
2 回答
2
如果要对齐一个单元格,请使用
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
于 2014-03-20T14:30:09.153 回答
0
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;
}
如果您想在工作表中正确对齐特定部分
于 2020-01-01T09:17:28.373 回答