Excel.ShapeCollection class

ワークシート内のすべての図形のコレクションを表します。

Extends

注釈

[ API セット: ExcelApi 1.9 ]

プロパティ

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

items

このコレクション内に読み込まれた子アイテムを取得します。

メソッド

addGeometricShape(geometricShapeType)

幾何学的図形をワークシートに追加します。 新しい図形を Shape 表す オブジェクトを返します。

addGeometricShape(geometricShapeTypeString)

幾何学的図形をワークシートに追加します。 新しい図形を Shape 表す オブジェクトを返します。

addGroup(values)

このコレクションのワークシート内の図形のサブセットをグループ化します。 図形の Shape 新しいグループを表す オブジェクトを返します。

addImage(base64ImageString)

base64 エンコード文字列から画像を作成し、それをワークシートに追加します。 新しいイメージを Shape 表す オブジェクトを返します。

addLine(startLeft, startTop, endLeft, endTop, connectorType)

ワークシートに行を追加します。 新しい行を Shape 表す オブジェクトを返します。

addLine(startLeft, startTop, endLeft, endTop, connectorTypeString)

ワークシートに行を追加します。 新しい行を Shape 表す オブジェクトを返します。

addSvg(xml)

XML 文字列からスケーラブルなベクター グラフィックス (SVG) を作成し、それをワークシートに追加します。 新しいイメージを Shape 表す オブジェクトを返します。

addTextBox(text)

指定されたテキストを含むテキスト ボックスをワークシートに追加します。 新しいテキスト ボックスを Shape 表す オブジェクトを返します。

getCount()

ワークシートの図形数を返します。

getItem(key)

名前または ID を使用して図形を取得します。

getItemAt(index)

コレクション内の位置を使用して図形を取得します。

getItemOrNullObject(key)

名前または ID を使用して図形を取得します。 shape オブジェクトが存在しない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出 toJSON します)。元 Excel.ShapeCollection のオブジェクトは API オブジェクトですが、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト (として Excel.Interfaces.ShapeCollectionData型指定) を返します。

プロパティの詳細

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

items

このコレクション内に読み込まれた子アイテムを取得します。

readonly items: Excel.Shape[];

プロパティ値

メソッドの詳細

addGeometricShape(geometricShapeType)

幾何学的図形をワークシートに追加します。 新しい図形を Shape 表す オブジェクトを返します。

addGeometricShape(geometricShapeType: Excel.GeometricShapeType): Excel.Shape;

パラメーター

geometricShapeType
Excel.GeometricShapeType

ジオメトリ シェイプの種類を表します。 詳細は「Excel.GeometricShapeType」をご覧ください。

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

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

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Shapes");
    const shape = sheet.shapes.addGeometricShape(Excel.GeometricShapeType.hexagon);
    shape.left = 5;
    shape.top = 5;
    shape.height = 175;
    shape.width = 200;
    await context.sync();
});

addGeometricShape(geometricShapeTypeString)

幾何学的図形をワークシートに追加します。 新しい図形を Shape 表す オブジェクトを返します。

