Excel.Image class

表示工作表中的图像。 若要获取相应的 Shape 对象,请使用 Image.shape

扩展

注解

[ API 集:ExcelApi 1.9 ]

属性

brightness

指定图像的亮度。 此属性的值必须是介于 0.0 (最暗) 到 1.0 (最亮)。

colorType

指定应用于图像的颜色转换的类型。

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

contrast

指定图像的对比度。 此属性的值必须是数字从 0.0 (最小的对比度) 到 1.0 (最大对比度)。

cropBottom

指定从图像底部裁剪的点数。

cropLeft

指定从图像左侧裁剪的点数。

cropRight

指定从图像右侧裁剪的点数。

cropTop

指定从图像顶部裁剪的点数。

format

返回图像的格式。

id

指定图像对象的形状标识符。

shape

返回与 Shape 图像关联的 对象。

方法

incrementBrightness(increment)

按指定量递增图像的亮度。

incrementContrast(increment)

按指定量递增图像的对比度。

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。

set(properties)

基于现有的已加载对象,同时对对象设置多个属性。

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,依次调用toJSON传递给它的 对象的 方法。) 虽然原始Excel.Image对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.ImageData) ,其中包含从原始对象加载的任何子属性的浅表副本。

属性详细信息

brightness

指定图像的亮度。 此属性的值必须是介于 0.0 (最暗) 到 1.0 (最亮)。

brightness: number;

属性值

number

注解

[ API 集:ExcelApiDesktop 1.1 ]

colorType

指定应用于图像的颜色转换的类型。

colorType: Excel.PictureColorType | "Mixed" | "Automatic" | "GrayScale" | "BlackAndWhite" | "Watermark";

属性值

Excel.PictureColorType | "Mixed" | "Automatic" | "GrayScale" | "BlackAndWhite" | "Watermark"

注解

[ API 集:ExcelApiDesktop 1.1 ]

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

contrast

指定图像的对比度。 此属性的值必须是数字从 0.0 (最小的对比度) 到 1.0 (最大对比度)。

contrast: number;

属性值

number

注解

[ API 集:ExcelApiDesktop 1.1 ]

cropBottom

指定从图像底部裁剪的点数。

cropBottom: number;

属性值

number

注解

[ API 集:ExcelApiDesktop 1.1 ]

cropLeft

指定从图像左侧裁剪的点数。

cropLeft: number;

属性值

number

注解

[ API 集:ExcelApiDesktop 1.1 ]

cropRight

指定从图像右侧裁剪的点数。

cropRight: number;

属性值

number

注解

[ API 集:ExcelApiDesktop 1.1 ]

cropTop

指定从图像顶部裁剪的点数。

cropTop: number;

属性值

number

注解

[ API 集:ExcelApiDesktop 1.1 ]

format

返回图像的格式。

readonly format: Excel.PictureFormat | "UNKNOWN" | "BMP" | "JPEG" | "GIF" | "PNG" | "SVG";

属性值

Excel.PictureFormat | "UNKNOWN" | "BMP" | "JPEG" | "GIF" | "PNG" | "SVG"

注解

[ API 集:ExcelApi 1.9 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/44-shape/shape-images.yaml

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Shapes");
    const image = sheet.shapes.getItem("Image").image;
    image.load("format");
    await context.sync();

    console.log("The image's format is: " + image.format);
    await context.sync();
});

id

指定图像对象的形状标识符。

readonly id: string;

属性值

string

注解

[ API 集:ExcelApi 1.9 ]

shape

返回与 Shape 图像关联的 对象。

readonly shape: Excel.Shape;

属性值

注解

[ API 集:ExcelApi 1.9 ]

方法详细信息

incrementBrightness(increment)

按指定量递增图像的亮度。

incrementBrightness(increment: number): void;

参数

increment

number

指定量更改图片的 亮度 属性的值。 正值使图片更亮;使用负值可使图片变暗。

返回

void

注解

[ API 集:ExcelApiDesktop 1.1 ]

incrementContrast(increment)

按指定量递增图像的对比度。

incrementContrast(increment: number): void;

参数

increment

number

指定量更改图片的 对比度 属性的值。 正值会增加对比度。

返回

void

注解

[ API 集:ExcelApiDesktop 1.1 ]

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: Excel.Interfaces.ImageLoadOptions): Excel.Image;

参数

options
Excel.Interfaces.ImageLoadOptions

提供要加载对象的属性的选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames?: string | string[]): Excel.Image;

参数

propertyNames

string | string[]

逗号分隔的字符串或指定要加载的属性的字符串数组。

返回

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.Image;

参数

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。

返回

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。

set(properties: Interfaces.ImageUpdateData, options?: OfficeExtension.UpdateOptions): void;

参数

properties
Excel.Interfaces.ImageUpdateData

一个 JavaScript 对象,其属性按同构方式构造为调用方法的对象的属性。

options
OfficeExtension.UpdateOptions

提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止显示错误。

返回

void

set(properties)

基于现有的已加载对象,同时对对象设置多个属性。

set(properties: Excel.Image): void;

参数

properties
Excel.Image

返回

void

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,依次调用toJSON传递给它的 对象的 方法。) 虽然原始Excel.Image对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.ImageData) ,其中包含从原始对象加载的任何子属性的浅表副本。

toJSON(): Excel.Interfaces.ImageData;

返回