PowerPoint.SlideBackgroundFill class
Represents the fill formatting of a slide background object.
- Extends
Remarks
[ API set: PowerPointApi 1.10 ]
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-background-fill.yaml
// Gets the background fill type of the first selected slide.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const fill: PowerPoint.SlideBackgroundFill = slide.background.fill;
fill.load("type");
await context.sync();
const fillType = fill.type as PowerPoint.SlideBackgroundFillType;
console.log(`Background fill type: ${fillType}`);
});
Properties
| context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
| type | Returns the fill type of the slide background. See PowerPoint.SlideBackgroundFillType for details. |
Methods
| get |
Gets the gradient fill properties. If the fill type is not |
| get |
Gets the pattern fill properties. If the fill type is not |
| get |
Gets the picture or texture fill properties. If the fill type is not |
| get |
Gets the solid fill properties. If the fill type is not |
| load(options) | Queues up a command to load the specified properties of the object. You must call |
| load(property |
Queues up a command to load the specified properties of the object. You must call |
| load(property |
Queues up a command to load the specified properties of the object. You must call |
| set |
Sets the fill formatting of the slide background to a gradient fill. This changes the fill type to |
| set |
Sets the fill formatting of the slide background to a pattern fill. This changes the fill type to |
| set |
Sets the fill formatting of the slide background to a picture or texture fill. This changes the fill type to |
| set |
Sets the fill formatting of the slide background to a solid fill. This changes the fill type to |
| toJSON() | Overrides the JavaScript |
Property Details
context
The request context associated with the object. This connects the add-in's process to the Office host application's process.
context: RequestContext;
Property Value
type
Returns the fill type of the slide background. See PowerPoint.SlideBackgroundFillType for details.
readonly type: PowerPoint.SlideBackgroundFillType | "Unsupported" | "Solid" | "Gradient" | "PictureOrTexture" | "Pattern";
Property Value
PowerPoint.SlideBackgroundFillType | "Unsupported" | "Solid" | "Gradient" | "PictureOrTexture" | "Pattern"
Remarks
Method Details
getGradientFillOrNullObject()
Gets the gradient fill properties. If the fill type is not gradient, an object with an isNullObject property set to true is returned. For further information, see *OrNullObject methods and properties.
getGradientFillOrNullObject(): PowerPoint.SlideBackgroundGradientFill;
Returns
Remarks
[ API set: PowerPointApi 1.10 ]
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-background-fill.yaml
// Gets the gradient fill properties of the first selected slide's background.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const fill: PowerPoint.SlideBackgroundFill = slide.background.fill;
fill.load("type");
await context.sync();
if (fill.type !== PowerPoint.SlideBackgroundFillType.gradient) {
console.warn("The slide background isn't a gradient fill.");
return;
}
const gradientFill: PowerPoint.SlideBackgroundGradientFill = slide.background.fill.getGradientFillOrNullObject();
gradientFill.load("type");
await context.sync();
if (gradientFill.isNullObject) {
console.warn("The slide background isn't a gradient fill.");
} else {
console.log("Gradient fill:", `- type: ${gradientFill.type}`);
}
});
getPatternFillOrNullObject()
Gets the pattern fill properties. If the fill type is not pattern, an object with an isNullObject property set to true is returned. For further information, see *OrNullObject methods and properties.
getPatternFillOrNullObject(): PowerPoint.SlideBackgroundPatternFill;
Returns
Remarks
[ API set: PowerPointApi 1.10 ]
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-background-fill.yaml
// Gets the pattern fill properties of the first selected slide's background.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const fill: PowerPoint.SlideBackgroundFill = slide.background.fill;
fill.load("type");
await context.sync();
if (fill.type !== PowerPoint.SlideBackgroundFillType.pattern) {
console.warn("The slide background isn't a pattern fill.");
return;
}
const patternFill: PowerPoint.SlideBackgroundPatternFill = slide.background.fill.getPatternFillOrNullObject();
patternFill.load(["foregroundColor", "backgroundColor", "pattern"]);
await context.sync();
if (patternFill.isNullObject) {
console.warn("The slide background isn't a pattern fill.");
} else {
console.log(
"Pattern fill:",
`- foregroundColor: ${patternFill.foregroundColor}`,
`- backgroundColor: ${patternFill.backgroundColor}`,
`- pattern: ${patternFill.pattern}`,
);
}
});
getPictureOrTextureFillOrNullObject()
Gets the picture or texture fill properties. If the fill type is not pictureOrTexture, an object with an isNullObject property set to true is returned. For further information, see *OrNullObject methods and properties.
getPictureOrTextureFillOrNullObject(): PowerPoint.SlideBackgroundPictureOrTextureFill;
Returns
Remarks
[ API set: PowerPointApi 1.10 ]
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-background-fill.yaml
// Gets the picture or texture fill properties of the first selected slide's background.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const fill: PowerPoint.SlideBackgroundFill = slide.background.fill;
fill.load("type");
await context.sync();
if (fill.type !== PowerPoint.SlideBackgroundFillType.pictureOrTexture) {
console.warn("The slide background isn't a picture or texture fill.");
return;
}
const pictureFill: PowerPoint.SlideBackgroundPictureOrTextureFill =
slide.background.fill.getPictureOrTextureFillOrNullObject();
pictureFill.load("transparency");
await context.sync();
if (pictureFill.isNullObject) {
console.warn("The slide background isn't a picture or texture fill.");
} else {
console.log("Picture or texture fill:", `- transparency: ${pictureFill.transparency}`);
}
});
getSolidFillOrNullObject()
Gets the solid fill properties. If the fill type is not solid, an object with an isNullObject property set to true is returned. For further information, see *OrNullObject methods and properties.
getSolidFillOrNullObject(): PowerPoint.SlideBackgroundSolidFill;
Returns
Remarks
[ API set: PowerPointApi 1.10 ]
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-background-fill.yaml
// Gets the solid fill properties of the first selected slide's background.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const fill: PowerPoint.SlideBackgroundFill = slide.background.fill;
fill.load("type");
await context.sync();
if (fill.type !== PowerPoint.SlideBackgroundFillType.solid) {
console.warn("The slide background isn't a solid fill.");
return;
}
const solidFill: PowerPoint.SlideBackgroundSolidFill = slide.background.fill.getSolidFillOrNullObject();
solidFill.load(["color", "transparency"]);
await context.sync();
if (solidFill.isNullObject) {
console.warn("The slide background isn't a solid fill.");
} else {
console.log("Solid fill:", `- color: ${solidFill.color}`, `- transparency: ${solidFill.transparency}`);
}
});
load(options)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(options?: PowerPoint.Interfaces.SlideBackgroundFillLoadOptions): PowerPoint.SlideBackgroundFill;
Parameters
Provides options for which properties of the object to load.
Returns
load(propertyNames)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(propertyNames?: string | string[]): PowerPoint.SlideBackgroundFill;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
load(propertyNamesAndPaths)
Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): PowerPoint.SlideBackgroundFill;
Parameters
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.
Returns
setGradientFill(options)
Sets the fill formatting of the slide background to a gradient fill. This changes the fill type to gradient.
setGradientFill(options?: PowerPoint.SlideBackgroundGradientFillOptions): void;
Parameters
Options for the gradient fill.
Returns
void
Remarks
[ API set: PowerPointApi 1.10 ]
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-background-fill.yaml
// Sets the background of the first selected slide to a linear gradient fill.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
slide.background.fill.setGradientFill({
type: PowerPoint.SlideBackgroundGradientFillType.linear,
} as PowerPoint.SlideBackgroundGradientFillOptions);
await context.sync();
console.log("Background set to linear gradient fill.");
});
setPatternFill(options)
Sets the fill formatting of the slide background to a pattern fill. This changes the fill type to pattern.
setPatternFill(options?: PowerPoint.SlideBackgroundPatternFillOptions): void;
Parameters
Options for the pattern fill.
Returns
void
Remarks
[ API set: PowerPointApi 1.10 ]
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-background-fill.yaml
// Sets the background of the first selected slide to a diagonal cross pattern fill.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
slide.background.fill.setPatternFill({
foregroundColor: "#1F3864",
backgroundColor: "#D6E4F7",
pattern: PowerPoint.SlideBackgroundPatternFillType.diagonalCross,
} as PowerPoint.SlideBackgroundPatternFillOptions);
await context.sync();
console.log("Background set to diagonal cross pattern fill.");
});
setPictureOrTextureFill(options)
Sets the fill formatting of the slide background to a picture or texture fill. This changes the fill type to pictureOrTexture.
setPictureOrTextureFill(options?: PowerPoint.SlideBackgroundPictureOrTextureFillOptions): void;
Parameters
Options for the picture or texture fill.
Returns
void
Remarks
[ API set: PowerPointApi 1.10 ]
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-background-fill.yaml
// Sets the background of the first selected slide to a picture fill at 60% transparency.
// Uses a sample image from a Base64-encoded string.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
slide.background.fill.setPictureOrTextureFill({
imageBase64: getSampleImageAsBase64String(),
transparency: 0.6,
} as PowerPoint.SlideBackgroundPictureOrTextureFillOptions);
await context.sync();
console.log("Background set to picture fill (60% transparent).");
});
setSolidFill(options)
Sets the fill formatting of the slide background to a solid fill. This changes the fill type to solid.
setSolidFill(options?: PowerPoint.SlideBackgroundSolidFillOptions): void;
Parameters
Options for the solid fill.
Returns
void
Remarks
[ API set: PowerPointApi 1.10 ]
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-background-fill.yaml
// Sets the background of the first selected slide to a solid orange fill at 20% transparency.
await PowerPoint.run(async (context) => {
const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
slide.background.fill.setSolidFill({
color: "#FF8C00",
transparency: 0.2,
} as PowerPoint.SlideBackgroundSolidFillOptions);
await context.sync();
console.log("Background set to solid orange fill (20% transparent).");
});
toJSON()
Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original PowerPoint.SlideBackgroundFill object is an API object, the toJSON method returns a plain JavaScript object (typed as PowerPoint.Interfaces.SlideBackgroundFillData) that contains shallow copies of any loaded child properties from the original object.
toJSON(): PowerPoint.Interfaces.SlideBackgroundFillData;