Excel.RangeFormat class

範囲のフォント、塗りつぶし、境界線、配置などのプロパティをカプセル化する、書式設定オブジェクトです。

Extends

プロパティ

borders

選択した範囲全体に適用する境界線オブジェクトのコレクション。

context

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

fill

範囲全体に定義された塗りつぶしオブジェクトを返します。

font

範囲全体に定義されたフォント オブジェクトを返します。

horizontalAlignment

指定したオブジェクトの水平方向の配置を表します。 詳細は「Excel.HorizontalAlignment」をご覧ください。

verticalAlignment

指定したオブジェクトの垂直方向の配置を表します。 詳細は「Excel.VerticalAlignment」をご覧ください。

wrapText

Excel がオブジェクト内のテキストを折り返すかどうかを指定します。 null値は、範囲全体に均一な折り返し設定が設定されていないことを示します

メソッド

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.RangeFormat オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.RangeFormatData と型指定) を返します。

プロパティの詳細

borders

選択した範囲全体に適用する境界線オブジェクトのコレクション。

readonly borders: Excel.RangeBorderCollection;

プロパティ値

注釈

API セット: ExcelApi 1.1

context

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

context: RequestContext;

プロパティ値

fill

範囲全体に定義された塗りつぶしオブジェクトを返します。

readonly fill: Excel.RangeFill;

プロパティ値

注釈

API セット: ExcelApi 1.1

例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/formatting.yaml

// Set the fill color for the header range.
await Excel.run(async (context) => {
    const sheet: Excel.Worksheet = context.workbook.worksheets.getItem("Sample");
    const headerRange: Excel.Range = sheet.getRange("B2:E2");

    headerRange.format.fill.color = "#D9EAF7";

    await context.sync();
    console.log("The header fill color was updated.");
});

font

範囲全体に定義されたフォント オブジェクトを返します。

readonly font: Excel.RangeFont;

プロパティ値

注釈

API セット: ExcelApi 1.1

horizontalAlignment

指定したオブジェクトの水平方向の配置を表します。 詳細は「Excel.HorizontalAlignment」をご覧ください。

horizontalAlignment: Excel.HorizontalAlignment | "General" | "Left" | "Center" | "Right" | "Fill" | "Justify" | "CenterAcrossSelection" | "Distributed";

プロパティ値

Excel.HorizontalAlignment | "General" | "Left" | "Center" | "Right" | "Fill" | "Justify" | "CenterAcrossSelection" | "Distributed"

注釈

API セット: ExcelApi 1.1

例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-pivotlayout.yaml

await Excel.run(async (context) => {
  // Set a default value for an empty cell in the PivotTable. This doesn't include cells left blank by the layout.
  const pivotTable = context.workbook.pivotTables.getItem("Farm Sales");
  const pivotLayout = pivotTable.layout;

  pivotLayout.emptyCellText = "--";

  // Set the text alignment to match the rest of the PivotTable.
  pivotLayout.getDataBodyRange().format.horizontalAlignment = Excel.HorizontalAlignment.right;
  await context.sync();
});

verticalAlignment

指定したオブジェクトの垂直方向の配置を表します。 詳細は「Excel.VerticalAlignment」をご覧ください。

verticalAlignment: Excel.VerticalAlignment | "Top" | "Center" | "Bottom" | "Justify" | "Distributed";

プロパティ値

Excel.VerticalAlignment | "Top" | "Center" | "Bottom" | "Justify" | "Distributed"

注釈

API セット: ExcelApi 1.1

例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/style.yaml

await Excel.run(async (context) => {
    let worksheet = context.workbook.worksheets.getItem("Sample");
    let range = worksheet.getRange("A1:E1");
    // Apply new style.
    range.style = ("Diagonal Orientation Style");
    range.format.verticalAlignment = "Justify";

    await context.sync();
});

wrapText

Excel がオブジェクト内のテキストを折り返すかどうかを指定します。 null値は、範囲全体に均一な折り返し設定が設定されていないことを示します

wrapText: boolean;

プロパティ値

boolean

注釈

API セット: ExcelApi 1.1

メソッドの詳細

load(options)

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

load(options?: Excel.Interfaces.RangeFormatLoadOptions): Excel.RangeFormat;

パラメーター

options
Excel.Interfaces.RangeFormatLoadOptions

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

返品

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

返品

例

// Select all of the range's format properties.
await Excel.run(async (context) => { 
    const sheetName = "Sheet1";
    const rangeAddress = "F:G";
    const worksheet = context.workbook.worksheets.getItem(sheetName);
    const range = worksheet.getRange(rangeAddress);
    range.load(["format/*", "format/fill", "format/borders", "format/font"]);
    await context.sync();
    
    console.log(range.format.wrapText);
    console.log(range.format.fill.color);
    console.log(range.format.font.name);
});

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.RangeFormat;

パラメーター

propertyNamesAndPaths

{ select?: string; expand?: string; }

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

返品

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。

set(properties: Interfaces.RangeFormatUpdateData, options?: OfficeExtension.UpdateOptions): void;

パラメーター

properties
Excel.Interfaces.RangeFormatUpdateData

メソッドが呼び出されたオブジェクトのプロパティと同型構造のプロパティを持つ JavaScript オブジェクト。

options
OfficeExtension.UpdateOptions

プロパティ オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。

返品

void

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

set(properties: Excel.RangeFormat): void;

パラメーター

properties
Excel.RangeFormat

返品

void

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.RangeFormat オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.RangeFormatData と型指定) を返します。

toJSON(): Excel.Interfaces.RangeFormatData;

返品