Excel.RangeFont class

このオブジェクトは、オブジェクトのフォントの属性 (フォント名、フォント サイズ、色など) を表します。

Extends

注釈

API セット: ExcelApi 1.1

使用元

例

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

// Set several font properties 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");
    const headerFont: Excel.RangeFont = headerRange.format.font;

    headerFont.set({
        bold: true,
        color: "#1F4E78",
        italic: false,
        name: "Aptos Display",
        size: 14,
        underline: Excel.RangeUnderlineStyle.single
    });

    await context.sync();
    console.log("The header font formatting was updated.");
});

プロパティ

bold

フォントの太字の状態を表します。

color

テキスト色の HTML カラー コード表現 (例: #FF0000 は赤を表します)。

context

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

italic

フォントの斜体の状態を指定します。

name

フォント名 (例: "Calibri")。 名前の長さは 31 文字以内にする必要があります。

size

フォント サイズ。

underline

フォントに適用する下線の種類。 詳細は「Excel.RangeUnderlineStyle」をご覧ください。

メソッド

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.RangeFont オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.RangeFontData と型指定) を返します。

プロパティの詳細

bold

フォントの太字の状態を表します。

bold: boolean;

プロパティ値

boolean

注釈

API セット: ExcelApi 1.1

例

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

await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getActiveWorksheet();
  const sumRange = sheet.getRange("F4");
  sumRange.formulas = [["=SUM(B4:E4)"]];
  sumRange.format.fill.color = "LightBlue";
  sumRange.format.font.bold = true;
  sheet.getRanges("K4,P4").copyFrom("F4", Excel.RangeCopyType.all);
  sheet.getRanges("F4,K4,P4").format.autofitColumns();
  await context.sync();
});

color

テキスト色の HTML カラー コード表現 (例: #FF0000 は赤を表します)。

color: string;

プロパティ値

string

注釈

API セット: ExcelApi 1.1

例

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

// Get the font properties 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");
    const headerFont: Excel.RangeFont = headerRange.format.font;

    headerFont.load("bold, color, italic, name, size, underline");
    await context.sync();

    console.log(`Bold: ${headerFont.bold}`);
    console.log(`Color: ${headerFont.color}`);
    console.log(`Italic: ${headerFont.italic}`);
    console.log(`Name: ${headerFont.name}`);
    console.log(`Size: ${headerFont.size}`);
    console.log(`Underline: ${headerFont.underline}`);
});

context

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

context: RequestContext;

プロパティ値

italic

フォントの斜体の状態を指定します。

italic: boolean;

プロパティ値

boolean

注釈

API セット: ExcelApi 1.1

name

フォント名 (例: "Calibri")。 名前の長さは 31 文字以内にする必要があります。

name: string;

プロパティ値

string

注釈

API セット: ExcelApi 1.1

例

// Change the font of the selected range to "Impact".
await Excel.run(async (context) => {
  const selection = context.workbook.getSelectedRange();
  selection.format.font.name = "Impact";
  await context.sync();
});

size

フォント サイズ。

size: number;

プロパティ値

number

注釈

API セット: ExcelApi 1.1

underline

フォントに適用する下線の種類。 詳細は「Excel.RangeUnderlineStyle」をご覧ください。

underline: Excel.RangeUnderlineStyle | "None" | "Single" | "Double" | "SingleAccountant" | "DoubleAccountant";

プロパティ値

Excel.RangeUnderlineStyle | "None" | "Single" | "Double" | "SingleAccountant" | "DoubleAccountant"

注釈

API セット: ExcelApi 1.1

メソッドの詳細

load(options)

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

load(options?: Excel.Interfaces.RangeFontLoadOptions): Excel.RangeFont;

パラメーター

options
Excel.Interfaces.RangeFontLoadOptions

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

返品

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

返品

例

await Excel.run(async (context) => { 
    const sheetName = "Sheet1";
    const rangeAddress = "F:G";
    const worksheet = context.workbook.worksheets.getItem(sheetName);
    const range = worksheet.getRange(rangeAddress);
    const rangeFont = range.format.font;
    rangeFont.load('name');
    await context.sync();
    console.log(rangeFont.name);
});

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths

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

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

返品

set(properties, options)

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

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

パラメーター

properties
Excel.Interfaces.RangeFontUpdateData

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

options
OfficeExtension.UpdateOptions

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

返品

void

set(properties)

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

set(properties: Excel.RangeFont): void;

パラメーター

properties
Excel.RangeFont

返品

void

toJSON()

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

toJSON(): Excel.Interfaces.RangeFontData;

返品