ExcelScript.TextRange interface

図形に結合するテキストや、テキストを操作するためのプロパティおよびメソッドが含まれます。

注釈

/**
 * This script adds text to a shape.
 */
function main(workbook: ExcelScript.Workbook) {
  // Create a hexagon shape in the current worksheet.
  const sheet = workbook.getActiveWorksheet();
  const hexagon = sheet.addGeometricShape(ExcelScript.GeometricShapeType.hexagon);
  
  // Set the text of the shape.
  const hexText: ExcelScript.TextRange = hexagon.getTextFrame().getTextRange();
  hexText.setText("Forest");
}

メソッド

getFont()

テキスト範囲の ShapeFont フォント属性を表す オブジェクトを返します。

getSubstring(start, length)

指定された範囲の部分文字列に対する TextRange オブジェクトを返します。

getText()

テキスト範囲のプレーン テキスト コンテンツを表します。

setText(text)

テキスト範囲のプレーン テキスト コンテンツを表します。

メソッドの詳細

getFont()

テキスト範囲の ShapeFont フォント属性を表す オブジェクトを返します。

getFont(): ShapeFont;

戻り値

/**
 * This sample sets the font of a shape to be bold. 
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first shape in the current worksheet.
  const sheet = workbook.getActiveWorksheet();
  const shape = sheet.getShapes()[0];

  // Get the text font from the shape.
  const text: ExcelScript.TextRange = shape.getTextFrame().getTextRange();
  const shapeTextFont: ExcelScript.ShapeFont = text.getFont();

  // Set the font to be bold.
  shapeTextFont.setBold(true);
}

getSubstring(start, length)

指定された範囲の部分文字列に対する TextRange オブジェクトを返します。

getSubstring(start: number, length?: number): TextRange;

パラメーター

start

number

テキスト範囲から取得する最初の文字の 0 から始まるインデックス。

length

number

省略可能です。 新しいテキスト範囲で返される文字数。 length を省略すると、テキスト範囲の最後の段落の先頭から末尾までのすべての文字が返されます。

戻り値

getText()

テキスト範囲のプレーン テキスト コンテンツを表します。

getText(): string;

戻り値

string

/**
 * This script writes all the text from the workbook's geometric shapes in a new worksheet.
 */
function main(workbook: ExcelScript.Workbook) {
  // Create a new worksheet.
  const shapeTextSheet = workbook.addWorksheet("ShapeText");
  let shapeTextValues: string[][] = [];

  // Get the text from every geometric shape in every worksheet.
  workbook.getWorksheets().forEach((sheet) => {
    sheet.getShapes().forEach((shape) => {
      if (shape.getType() === ExcelScript.ShapeType.geometricShape)
      shapeTextValues.push([
        sheet.getName(),
        shape.getGeometricShapeType().toString(),
        shape.getTextFrame().getTextRange().getText()]);
    });
  });

  // Add the text to the new worksheet.
  const range = shapeTextSheet.getRangeByIndexes(
    0,
    0, 
    shapeTextValues.length, 
    shapeTextValues[0].length);
  range.setValues(shapeTextValues);
}

setText(text)

テキスト範囲のプレーン テキスト コンテンツを表します。

setText(text: string): void;

パラメーター

text

string

戻り値

void