跳到主要内容

CreateShape

使用指定的参数创建形状。

语法

expression.CreateShape(sType, nWidth, nHeight, oFill, oStroke);

expression - 表示 Api 类的变量。

参数

名称必需/可选数据类型默认值描述
sType可选ShapeType"rect"指定预设形状几何图形的形状类型。
nWidth可选EMU914400以英制度量单位表示的形状宽度。
nHeight可选EMU914400以英制度量单位表示的形状高度。
oFill可选ApiFillApi.CreateNoFill()用于填充形状的颜色或图案。
oStroke可选ApiStrokeApi.CreateStroke(0, Api.CreateNoFill())用于创建元素阴影的笔触。

返回值

ApiShape

示例

此示例使用 'flowChartMagneticTape' 预设创建形状。

// How to add a new flowchart shape.

// Add a new shape indicating its properties.

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("flowChartMagneticTape", 300 * 36000, 130 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);
const docContent = shape.GetDocContent();
const paragraph = docContent.GetElement(0);

let run = Api.CreateRun();
run.SetFontSize(60);
run.AddText("This is just a sample text. ");
paragraph.AddElement(run);

run = Api.CreateRun();
run.SetFontSize(60);
run.SetFontFamily("Comic Sans MS");
run.AddText("This is a text run with the font family set to 'Comic Sans MS'.");
paragraph.AddElement(run);
slide.AddObject(shape);