Excel.RangeFormat class
一个格式对象,其中封装了区域的字体、填充、边框、对齐方式和其他属性。
属性
| auto |
指定当文本对齐设置为均匀分布时是否自动缩进文本。 |
| borders | 应用于整个区域的 Border 对象的集合。 |
| column |
指定范围内所有列的宽度。 如果列宽不一致, |
| context | 与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。 |
| fill | 返回在整个区域内定义的 fill 对象。 |
| font | 返回在整个区域内定义的 Font 对象。 |
| horizontal |
表示指定对象的水平对齐方式。 有关详细信息,请参阅 |
| indent |
0 到 250 之间的一个整数,指示缩进水平。 |
| protection | 返回某一区域的格式 protection 对象。 |
| reading |
区域的读取顺序。 |
| row |
区域中所有行的高度。 如果行高不一致, |
| shrink |
指定文本是否自动缩小以适应可用列宽。 |
| text |
区域内所有单元格的文本方向。 文本方向应为 -90 到 90 之间的整数,对于垂直方向的文本,应为 180。 如果某个范围内的方向不均匀, |
| use |
确定对象的 |
| use |
指定对象的 |
| vertical |
表示指定对象的垂直对齐方式。 有关详细信息,请参阅 |
| wrap |
指定 Excel 是否将文本换行到对象中。 一个 |
方法
| adjust |
调整区域格式的缩进。 缩进值的范围是 0 到 250,并且以字符为单位进行度量。 |
| autofit |
根据列中的当前数据更改当前范围的列宽,以达到最佳宽度。 |
| autofit |
根据列中的当前数据,更改当前范围的行高以达到最佳高度。 |
| load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| set(properties, options) | 同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。 |
| set(properties) | 基于现有加载的对象,同时在对象上设置多个属性。 |
| toJSON() | 覆盖 JavaScript |
属性详细信息
autoIndent
borders
应用于整个区域的 Border 对象的集合。
readonly borders: Excel.RangeBorderCollection;
属性值
注解
columnWidth
context
fill
font
horizontalAlignment
表示指定对象的水平对齐方式。 有关详细信息,请参阅 Excel.HorizontalAlignment。
horizontalAlignment: Excel.HorizontalAlignment | "General" | "Left" | "Center" | "Right" | "Fill" | "Justify" | "CenterAcrossSelection" | "Distributed";
属性值
Excel.HorizontalAlignment | "General" | "Left" | "Center" | "Right" | "Fill" | "Justify" | "CenterAcrossSelection" | "Distributed"
注解
indentLevel
protection
返回某一区域的格式 protection 对象。
readonly protection: Excel.FormatProtection;
属性值
注解
readingOrder
区域的读取顺序。
readingOrder: Excel.ReadingOrder | "Context" | "LeftToRight" | "RightToLeft";
属性值
Excel.ReadingOrder | "Context" | "LeftToRight" | "RightToLeft"
注解
rowHeight
shrinkToFit
textOrientation
区域内所有单元格的文本方向。 文本方向应为 -90 到 90 之间的整数,对于垂直方向的文本,应为 180。 如果某个范围内的方向不均匀, null 则将返回。
textOrientation: number;
属性值
number
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/range-text-orientation.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const range = sheet.getRange("B2:E2");
// Set textOrientation to either an integer between -90 and 90
// or to 180 for vertically-oriented text.
range.format.textOrientation = 90;
await context.sync();
});
useStandardHeight
确定对象的 Range 行高是否等于工作表的标准高度。 对象的Range行高是否等于工作表的标准高度,则返回true。 如果区域包含多个行,并且这些行的高度不相同,则返回 null 。 否则返回 false 。 注意:此属性仅用于设置为 true。 设置为 false 没有任何效果。
useStandardHeight: boolean;
属性值
boolean
注解
useStandardWidth
指定对象的 Range 列宽是否等于工作表的标准宽度。 如果对象的Range列宽等于工作表的标准宽度,则返回true。 如果区域包含多个列,并且列的高度并不全部相同,则返回 null 。 否则返回 false 。 注意:此属性仅用于设置为 true。 设置为 false 没有任何效果。
useStandardWidth: boolean;
属性值
boolean
注解
verticalAlignment
表示指定对象的垂直对齐方式。 有关详细信息,请参阅 Excel.VerticalAlignment。
verticalAlignment: Excel.VerticalAlignment | "Top" | "Center" | "Bottom" | "Justify" | "Distributed";
属性值
Excel.VerticalAlignment | "Top" | "Center" | "Bottom" | "Justify" | "Distributed"
注解
wrapText
方法详细信息
adjustIndent(amount)
调整区域格式的缩进。 缩进值的范围是 0 到 250,并且以字符为单位进行度量。
adjustIndent(amount: number): void;
参数
- amount
-
number
用于调整当前缩进的字符空格数。 此值应在 -250 和 250 之间。 注意:如果此数量会将缩进级别提高到 250 以上,则缩进级别将保持为 250。 同样,如果缩进级别低于 0,则缩进级别将保持为 0。
返回
void
注解
autofitColumns()
autofitRows()
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(options?: Excel.Interfaces.RangeFormatLoadOptions): Excel.RangeFormat;
参数
为要加载的对象属性提供选项。
返回
load(propertyNames)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNames?: string | string[]): Excel.RangeFormat;
参数
- propertyNames
-
string | string[]
指定要加载的属性的逗号分隔的字符串或字符串数组。
返回
示例
// Select all of the range's format properties.
await Excel.run(async (context) => {
const sheetName = "Sheet1";
const rangeAddress = "F:G";
const worksheet = context.workbook.worksheets.getItem(sheetName);
const range = worksheet.getRange(rangeAddress);
range.load(["format/*", "format/fill", "format/borders", "format/font"]);
await context.sync();
console.log(range.format.wrapText);
console.log(range.format.fill.color);
console.log(range.format.font.name);
});
load(propertyNamesAndPaths)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Excel.RangeFormat;
参数
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。
返回
set(properties, options)
同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。
set(properties: Interfaces.RangeFormatUpdateData, options?: OfficeExtension.UpdateOptions): void;
参数
- properties
- Excel.Interfaces.RangeFormatUpdateData
一个 JavaScript 对象,其属性与调用该方法的对象的属性同构结构。
- options
- OfficeExtension.UpdateOptions
提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止错误。
返回
void
set(properties)
基于现有加载的对象,同时在对象上设置多个属性。
set(properties: Excel.RangeFormat): void;
参数
- properties
- Excel.RangeFormat
返回
void
toJSON()
覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Excel.RangeFormat 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 Excel.Interfaces.RangeFormatData) ,其中包含从原始对象加载的任何子属性的浅层副本。
toJSON(): Excel.Interfaces.RangeFormatData;