PowerPoint.ShapeFill class
Representa a formatação de preenchimento de um objeto de forma.
- Extends
Comentários
[ Conjunto de API: PowerPointApi 1.4 ]
Exemplos
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
// Changes the transparency of every geometric shape in the slide.
await PowerPoint.run(async (context) => {
// Get the type of shape for every shape in the collection.
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
shapes.load("type");
await context.sync();
// Change the shape transparency to be halfway transparent.
shapes.items.forEach((shape) => {
if (shape.type === PowerPoint.ShapeType.geometricShape) {
shape.fill.transparency = 0.5;
}
});
await context.sync();
});
Propriedades
| context | O contexto do pedido associado ao objeto . Esta ação liga o processo do suplemento ao processo da aplicação anfitriã do Office. |
| foreground |
Representa a cor de primeiro plano do preenchimento da forma no formato de cor HTML, no formulário #RRGGBB (por exemplo, "FFA500") ou como uma cor HTML nomeada (por exemplo, "laranja"). |
| transparency | Especifica a percentagem de transparência do preenchimento como um valor de 0,0 (opaco) a 1,0 (claro). Devolve |
| type | Retorna o tipo de preenchimento da forma. Consulte PowerPoint.ShapeFillType para obter detalhes. |
Métodos
| clear() | Limpa a formatação do preenchimento de um objeto de forma. |
| load(options) | Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar |
| load(property |
Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar |
| load(property |
Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar |
| set |
Define a formatação de preenchimento da forma para uma imagem. Esta ação altera o tipo de preenchimento para |
| set |
Define a formatação de preenchimento de um formato com uma cor uniforme. Esta ação altera o tipo de preenchimento para |
| toJSON() | Substitui o método JavaScript |
Detalhes da propriedade
context
O contexto do pedido associado ao objeto . Esta ação liga o processo do suplemento ao processo da aplicação anfitriã do Office.
context: RequestContext;
Valor da propriedade
foregroundColor
Representa a cor de primeiro plano do preenchimento da forma no formato de cor HTML, no formulário #RRGGBB (por exemplo, "FFA500") ou como uma cor HTML nomeada (por exemplo, "laranja").
foregroundColor: string;
Valor da propriedade
string
Comentários
[ Conjunto de API: PowerPointApi 1.4 ]
Exemplos
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Creates random shapes on the selected slide.
await PowerPoint.run(async (context) => {
let finalTable = "";
const currentSlide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const maxNewShapeWidth = 200;
const maxNewShapeHeight = 200;
const minNewShapeWidth = 50;
const minNewShapeHeight = 50;
for (let i = 0; i < 20; i++) {
const rectangle: PowerPoint.Shape = currentSlide.shapes.addGeometricShape(
PowerPoint.GeometricShapeType.rectangle,
);
rectangle.height = getRandomBetween(minNewShapeWidth, maxNewShapeWidth);
rectangle.width = getRandomBetween(minNewShapeHeight, maxNewShapeHeight);
rectangle.left = getRandomBetween(0, slideWidth - rectangle.width);
rectangle.top = getRandomBetween(0, slideHeight - rectangle.height);
rectangle.fill.foregroundColor = generateRandomHexColor();
}
finalTable += "Done<br>";
const outputSpan = document.getElementById("outputSpan");
outputSpan.innerHTML = "";
outputSpan.innerHTML += finalTable;
});
transparency
Especifica a percentagem de transparência do preenchimento como um valor de 0,0 (opaco) a 1,0 (claro). Devolve null se o tipo de forma não suportar transparência ou se o preenchimento da forma tiver transparência inconsistente, tal como com um tipo de preenchimento com gradação de cor.
transparency: number;
Valor da propriedade
number
Comentários
[ Conjunto de API: PowerPointApi 1.4 ]
Exemplos
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
// Changes the transparency of every geometric shape in the slide.
await PowerPoint.run(async (context) => {
// Get the type of shape for every shape in the collection.
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
shapes.load("type");
await context.sync();
// Change the shape transparency to be halfway transparent.
shapes.items.forEach((shape) => {
if (shape.type === PowerPoint.ShapeType.geometricShape) {
shape.fill.transparency = 0.5;
}
});
await context.sync();
});
type
Retorna o tipo de preenchimento da forma. Consulte PowerPoint.ShapeFillType para obter detalhes.
readonly type: PowerPoint.ShapeFillType | "NoFill" | "Solid" | "Gradient" | "Pattern" | "PictureAndTexture" | "SlideBackground";
Valor da propriedade
PowerPoint.ShapeFillType | "NoFill" | "Solid" | "Gradient" | "Pattern" | "PictureAndTexture" | "SlideBackground"
Comentários
[ Conjunto de API: PowerPointApi 1.4 ]
Exemplos
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Changes the selected shapes fill color to red.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items/fill/type");
await context.sync();
shapes.items.map((shape) => {
const shapeFillType = shape.fill.type as PowerPoint.ShapeFillType;
console.log(`Shape ID ${shape.id} original fill type: ${shapeFillType}`);
shape.fill.setSolidColor("red");
});
await context.sync();
});
Detalhes do método
clear()
Limpa a formatação do preenchimento de um objeto de forma.
clear(): void;
Retornos
void
Comentários
load(options)
Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.
load(options?: PowerPoint.Interfaces.ShapeFillLoadOptions): PowerPoint.ShapeFill;
Parâmetros
Fornece opções para as propriedades do objeto a carregar.
Retornos
load(propertyNames)
Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.
load(propertyNames?: string | string[]): PowerPoint.ShapeFill;
Parâmetros
- propertyNames
-
string | string[]
Uma cadeia delimitada por vírgulas ou uma matriz de cadeias que especificam as propriedades a carregar.
Retornos
load(propertyNamesAndPaths)
Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): PowerPoint.ShapeFill;
Parâmetros
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select é uma cadeia delimitada por vírgulas que especifica as propriedades a carregar e propertyNamesAndPaths.expand é uma cadeia delimitada por vírgulas que especifica as propriedades de navegação a carregar.
Retornos
setImage(base64EncodedImage)
Define a formatação de preenchimento da forma para uma imagem. Esta ação altera o tipo de preenchimento para PictureAndTexture.
setImage(base64EncodedImage: string): void;
Parâmetros
- base64EncodedImage
-
string
Uma cadeia que é uma codificação Base64 dos dados da imagem.
Retornos
void
Comentários
[ Conjunto de API: PowerPointApi 1.8 ]
Exemplos
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
// Inserts an image with binding.
await PowerPoint.run(async (context) => {
const bindingId = (document.getElementById("temp-binding-id") as HTMLInputElement).value;
const slide = context.presentation.getSelectedSlides().getItemAt(0);
const myShape = slide.shapes.addGeometricShape(PowerPoint.GeometricShapeType.rectangle, {
top: 100,
left: 30,
width: 200,
height: 200
});
myShape.fill.setImage(flowerImage);
context.presentation.bindings.add(myShape, PowerPoint.BindingType.shape, bindingId);
await context.sync();
const bindingsDropdown = document.getElementById("bindings-dropdown") as HTMLSelectElement;
const option = new Option(`Binding ${bindingId}`, bindingId);
// When a binding ID already exists, the binding is updated to refer to the new shape
// so select the existing item rather than add a new one.
const foundIndex = findDropdownItem(bindingsDropdown, option.text);
if (foundIndex < 0) {
bindingsDropdown.add(option);
bindingsDropdown.selectedIndex = bindingsDropdown.options.length - 1;
} else {
bindingsDropdown.selectedIndex = foundIndex;
}
});
setSolidColor(color)
Define a formatação de preenchimento de um formato com uma cor uniforme. Esta ação altera o tipo de preenchimento para Solid.
setSolidColor(color: string): void;
Parâmetros
- color
-
string
Uma cadeia que especifica a cor de preenchimento no formato de cor HTML, no formulário #RRGGBB (por exemplo, "FFA500") ou como uma cor HTML nomeada (por exemplo, "laranja").
Retornos
void
Comentários
[ Conjunto de API: PowerPointApi 1.4 ]
Exemplos
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Changes the selected shapes fill color to red.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items/fill/type");
await context.sync();
shapes.items.map((shape) => {
const shapeFillType = shape.fill.type as PowerPoint.ShapeFillType;
console.log(`Shape ID ${shape.id} original fill type: ${shapeFillType}`);
shape.fill.setSolidColor("red");
});
await context.sync();
});
toJSON()
Substitui o método JavaScript toJSON() para fornecer uma saída mais útil quando um objeto de API é transmitido para JSON.stringify(). (JSON.stringifypor sua vez, chama o toJSON método do objeto que lhe é transmitido.) Enquanto o objeto original PowerPoint.ShapeFill é um objeto de API, o toJSON método devolve um objeto JavaScript simples (escrito como PowerPoint.Interfaces.ShapeFillData) que contém cópias rasas de quaisquer propriedades subordinadas carregadas do objeto original.
toJSON(): PowerPoint.Interfaces.ShapeFillData;