addGeometricShape(geometricShapeTypeString: "LineInverse" | "Triangle" | "RightTriangle" | "Rectangle" | "Diamond" | "Parallelogram" | "Trapezoid" | "NonIsoscelesTrapezoid" | "Pentagon" | "Hexagon" | "Heptagon" | "Octagon" | "Decagon" | "Dodecagon" | "Star4" | "Star5" | "Star6" | "Star7" | "Star8" | "Star10" | "Star12" | "Star16" | "Star24" | "Star32" | "RoundRectangle" | "Round1Rectangle" | "Round2SameRectangle" | "Round2DiagonalRectangle" | "SnipRoundRectangle" | "Snip1Rectangle" | "Snip2SameRectangle" | "Snip2DiagonalRectangle" | "Plaque" | "Ellipse" | "Teardrop" | "HomePlate" | "Chevron" | "PieWedge" | "Pie" | "BlockArc" | "Donut" | "NoSmoking" | "RightArrow" | "LeftArrow" | "UpArrow" | "DownArrow" | "StripedRightArrow" | "NotchedRightArrow" | "BentUpArrow" | "LeftRightArrow" | "UpDownArrow" | "LeftUpArrow" | "LeftRightUpArrow" | "QuadArrow" | "LeftArrowCallout" | "RightArrowCallout" | "UpArrowCallout" | "DownArrowCallout" | "LeftRightArrowCallout" | "UpDownArrowCallout" | "QuadArrowCallout" | "BentArrow" | "UturnArrow" | "CircularArrow" | "LeftCircularArrow" | "LeftRightCircularArrow" | "CurvedRightArrow" | "CurvedLeftArrow" | "CurvedUpArrow" | "CurvedDownArrow" | "SwooshArrow" | "Cube" | "Can" | "LightningBolt" | "Heart" | "Sun" | "Moon" | "SmileyFace" | "IrregularSeal1" | "IrregularSeal2" | "FoldedCorner" | "Bevel" | "Frame" | "HalfFrame" | "Corner" | "DiagonalStripe" | "Chord" | "Arc" | "LeftBracket" | "RightBracket" | "LeftBrace" | "RightBrace" | "BracketPair" | "BracePair" | "Callout1" | "Callout2" | "Callout3" | "AccentCallout1" | "AccentCallout2" | "AccentCallout3" | "BorderCallout1" | "BorderCallout2" | "BorderCallout3" | "AccentBorderCallout1" | "AccentBorderCallout2" | "AccentBorderCallout3" | "WedgeRectCallout" | "WedgeRRectCallout" | "WedgeEllipseCallout" | "CloudCallout" | "Cloud" | "Ribbon" | "Ribbon2" | "EllipseRibbon" | "EllipseRibbon2" | "LeftRightRibbon" | "VerticalScroll" | "HorizontalScroll" | "Wave" | "DoubleWave" | "Plus" | "FlowChartProcess" | "FlowChartDecision" | "FlowChartInputOutput" | "FlowChartPredefinedProcess" | "FlowChartInternalStorage" | "FlowChartDocument" | "FlowChartMultidocument" | "FlowChartTerminator" | "FlowChartPreparation" | "FlowChartManualInput" | "FlowChartManualOperation" | "FlowChartConnector" | "FlowChartPunchedCard" | "FlowChartPunchedTape" | "FlowChartSummingJunction" | "FlowChartOr" | "FlowChartCollate" | "FlowChartSort" | "FlowChartExtract" | "FlowChartMerge" | "FlowChartOfflineStorage" | "FlowChartOnlineStorage" | "FlowChartMagneticTape" | "FlowChartMagneticDisk" | "FlowChartMagneticDrum" | "FlowChartDisplay" | "FlowChartDelay" | "FlowChartAlternateProcess" | "FlowChartOffpageConnector" | "ActionButtonBlank" | "ActionButtonHome" | "ActionButtonHelp" | "ActionButtonInformation" | "ActionButtonForwardNext" | "ActionButtonBackPrevious" | "ActionButtonEnd" | "ActionButtonBeginning" | "ActionButtonReturn" | "ActionButtonDocument" | "ActionButtonSound" | "ActionButtonMovie" | "Gear6" | "Gear9" | "Funnel" | "MathPlus" | "MathMinus" | "MathMultiply" | "MathDivide" | "MathEqual" | "MathNotEqual" | "CornerTabs" | "SquareTabs" | "PlaqueTabs" | "ChartX" | "ChartStar" | "ChartPlus"): Excel.Shape;

パラメーター

geometricShapeTypeString

