IronXL 操作指南 字体和大小 How to Set Cell Font and Size Chaknith Bin 已更新:八月 4, 2025 Download IronXL NuGet 下载 DLL 下载 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English Customizing font properties, including font name, size, color, underline, bold, italic, script, and strikeout, offers numerous benefits in document formatting. These options empower you to improve readability, emphasize critical information, and create visually appealing documents. With IronXL, you can effortlessly edit font properties without interop in C# .NET, simplifying the process and enabling you to create professional and polished materials effortlessly. Quickstart: Change a Cell's Font Size in One Line Use IronXL to instantly adjust the font size of a cell with minimal setup. This concise code shows how developers can pick a target cell and set its font height in a single, easy-to-read line using IronXL. Get started making PDFs with NuGet now: Install IronXL with NuGet Package Manager PM > Install-Package IronXL.Excel Copy and run this code snippet. workSheet["C3"].Style.Font.Height = 18; Deploy to test on your live environment Start using IronXL in your project today with a free trial Free 30 day Trial Minimal Workflow (5 steps) Download the C# library to set font and size Open an existing Excel spreadsheet or create a new one Use Font properties to customize font appearance, such as name, size, and boldness Set the Font to italic, strikeout, or use FontScript Explore all available options for underlining Set Cell Font and Size Example To personalize the font of a selected cell, column, row, or range, simply set the Font properties of the Style. Utilize the Name property to set the desired font family, the Height property to adjust the font size, and the Bold property to emphasize the font weight. Additionally, you can employ the Underline property to add underlining for further visual emphasis. 请注意The Name property sets the font name exactly as provided. For instance, if you want to use the "Times New Roman" font, make sure to input it exactly with the same spaces and capital letters. :path=/static-assets/excel/content-code-examples/how-to/cell-font-size-set-font.cs using IronXL; using IronXL.Styles; WorkBook workBook = WorkBook.Create(); WorkSheet workSheet = workBook.DefaultWorkSheet; workSheet["B2"].StringValue = "Font and Size"; // Set font family workSheet["B2"].Style.Font.Name = "Times New Roman"; // Set font size workSheet["B2"].Style.Font.Height = 15; // Set font to bold workSheet["B2"].Style.Font.Bold = true; // Set underline workSheet["B2"].Style.Font.Underline = FontUnderlineType.Single; workBook.SaveAs("fontAndSize.xlsx"); Imports IronXL Imports IronXL.Styles Private workBook As WorkBook = WorkBook.Create() Private workSheet As WorkSheet = workBook.DefaultWorkSheet Private workSheet("B2").StringValue = "Font and Size" ' Set font family Private workSheet("B2").Style.Font.Name = "Times New Roman" ' Set font size Private workSheet("B2").Style.Font.Height = 15 ' Set font to bold Private workSheet("B2").Style.Font.Bold = True ' Set underline Private workSheet("B2").Style.Font.Underline = FontUnderlineType.Single workBook.SaveAs("fontAndSize.xlsx") $vbLabelText $csharpLabel Set Cell Font and Size Advanced Example In addition to the options discussed in the previous section, you can further customize the font appearance in Excel. This includes setting the font to Italic, applying Strikeout, using FontScript for super and subscripts, and choosing a specific font color. Below is an example demonstrating how to utilize these additional options to create personalized font styles for your cells. :path=/static-assets/excel/content-code-examples/how-to/cell-font-size-set-font-advanced.cs using IronXL; using IronXL.Styles; WorkBook workBook = WorkBook.Create(); WorkSheet workSheet = workBook.DefaultWorkSheet; workSheet["B2"].StringValue = "Advanced"; // Set font family workSheet["B2"].Style.Font.Name = "Lucida Handwriting"; // Set font script workSheet["B2"].Style.Font.FontScript = FontScript.None; // Set underline workSheet["B2"].Style.Font.Underline = FontUnderlineType.Double; // Set bold property workSheet["B2"].Style.Font.Bold = true; // Set italic property workSheet["B2"].Style.Font.Italic = false; // Set strikeout property workSheet["B2"].Style.Font.Strikeout = false; // Set font color workSheet["B2"].Style.Font.Color = "#00FFFF"; workBook.SaveAs("fontAndSizeAdvanced.xlsx"); Imports IronXL Imports IronXL.Styles Private workBook As WorkBook = WorkBook.Create() Private workSheet As WorkSheet = workBook.DefaultWorkSheet Private workSheet("B2").StringValue = "Advanced" ' Set font family Private workSheet("B2").Style.Font.Name = "Lucida Handwriting" ' Set font script Private workSheet("B2").Style.Font.FontScript = FontScript.None ' Set underline Private workSheet("B2").Style.Font.Underline = FontUnderlineType.Double ' Set bold property Private workSheet("B2").Style.Font.Bold = True ' Set italic property Private workSheet("B2").Style.Font.Italic = False ' Set strikeout property Private workSheet("B2").Style.Font.Strikeout = False ' Set font color Private workSheet("B2").Style.Font.Color = "#00FFFF" workBook.SaveAs("fontAndSizeAdvanced.xlsx") $vbLabelText $csharpLabel Underline In Excel, there are different types of underlines available for text formatting. One such option is the Accounting underline, which has additional spacing between the characters and the lines compared to the normal underline. For text entries, the underline extends beyond the value both in front and back. However, for numeric data formats, the underline remains confined to the value. In cases where a cell contains both numbers and other characters, the Accounting underline will behave similarly to text. Font Script Font script in IronXL offers three options: none, super, and sub. none: The default option, setting the font on the baseline for regular text appearance. super: Positions text characters above the baseline for exponents or footnotes. sub: Positions text characters below the baseline for chemical formulas and math notations. Font Color You can set the font color using either the Color property or the SetColor method. The SetColor method accepts input in the form of IronSoftware.Drawing.Color or a Hex color code. :path=/static-assets/excel/content-code-examples/how-to/cell-font-size-set-font-color.cs using IronXL; using IronSoftware.Drawing; WorkBook workBook = WorkBook.Create(); WorkSheet workSheet = workBook.DefaultWorkSheet; // Set Color property workSheet["B2"].Style.Font.Color = "#00FFFF"; // Use Hex color code workSheet["B2"].Style.Font.SetColor("#00FFFF"); // Use IronSoftware.Drawing workSheet["B2"].Style.Font.SetColor(Color.Red); Imports IronXL Imports IronSoftware.Drawing Private workBook As WorkBook = WorkBook.Create() Private workSheet As WorkSheet = workBook.DefaultWorkSheet ' Set Color property Private workSheet("B2").Style.Font.Color = "#00FFFF" ' Use Hex color code workSheet("B2").Style.Font.SetColor("#00FFFF") ' Use IronSoftware.Drawing workSheet("B2").Style.Font.SetColor(Color.Red) $vbLabelText $csharpLabel 常见问题解答 如何在Excel电子表格中使用C#更改字体大小? 在IronXL中,您可以通过访问Font对象的Height属性来更改字体大小。例如,将cell.Style.Font.Height设置为您想要的大小。 IronXL中可用的字体自定义选项有哪些? IronXL允许自定义字体属性,如名称、大小、颜色、加粗、斜体、下划线、删除线和脚本(上标或下标)。 如何在Excel单元格中使用C#加粗文本? 要加粗文本,将Font对象的Bold属性设置为true。例如,在IronXL中使用cell.Style.Font.Bold = true。 是否可以在Excel中使用C#应用斜体和删除线样式到文本? 是的,您可以通过设置cell.Style.Font.Italic = true应用斜体,通过设置cell.Style.Font.Strikeout = true应用删除线,在IronXL中。 如何在Excel单元格中使用IronXL下划线文本? 使用Font对象的Underline属性应用下划线。例如,使用cell.Style.Font.Underline = ExcelFont.UnderlineType.Single。 IronXL中可用的字体脚本选项有哪些? IronXL提供三种字体脚本选项:none(默认)、super(用于上标)、sub(用于下标)。 如何在Excel单元格中使用C#更改字体颜色? 您可以使用IronXL的Color属性或SetColor方法更改字体颜色。例如,使用cell.Style.Font.Color = Color.Red或cell.Style.Font.SetColor("#FF0000")。 什么是Excel中的会计下划线? 会计下划线是一种下划线类型,包含额外的间距,通常用于数值,延伸超过文本项。 如何使用IronXL加载和保存Excel文件? 在IronXL中加载Excel文件,使用WorkBook.Load("example.xlsx")。要保存更改,使用workbook.SaveAs("example_modified.xlsx")。 我可以在Excel单元格中使用C#设置特定的字体系列吗? 是的,您可以通过将所需的字体名称赋值给cell.Style.Font.Name来设置特定的字体系列,例如'Arial'或'Times New Roman'在IronXL中。 Chaknith Bin 立即与工程团队聊天 软件工程师 Chaknith 在 IronXL 和 IronBarcode 工作。他在 C# 和 .NET 方面有着深厚的专业知识,帮助改进软件并支持客户。他从用户互动中获得的见解有助于更好的产品、文档和整体体验。 准备开始了吗? Nuget 下载 1,686,155 | 版本: 2025.11 刚刚发布 免费 NuGet 下载 总下载量:1,686,155 查看许可证