Class TextStyleBuilder
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
TextStyleBuilder
文本样式的构建器。
详细文档
setFontFamily(fontFamily)
设置文本字体系列,例如“Arial”。
参数
名称 | 类型 | 说明 |
fontFamily | String | 所需的字体系列。 |
返回
TextStyleBuilder
- 用于链式调用的构建器。
setFontSize(fontSize)
设置文本字体大小(以点为单位)。
参数
名称 | 类型 | 说明 |
fontSize | Integer | 所需的字号。 |
返回
TextStyleBuilder
- 用于链式调用的构建器。
setForegroundColor(cssString)
设置文本字体颜色。
参数
名称 | 类型 | 说明 |
cssString | String | 所需的 CSS 注释字体颜色(例如 '#ffffff' 或 'white' )。 |
返回
TextStyleBuilder
- 用于链式调用的构建器。
setForegroundColorObject(color)
setStrikethrough(strikethrough)
设置文本是否带有删除线。
参数
名称 | 类型 | 说明 |
strikethrough | Boolean | 文本是否带有删除线。 |
返回
TextStyleBuilder
- 用于链式调用的构建器。
setUnderline(underline)
设置文本是否带下划线。
参数
名称 | 类型 | 说明 |
underline | Boolean | 文本是否带下划线。 |
返回
TextStyleBuilder
- 用于链式调用的构建器。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eTextStyleBuilder\u003c/code\u003e helps create custom text styles with various formatting options.\u003c/p\u003e\n"],["\u003cp\u003eYou can specify font family, size, color, and styles like bold, italic, underline, and strikethrough.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods like \u003ccode\u003esetBold\u003c/code\u003e, \u003ccode\u003esetFontFamily\u003c/code\u003e, \u003ccode\u003esetFontSize\u003c/code\u003e, and others to define text attributes.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003ebuild()\u003c/code\u003e method to create a \u003ccode\u003eTextStyle\u003c/code\u003e object with your defined formatting.\u003c/p\u003e\n"],["\u003cp\u003eThis builder enables flexible and detailed control over text presentation in Google Apps Script.\u003c/p\u003e\n"]]],[],null,["# Class TextStyleBuilder\n\nTextStyleBuilder\n\nA builder for text styles. \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------------------------------|------------------------------------------------------------|-------------------------------------------------|\n| [build()](#build()) | [TextStyle](/apps-script/reference/spreadsheet/text-style) | Creates a text style from this builder. |\n| [setBold(bold)](#setBold(Boolean)) | [TextStyleBuilder](#) | Sets whether or not the text is bold. |\n| [setFontFamily(fontFamily)](#setFontFamily(String)) | [TextStyleBuilder](#) | Sets the text font family, such as \"Arial\". |\n| [setFontSize(fontSize)](#setFontSize(Integer)) | [TextStyleBuilder](#) | Sets the text font size in points. |\n| [setForegroundColor(cssString)](#setForegroundColor(String)) | [TextStyleBuilder](#) | Sets the text font color. |\n| [setForegroundColorObject(color)](#setForegroundColorObject(Color)) | [TextStyleBuilder](#) | Sets the text font color. |\n| [setItalic(italic)](#setItalic(Boolean)) | [TextStyleBuilder](#) | Sets whether or not the text is italic. |\n| [setStrikethrough(strikethrough)](#setStrikethrough(Boolean)) | [TextStyleBuilder](#) | Sets whether or not the text has strikethrough. |\n| [setUnderline(underline)](#setUnderline(Boolean)) | [TextStyleBuilder](#) | Sets whether or not the text is underlined. |\n\nDetailed documentation\n----------------------\n\n### `build()`\n\nCreates a text style from this builder.\n\n#### Return\n\n\n[TextStyle](/apps-script/reference/spreadsheet/text-style) --- A text style created from this builder.\n\n*** ** * ** ***\n\n### `set``Bold(bold)`\n\nSets whether or not the text is bold.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|-----------|----------------------------------|\n| `bold` | `Boolean` | Whether or not the text is bold. |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- The builder for chaining.\n\n*** ** * ** ***\n\n### `set``Font``Family(fontFamily)`\n\nSets the text font family, such as \"Arial\".\n\n#### Parameters\n\n| Name | Type | Description |\n|----------------|----------|--------------------------|\n| `font``Family` | `String` | The desired font family. |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- The builder for chaining.\n\n*** ** * ** ***\n\n### `set``Font``Size(fontSize)`\n\nSets the text font size in points.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|-----------|------------------------|\n| `font``Size` | `Integer` | The desired font size. |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- The builder for chaining.\n\n*** ** * ** ***\n\n### `set``Foreground``Color(cssString)`\n\nSets the text font color.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------------|----------|----------------------------------------------------------------------------|\n| `css``String` | `String` | The desired font color in CSS notation (such as `'#ffffff'` or `'white'`). |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- The builder for chaining.\n\n*** ** * ** ***\n\n### `set``Foreground``Color``Object(color)`\n\nSets the text font color.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|---------------------------------------------------|-------------------------|\n| `color` | [Color](/apps-script/reference/spreadsheet/color) | The desired font color. |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- The builder for chaining.\n\n*** ** * ** ***\n\n### `set``Italic(italic)`\n\nSets whether or not the text is italic.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|-----------|------------------------------------|\n| `italic` | `Boolean` | Whether or not the text is italic. |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- The builder for chaining.\n\n*** ** * ** ***\n\n### `set``Strikethrough(strikethrough)`\n\nSets whether or not the text has strikethrough.\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------|-----------|--------------------------------------------|\n| `strikethrough` | `Boolean` | Whether or not the text has strikethrough. |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- The builder for chaining.\n\n*** ** * ** ***\n\n### `set``Underline(underline)`\n\nSets whether or not the text is underlined.\n\n#### Parameters\n\n| Name | Type | Description |\n|-------------|-----------|----------------------------------------|\n| `underline` | `Boolean` | Whether or not the text is underlined. |\n\n#### Return\n\n\n[TextStyleBuilder](#) --- The builder for chaining."]]