"LineInverse" | "Triangle" | "RightTriangle" | "Rectangle" | "Diamond" | "Parallelogram" | "Trapezoid" | "NonIsoscelesTrapezoid" | "Pentagon" | "Hexagon" | "Heptagon" | "Octagon" | "Decagon" | "Dodecagon" | "Star4" | "Star5" | "Star6" | "Star7" | "Star8" | "Star10" | "Star12" | "Star16" | "Star24" | "Star32" | "RoundRectangle" | "Round1Rectangle" | "Round2SameRectangle" | "Round2DiagonalRectangle" | "SnipRoundRectangle" | "Snip1Rectangle" | "Snip2SameRectangle" | "Snip2DiagonalRectangle" | "Plaque" | "Ellipse" | "Teardrop" | "HomePlate" | "Chevron" | "PieWedge" | "Pie" | "BlockArc" | "Donut" | "NoSmoking" | "RightArrow" | "LeftArrow" | "UpArrow" | "DownArrow" | "StripedRightArrow" | "NotchedRightArrow" | "BentUpArrow" | "LeftRightArrow" | "UpDownArrow" | "LeftUpArrow" | "LeftRightUpArrow" | "QuadArrow" | "LeftArrowCallout" | "RightArrowCallout" | "UpArrowCallout" | "DownArrowCallout" | "LeftRightArrowCallout" | "UpDownArrowCallout" | "QuadArrowCallout" | "BentArrow" | "UturnArrow" | "CircularArrow" | "LeftCircularArrow" | "LeftRightCircularArrow" | "CurvedRightArrow" | "CurvedLeftArrow" | "CurvedUpArrow" | "CurvedDownArrow" | "SwooshArrow" | "Cube" | "Can" | "LightningBolt" | "Heart" | "Sun" | "Moon" | "SmileyFace" | "IrregularSeal1" | "IrregularSeal2" | "FoldedCorner" | "Bevel" | "Frame" | "HalfFrame" | "Corner" | "DiagonalStripe" | "Chord" | "Arc" | "LeftBracket" | "RightBracket" | "LeftBrace" | "RightBrace" | "BracketPair" | "BracePair" | "Callout1" | "Callout2" | "Callout3" | "AccentCallout1" | "AccentCallout2" | "AccentCallout3" | "BorderCallout1" | "BorderCallout2" | "BorderCallout3" | "AccentBorderCallout1" | "AccentBorderCallout2" | "AccentBorderCallout3" | "WedgeRectCallout" | "WedgeRRectCallout" | "WedgeEllipseCallout" | "CloudCallout" | "Cloud" | "Ribbon" | "Ribbon2" | "EllipseRibbon" | "EllipseRibbon2" | "LeftRightRibbon" | "VerticalScroll" | "HorizontalScroll" | "Wave" | "DoubleWave" | "Plus" | "FlowChartProcess" | "FlowChartDecision" | "FlowChartInputOutput" | "FlowChartPredefinedProcess" | "FlowChartInternalStorage" | "FlowChartDocument" | "FlowChartMultidocument" | "FlowChartTerminator" | "FlowChartPreparation" | "FlowChartManualInput" | "FlowChartManualOperation" | "FlowChartConnector" | "FlowChartPunchedCard" | "FlowChartPunchedTape" | "FlowChartSummingJunction" | "FlowChartOr" | "FlowChartCollate" | "FlowChartSort" | "FlowChartExtract" | "FlowChartMerge" | "FlowChartOfflineStorage" | "FlowChartOnlineStorage" | "FlowChartMagneticTape" | "FlowChartMagneticDisk" | "FlowChartMagneticDrum" | "FlowChartDisplay" | "FlowChartDelay" | "FlowChartAlternateProcess" | "FlowChartOffpageConnector" | "ActionButtonBlank" | "ActionButtonHome" | "ActionButtonHelp" | "ActionButtonInformation" | "ActionButtonForwardNext" | "ActionButtonBackPrevious" | "ActionButtonEnd" | "ActionButtonBeginning" | "ActionButtonReturn" | "ActionButtonDocument" | "ActionButtonSound" | "ActionButtonMovie" | "Gear6" | "Gear9" | "Funnel" | "MathPlus" | "MathMinus" | "MathMultiply" | "MathDivide" | "MathEqual" | "MathNotEqual" | "CornerTabs" | "SquareTabs" | "PlaqueTabs" | "ChartX" | "ChartStar" | "ChartPlus"

ジオメトリ シェイプの種類を表します。 詳細は「Excel.GeometricShapeType」をご覧ください。

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

addGroup(values)

このコレクションのワークシート内の図形のサブセットをグループ化します。 図形の Shape 新しいグループを表す オブジェクトを返します。

addGroup(values: Array<string | Shape>): Excel.Shape;

パラメーター

values

Array<string | Excel.Shape>

図形 ID または図形オブジェクトの配列。

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

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

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Shapes");
    const square = sheet.shapes.getItem("Square");
    const pentagon = sheet.shapes.getItem("Pentagon");
    const octagon = sheet.shapes.getItem("Octagon");

    const shapeGroup = sheet.shapes.addGroup([square, pentagon, octagon]);
    shapeGroup.name = "Group";
    console.log("Shapes grouped");

    await context.sync();
});

addImage(base64ImageString)

base64 エンコード文字列から画像を作成し、それをワークシートに追加します。 新しいイメージを Shape 表す オブジェクトを返します。

addImage(base64ImageString: string): Excel.Shape;

パラメーター

base64ImageString

string

JPEG または PNG 形式の画像を表す base64 でエンコードされた文字列。

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

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

const myFile = <HTMLInputElement>document.getElementById("selectedFile");
const reader = new FileReader();

reader.onload = (event) => {
    Excel.run((context) => {
        const startIndex = reader.result.toString().indexOf("base64,");
        const myBase64 = reader.result.toString().substr(startIndex + 7);
        const sheet = context.workbook.worksheets.getItem("Shapes");
        const image = sheet.shapes.addImage(myBase64);
        image.name = "Image";
        return context.sync();
    });
};

// Read in the image file as a data URL.
reader.readAsDataURL(myFile.files[0]);

addLine(startLeft, startTop, endLeft, endTop, connectorType)

