Excel.ShapeCollection class

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

Extends

プロパティ

context

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

items

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

メソッド

addGeometricShape(geometricShapeType)

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

addGeometricShape(geometricShapeType)

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

addGroup(values)

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

addImage(base64ImageString)

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

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

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

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

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

addLocalImageReference(address)

セル アドレスに格納されているローカル画像の参照を作成し、セル上の浮動図形として表示します。

addSvg(xml)

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

addTextBox(text)

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

getCount()

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

getItem(key)

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

getItemAt(index)

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

getItemOrNullObject(key)

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

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、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(geometricShapeType)

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

addGeometricShape(geometricShapeType: "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;

パラメーター

geometricShapeType

"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 = document.getElementById("selectedFile") as HTMLInputElement;
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, connectorType)

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

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

パラメーター

startLeft

number

行の始点からワークシートの左側までの距離 (ポイント単位)。

startTop

number

行の始点からワークシートの先頭までの距離 (ポイント単位)。

endLeft

number

行の終点からワークシートの左までの距離 (ポイント単位)。

endTop

number

行の終わりからワークシートの先頭までの距離 (ポイント単位)。

connectorType

"Straight" | "Elbow" | "Curve"

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

返品

注釈

API セット: ExcelApi 1.9

addLocalImageReference(address)

注意

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

セル アドレスに格納されているローカル画像の参照を作成し、セル上の浮動図形として表示します。

addLocalImageReference(address: string): Excel.Shape;

パラメーター

address

string

ローカル イメージを含むセルのアドレス。

返品

フローティング シェイプに関連付けられている Shape オブジェクト。

注釈

API セット: ExcelApi ベータ版 (プレビューのみ)

addSvg(xml)

注意

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

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

addSvg(xml: string): Excel.Shape;

パラメーター

xml

string

SVG を表す XML 文字列。

返品

注釈

API セット: ExcelApi ベータ版 (プレビューのみ)

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 オブジェクトが存在しない場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *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 オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.ShapeCollection オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.ShapeCollectionData として型指定された) を返します。

toJSON(): Excel.Interfaces.ShapeCollectionData;

返品