跳到主要内容

CreateShape

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

语法

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

expression - 表示 Api 类的变量。

参数

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

返回值

ApiShape

示例

如何添加新的流程图形状。

// Add a new shape indicating its properties.

const doc = Api.GetDocument();
const page = doc.GetPage(0);

const fill = Api.CreateSolidFill(Api.CreateRGBColor(255, 111, 61));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("flowChartMagneticTape", 150 * 36000, 65 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);
const docContent = shape.GetContent();
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);
page.AddObject(shape);