ワークシートに行を追加します。 新しい行を Shape 表す オブジェクトを返します。

addLine(startLeft: number, startTop: number, endLeft: number, endTop: number, connectorType?: Excel.ConnectorType): Excel.Shape;

パラメーター

startLeft

number

線の始点からワークシートの左側までの距離をポイント単位で指定します。

startTop

number

線の始点からワークシートの上部までの距離をポイント単位で指定します。

endLeft

number

行の末尾からワークシートの左側までの距離をポイント単位で指定します。

endTop

number

線の終点からワークシートの上端までの距離をポイント単位で指定します。

connectorType
Excel.ConnectorType

コネクタの種類を表します。 詳細は「Excel.ConnectorType」をご覧ください。

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

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

await Excel.run(async (context) => {
    const shapes = context.workbook.worksheets.getItem("Shapes").shapes;
    const line = shapes.addLine(200, 50, 300, 150, Excel.ConnectorType.straight);
    line.name = "StraightLine";
    await context.sync();
});

addLine(startLeft, startTop, endLeft, endTop, connectorTypeString)

ワークシートに行を追加します。 新しい行を Shape 表す オブジェクトを返します。

addLine(startLeft: number, startTop: number, endLeft: number, endTop: number, connectorTypeString?: "Straight" | "Elbow" | "Curve"): Excel.Shape;

パラメーター

startLeft

number

線の始点からワークシートの左側までの距離をポイント単位で指定します。

startTop

number

線の始点からワークシートの上部までの距離をポイント単位で指定します。

endLeft

number

行の末尾からワークシートの左側までの距離をポイント単位で指定します。

endTop

number

線の終点からワークシートの上端までの距離をポイント単位で指定します。

connectorTypeString

"Straight" | "Elbow" | "Curve"

コネクタの種類を表します。 詳細は「Excel.ConnectorType」をご覧ください。

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

addSvg(xml)

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

XML 文字列からスケーラブルなベクター グラフィックス (SVG) を作成し、それをワークシートに追加します。 新しいイメージを Shape 表す オブジェクトを返します。

addSvg(xml: string): Excel.Shape;

パラメーター

xml

string

SVG を表す XML 文字列。

戻り値

注釈

[ API セット: ExcelApi BETA (プレビューのみ) ]

addTextBox(text)

指定されたテキストを含むテキスト ボックスをワークシートに追加します。 新しいテキスト ボックスを Shape 表す オブジェクトを返します。

addTextBox(text?: string): Excel.Shape;

パラメーター

text

string

作成したテキスト ボックスに表示されるテキストを表します。

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

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

await Excel.run(async (context) => {
    const shapes = context.workbook.worksheets.getItem("Shapes").shapes;
    const textbox = shapes.addTextBox("A box with text");
    textbox.left = 100;
    textbox.top = 100;
    textbox.height = 20;
    textbox.width = 175;
    textbox.name = "Textbox";
    await context.sync();
});

getCount()

ワークシートの図形数を返します。

getCount(): OfficeExtension.ClientResult<number>;

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

getItem(key)

名前または ID を使用して図形を取得します。

getItem(key: string): Excel.Shape;

パラメーター

key

string

取得する図形の名前または ID。

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

getItemAt(index)

コレクション内の位置を使用して図形を取得します。

getItemAt(index: number): Excel.Shape;

パラメーター

index

number

取得する図形の 0 から始まるインデックス。

戻り値

注釈

[ API セット: ExcelApi 1.9 ]

getItemOrNullObject(key)

名前または ID を使用して図形を取得します。 shape オブジェクトが存在しない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getItemOrNullObject(key: string): Excel.Shape;

パラメーター

key

string

取得する図形の名前または ID。

戻り値

注釈

[ API セット: ExcelApi 1.14 ]

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(options?: Excel.Interfaces.ShapeCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.ShapeCollection;

パラメーター

options

Excel.Interfaces.ShapeCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions

読み込むオブジェクトのプロパティのオプションを提供します。

戻り値

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

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

パラメーター

propertyNames

string | string[]

読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。

戻り値

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Excel.ShapeCollection;

パラメーター

propertyNamesAndPaths
OfficeExtension.LoadOption

propertyNamesAndPaths.select は、読み込むプロパティを指定するコンマ区切り文字列で propertyNamesAndPaths.expand 、読み込むナビゲーション プロパティを指定するコンマ区切りの文字列です。

戻り値

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出 toJSON します)。元 Excel.ShapeCollection のオブジェクトは API オブジェクトですが、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト (として Excel.Interfaces.ShapeCollectionData型指定) を返します。

toJSON(): Excel.Interfaces.ShapeCollectionData;

戻り値