Excel.Style class
封装样式的格式和其他属性的对象。
属性
| auto |
指定当单元格中的文本对齐设置为等分布时是否自动缩进文本。 |
| borders | 表示四个边框样式的四个边框对象的集合。 |
| built |
指定样式是否为内置样式。 |
| context | 与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。 |
| fill | 样式的填充。 |
| font |
|
| formula |
指定在保护工作表时是否隐藏公式。 |
| horizontal |
表示样式水平对齐。 有关详细信息,请参阅 |
| include |
指定样式是否包括自动缩进、水平对齐、垂直对齐、自动换行、缩进级别和文本方向属性。 |
| include |
指定样式是否包括颜色、颜色索引、线条样式和粗细边框属性。 |
| include |
指定样式是否包括背景、粗体、颜色、颜色索引、字体样式、斜体、名称、大小、删除线、下标、上标和下划线字体属性。 |
| include |
指定样式是否包含数字格式属性。 |
| include |
指定样式是否包括颜色、颜色索引、反转(如果负)、图案、图案颜色和图案颜色索引内部属性。 |
| include |
指定样式是否包含公式隐藏和锁定保护属性。 |
| indent |
0 到 250 之间的一个整数,指示样式的缩进水平。 |
| locked | 指定在保护工作表时对象是否锁定。 |
| name | 样式的名称。 |
| number |
样式中数字格式的格式代码。 |
| number |
样式中数字格式的本地化格式代码。 |
| reading |
样式中的阅读顺序。 |
| shrink |
指定文本是否自动缩小以适应可用列宽。 |
| text |
此样式中的文本方向。 |
| vertical |
指定样式的垂直对齐方式。 有关详细信息,请参阅 |
| wrap |
指定 Excel 是否将文本换行到对象中。 |
方法
| delete() | 删除此样式。 |
| load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| set(properties, options) | 同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。 |
| set(properties) | 基于现有加载的对象,同时在对象上设置多个属性。 |
| toJSON() | 覆盖 JavaScript |
属性详细信息
autoIndent
borders
表示四个边框样式的四个边框对象的集合。
readonly borders: Excel.RangeBorderCollection;
属性值
注解
builtIn
context
fill
font
Font表示样式字体的对象。
readonly font: Excel.RangeFont;
属性值
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/style.yaml
await Excel.run(async (context) => {
let style = context.workbook.styles.getItem("Normal");
style.font.load("bold, color, italic, name, size");
style.fill.load("color");
await context.sync();
console.log("Bold: " + style.font.bold);
console.log("Font color: " + style.font.color);
console.log("Italic: " + style.font.italic);
console.log("Name: " + style.font.name);
console.log("Size: " + style.font.size);
console.log("Fill color: " + style.fill.color);
});
formulaHidden
horizontalAlignment
表示样式水平对齐。 有关详细信息,请参阅 Excel.HorizontalAlignment。
horizontalAlignment: Excel.HorizontalAlignment | "General" | "Left" | "Center" | "Right" | "Fill" | "Justify" | "CenterAcrossSelection" | "Distributed";
属性值
Excel.HorizontalAlignment | "General" | "Left" | "Center" | "Right" | "Fill" | "Justify" | "CenterAcrossSelection" | "Distributed"
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/style.yaml
await Excel.run(async (context) => {
let worksheet = context.workbook.worksheets.getItem("Sample");
let range = worksheet.getRange("A1:E1");
// Apply built-in style.
// Styles are in the Home tab ribbon.
range.style = Excel.BuiltInStyle.neutral;
range.format.horizontalAlignment = "Right";
await context.sync();
});
includeAlignment
指定样式是否包括自动缩进、水平对齐、垂直对齐、自动换行、缩进级别和文本方向属性。
includeAlignment: boolean;
属性值
boolean
注解
includeBorder
includeFont
指定样式是否包括背景、粗体、颜色、颜色索引、字体样式、斜体、名称、大小、删除线、下标、上标和下划线字体属性。
includeFont: boolean;
属性值
boolean
注解
includeNumber
includePatterns
指定样式是否包括颜色、颜色索引、反转(如果负)、图案、图案颜色和图案颜色索引内部属性。
includePatterns: boolean;
属性值
boolean
注解
includeProtection
indentLevel
locked
name
numberFormat
numberFormatLocal
readingOrder
样式中的阅读顺序。
readingOrder: Excel.ReadingOrder | "Context" | "LeftToRight" | "RightToLeft";
属性值
Excel.ReadingOrder | "Context" | "LeftToRight" | "RightToLeft"
注解
shrinkToFit
textOrientation
verticalAlignment
指定样式的垂直对齐方式。 有关详细信息,请参阅 Excel.VerticalAlignment。
verticalAlignment: Excel.VerticalAlignment | "Top" | "Center" | "Bottom" | "Justify" | "Distributed";
属性值
Excel.VerticalAlignment | "Top" | "Center" | "Bottom" | "Justify" | "Distributed"
注解
wrapText
方法详细信息
delete()
删除此样式。
delete(): void;
返回
void
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/style.yaml
await Excel.run(async (context) => {
let style = context.workbook.styles.getItem("Diagonal Orientation Style");
// Delete the diagonal orientation style from the style collection.
// Styles are in the Home tab ribbon.
style.delete();
await context.sync();
console.log("Successfully deleted the diagonal orientation style from the Home tab ribbon.");
});
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(options?: Excel.Interfaces.StyleLoadOptions): Excel.Style;
参数
为要加载的对象属性提供选项。
返回
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/style.yaml
await Excel.run(async (context) => {
let style = context.workbook.styles.getItem("Diagonal Orientation Style");
style.load("textOrientation, horizontalAlignment, autoIndent, readingOrder, wrapText, includeProtection, shrinkToFit, locked");
await context.sync();
console.log("Orientation: " + style.textOrientation);
console.log("Horizontal alignment: " + style.horizontalAlignment);
console.log("Add indent: " + style.autoIndent);
console.log("Reading order: " + style.readingOrder);
console.log("Wrap text: " + style.wrapText);
console.log("Include protection: " + style.includeProtection);
console.log("Shrink to fit: " + style.shrinkToFit);
console.log("Style locked: " + style.locked);
});
load(propertyNames)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNames?: string | string[]): Excel.Style;
参数
- propertyNames
-
string | string[]
指定要加载的属性的逗号分隔的字符串或字符串数组。
返回
load(propertyNamesAndPaths)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Excel.Style;
参数
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。
返回
set(properties, options)
同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。
set(properties: Interfaces.StyleUpdateData, options?: OfficeExtension.UpdateOptions): void;
参数
- properties
- Excel.Interfaces.StyleUpdateData
一个 JavaScript 对象,其属性与调用该方法的对象的属性同构结构。
- options
- OfficeExtension.UpdateOptions
提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止错误。
返回
void
set(properties)
toJSON()
覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Excel.Style 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 Excel.Interfaces.StyleData) ,其中包含从原始对象加载的任何子属性的浅层副本。
toJSON(): Excel.Interfaces.StyleData;