Previous topicNext topic
Help > 开发指南 > Excel > API > 示例 > 设置单元格格式 >
如何:配置单元格字体设置

使用 SpreadsheetFont 对象的属性指定工作表单元格和单元格区域的字体属性。

 

Cell.Font 属性允许您修改单个单元格的字体。

 

若要更改单元格区域的字体特征,请调用此区域的 CellRange.BeginUpdateFormatting 方法,使用返回对象的 Font 属性访问和修改 SpreadsheetFont 属性,并调用 CellRange.EndUpdateFormatting 方法完成修改。

 

SpreadsheetFont 对象包含以下用于更改单元格字体属性的属性:

 

创建和修改单元格样式,以同时将多个格式属性应用于工作表单元格。

 

此示例演示如何通过修改通过 Cell 对象的 Formatting.Font 属性访问的 SpreadsheetFont 对象来设置单元格字体特征(例如,字体名称、大小、颜色、样式)的格式。

 
Vb.Net
'访问Font对象。
Dim cellFont As DevExpress.Spreadsheet.SpreadsheetFont = worksheet.Cells("A1").Font
'设置字体名称。
cellFont.Name = "Times New Roman"
'设置字体大小。
cellFont.Size = 14
'设置字体颜色。
cellFont.Color = Color.Blue
'将文本设置为粗体。
cellFont.Bold = True
'将字体设置为带下划线。
cellFont.UnderlineType = DevExpress.Spreadsheet.UnderlineType.Single

C#
// 访问Font对象。
DevExpress.Spreadsheet.SpreadsheetFont cellFont = worksheet.Cells["A1"].Font;
// 设置字体名称。
cellFont.Name = "Times New Roman";
// 设置字体大小。
cellFont.Size = 14;
// 设置字体颜色。
cellFont.Color = Color.Blue;
// 将文本设置为粗体。
cellFont.Bold = true;
// 将字体设置为带下划线。
cellFont.UnderlineType = DevExpress.Spreadsheet.UnderlineType.Single;

 

下图显示了结果(工作簿在 Microsoft® Excel® 中打开)。