ExcelScript.RangeFormat interface

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

注釈

/**
 * This script applies some simple formatting to the top row of the used range.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the top row of the used range in the current worksheet.
  const selectedSheet = workbook.getActiveWorksheet();
  const topRow = selectedSheet.getUsedRange().getRow(0);

  // For the top row, set the fill to black, the font color to white, and the font to be bold.
  const format: ExcelScript.RangeFormat = topRow.getFormat();
  format.getFill().setColor("black");
  format.getFont().setColor("white");
  format.getFont().setBold(true);
}

メソッド

adjustIndent(amount)

範囲の書式設定のインデントを調整します。 インデント値の範囲は 0 ~ 250 で、文字数で測定されます。

autofitColumns()

現在の列のデータに基づいて、現在の範囲の列の幅を最適な幅に変更します。

autofitRows()

現在の行のデータに基づいて、現在の範囲の行の高さを最適な高さに変更します。

getAutoIndent()

テキストの配置が等しい分布に設定されている場合に、テキストを自動的にインデントするかどうかを指定します。

getBorders()

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

getColumnWidth()

範囲内のすべての列の幅を指定します。 列の幅が均一でない場合は、 null が返されます。

getFill()

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

getFont()

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

getHorizontalAlignment()

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

getIndentLevel()

インデント レベルを示す 0 から 250 までの整数。

getProtection()

範囲に対する書式保護オブジェクトを返します。

getRangeBorder(index)

オブジェクトの名前を使用して、境界線オブジェクトを取得します。

getRangeBorderTintAndShade()

範囲の境界線の色を明るくまたは暗くする倍精度浮動小数点型 (double) を指定します。 値は -1 (最も暗い) から 1 (最も明るい) の間で、元の色の場合は 0 です。 値は null 、罫線コレクション全体に均一 tintAndShade な設定がないことを示します。

getReadingOrder()

範囲に適用される読み上げ順序。

getRowHeight()

範囲内のすべての行の高さ。 行の高さが一様でない場合は、 null が返されます。

getShrinkToFit()

使用可能な列幅に合わせてテキストを自動的に縮小するかどうかを指定します。

getTextOrientation()

範囲内のすべてのセルのテキストの向き。 テキストの向きは、-90 ~ 90 の整数、または垂直方向のテキストの場合は 180 である必要があります。 範囲内の向きが一様でない場合は、 null 返されます。

getUseStandardHeight()

オブジェクトの行の高さがシートの Range 標準の高さと等しいかどうかを判断します。 オブジェクトの true 行の高さがシートの Range 標準の高さと等しい場合にを返します。 null範囲に複数の行が含まれており、行がすべて同じ高さではない場合は を返します。 それ以外の場合は を返します false

getUseStandardWidth()

オブジェクトの列幅がシートの Range 標準幅と等しいかどうかを指定します。 オブジェクトの true 列幅がシートの Range 標準幅と等しい場合にを返します。 null範囲に複数の列が含まれており、列がすべて同じ高さではない場合は を返します。 それ以外の場合は を返します false

getVerticalAlignment()

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

getWrapText()

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

setAutoIndent(autoIndent)

テキストの配置が等しい分布に設定されている場合に、テキストを自動的にインデントするかどうかを指定します。

setColumnWidth(columnWidth)

範囲内のすべての列の幅を指定します。

setHorizontalAlignment(horizontalAlignment)

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

setIndentLevel(indentLevel)

インデント レベルを示す 0 から 250 までの整数。

setRangeBorderTintAndShade(rangeBorderTintAndShade)

範囲の境界線の色を明るくまたは暗くする倍精度浮動小数点型 (double) を指定します。 値は -1 (最も暗い) から 1 (最も明るい) の間で、元の色の場合は 0 です。 値は null 、罫線コレクション全体に均一 tintAndShade な設定がないことを示します。

setReadingOrder(readingOrder)

範囲に適用される読み上げ順序。

setRowHeight(rowHeight)

範囲内のすべての行の高さを指定します。

setShrinkToFit(shrinkToFit)

使用可能な列幅に合わせてテキストを自動的に縮小するかどうかを指定します。

setTextOrientation(textOrientation)

範囲内のすべてのセルのテキストの向き。 テキストの向きは、-90 ~ 90 の整数、または垂直方向のテキストの場合は 180 である必要があります。 範囲内の向きが一様でない場合は、 null 返されます。

setUseStandardHeight(useStandardHeight)

オブジェクトの行の高さがシートの Range 標準の高さと等しいかどうかを判断します。 注: このプロパティは、 に設定 trueのみを目的としています。 に false 設定しても効果はありません。

setUseStandardWidth(useStandardWidth)

オブジェクトの列幅がシートの Range 標準幅と等しいかどうかを指定します。 注: このプロパティは、 に設定 trueのみを目的としています。 に false 設定しても効果はありません。

setVerticalAlignment(verticalAlignment)

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

setWrapText(wrapText)

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

メソッドの詳細

adjustIndent(amount)

範囲の書式設定のインデントを調整します。 インデント値の範囲は 0 ~ 250 で、文字数で測定されます。

adjustIndent(amount: number): void;

パラメーター

amount

number

現在のインデントを調整する文字数。 この値は -250 から 250 の間である必要があります。 : インデント レベルが 250 を超える場合、インデント レベルは 250 のままです。 同様に、インデント レベルが 0 より下の場合、インデント レベルは 0 のままです。

戻り値

void

/**
 * This script adjusts the indentation of a specific table column.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table in the current worksheet.
  const selectedSheet = workbook.getActiveWorksheet();
  const table = selectedSheet.getTables()[0];

  // Get the data range of the second column.
  const secondColumn = table.getColumn(2);
  const data = secondColumn.getRangeBetweenHeaderAndTotal();

  // Add an indentation of 1 character space to the data range.
  data.getFormat().adjustIndent(1);
}

autofitColumns()

現在の列のデータに基づいて、現在の範囲の列の幅を最適な幅に変更します。

autofitColumns(): void;

戻り値

void

/**
 * This script creates a new table from existing data and autofits the columns.
 */
function main(workbook: ExcelScript.Workbook) {
  const currentSheet = workbook.getActiveWorksheet();
  const usedRange = currentSheet.getUsedRange();

  // Create the table.
  const table = currentSheet.addTable(usedRange, true);

  // Format the table columns.
  table.getRange().getFormat().autofitColumns();
}

autofitRows()

現在の行のデータに基づいて、現在の範囲の行の高さを最適な高さに変更します。

autofitRows(): void;

戻り値

void

/**
 * This script creates a new table from existing data and autofits the rows.
 */
function main(workbook: ExcelScript.Workbook) {
  const currentSheet = workbook.getActiveWorksheet();
  const usedRange = currentSheet.getUsedRange();

  // Create the table.
  const table = currentSheet.addTable(usedRange, true);

  // Format the table rows.
  table.getRange().getFormat().autofitRows();
}

getAutoIndent()

テキストの配置が等しい分布に設定されている場合に、テキストを自動的にインデントするかどうかを指定します。

getAutoIndent(): boolean;

戻り値

boolean

getBorders()

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

getBorders(): RangeBorder[];

戻り値

getColumnWidth()

範囲内のすべての列の幅を指定します。 列の幅が均一でない場合は、 null が返されます。

getColumnWidth(): number;

戻り値

number

/**
 * This script doubles the column width for every column in the active worksheet's used range.
 */
function main(workbook: ExcelScript.Workbook) {
  const currentSheet = workbook.getActiveWorksheet();
  const usedRange = currentSheet.getUsedRange();

  // To optimize performance, get all the current row heights before setting them.
  let currentWidths = Array<number>(usedRange.getColumnCount());
  for (let column = 0; column < currentWidths.length; column++) {
    currentWidths[column] = usedRange.getColumn(column).getFormat().getColumnWidth();
  }

  // Set the new column widths.
  for (let column = 0; column < currentWidths.length; column++) {
    usedRange.getFormat().setColumnWidth(currentWidths[column] * 2);
  }

getFill()

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

getFill(): RangeFill;

戻り値

/**
 * This script gives the total row of a table a green color fill.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table in the workbook.
  let table = workbook.getTables()[0];

  // Get the range for the total row of the table.
  let totalRange = table.getTotalRowRange();

  // Set the fill color to green.
  totalRange.getFormat().getFill().setColor("green");
}

getFont()

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

getFont(): RangeFont;

戻り値

/**
 * This script bolds the text of cell A1.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get A1 on the current worksheet.
  const cell = workbook.getActiveWorksheet().getCell(0,0);

  // Bold the font for that cell
  cell.getFormat().getFont().setBold(true);
}

getHorizontalAlignment()

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

getHorizontalAlignment(): HorizontalAlignment;

戻り値

getIndentLevel()

インデント レベルを示す 0 から 250 までの整数。

getIndentLevel(): number;

戻り値

number

getProtection()

範囲に対する書式保護オブジェクトを返します。

getProtection(): FormatProtection;

戻り値

getRangeBorder(index)

オブジェクトの名前を使用して、境界線オブジェクトを取得します。

getRangeBorder(index: BorderIndex): RangeBorder;

パラメーター

index
ExcelScript.BorderIndex

取得する border オブジェクトのインデックス値。 詳細は「ExcelScript.BorderIndex」をご覧ください。

戻り値

/**
 * This script adds a border around the outside of a range.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get a range from the current worksheet.
  let range = workbook.getActiveWorksheet().getRange("B2:E15");

  // Add a border around the whole bounding range.
  let format = range.getFormat();
  format.getRangeBorder(ExcelScript.BorderIndex.edgeTop).setStyle(ExcelScript.BorderLineStyle.continuous); // Top border
  format.getRangeBorder(ExcelScript.BorderIndex.edgeBottom).setStyle(ExcelScript.BorderLineStyle.continuous); // Bottom border
  format.getRangeBorder(ExcelScript.BorderIndex.edgeLeft).setStyle(ExcelScript.BorderLineStyle.continuous); // Left border
  format.getRangeBorder(ExcelScript.BorderIndex.edgeRight).setStyle(ExcelScript.BorderLineStyle.continuous); // Right border
}

getRangeBorderTintAndShade()

範囲の境界線の色を明るくまたは暗くする倍精度浮動小数点型 (double) を指定します。 値は -1 (最も暗い) から 1 (最も明るい) の間で、元の色の場合は 0 です。 値は null 、罫線コレクション全体に均一 tintAndShade な設定がないことを示します。

getRangeBorderTintAndShade(): number;

戻り値

number

getReadingOrder()

範囲に適用される読み上げ順序。

getReadingOrder(): ReadingOrder;

戻り値

getRowHeight()

範囲内のすべての行の高さ。 行の高さが一様でない場合は、 null が返されます。

getRowHeight(): number;

戻り値

number

/**
 * This script doubles the row height for every row in the active worksheet's used range.
 */
function main(workbook: ExcelScript.Workbook) {
  const currentSheet = workbook.getActiveWorksheet();
  const usedRange = currentSheet.getUsedRange();

  // To optimize performance, get all the current row heights before setting them.
  let currentHeights = Array<number>(usedRange.getRowCount());
  for (let row = 0; row < currentHeights.length; row++) {
    currentHeights[row] = usedRange.getRow(row).getFormat().getRowHeight();
  }

  // Set the new row heights.
  for (let row = 0; row < currentHeights.length; row++) {
    usedRange.getFormat().setRowHeight(currentHeights[row] * 2);
  }
}

getShrinkToFit()

使用可能な列幅に合わせてテキストを自動的に縮小するかどうかを指定します。

getShrinkToFit(): boolean;

戻り値

boolean

getTextOrientation()

範囲内のすべてのセルのテキストの向き。 テキストの向きは、-90 ~ 90 の整数、または垂直方向のテキストの場合は 180 である必要があります。 範囲内の向きが一様でない場合は、 null 返されます。

getTextOrientation(): number;

戻り値

number

getUseStandardHeight()

オブジェクトの行の高さがシートの Range 標準の高さと等しいかどうかを判断します。 オブジェクトの true 行の高さがシートの Range 標準の高さと等しい場合にを返します。 null範囲に複数の行が含まれており、行がすべて同じ高さではない場合は を返します。 それ以外の場合は を返します false

getUseStandardHeight(): boolean;

戻り値

boolean

getUseStandardWidth()

オブジェクトの列幅がシートの Range 標準幅と等しいかどうかを指定します。 オブジェクトの true 列幅がシートの Range 標準幅と等しい場合にを返します。 null範囲に複数の列が含まれており、列がすべて同じ高さではない場合は を返します。 それ以外の場合は を返します false

getUseStandardWidth(): boolean;

戻り値

boolean

getVerticalAlignment()

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

getVerticalAlignment(): VerticalAlignment;

戻り値

getWrapText()

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

getWrapText(): boolean;

戻り値

boolean

setAutoIndent(autoIndent)

テキストの配置が等しい分布に設定されている場合に、テキストを自動的にインデントするかどうかを指定します。

setAutoIndent(autoIndent: boolean): void;

パラメーター

autoIndent

boolean

戻り値

void

setColumnWidth(columnWidth)

範囲内のすべての列の幅を指定します。

setColumnWidth(columnWidth: number): void;

パラメーター

columnWidth

number

戻り値

void

/**
 * This script inserts a new column and sets that column's width to 100 pixels wide.
 */
function main(workbook: ExcelScript.Workbook) {
  const currentSheet = workbook.getActiveWorksheet();

  // Insert a new column between the current B and C columns.
  const bcRange = currentSheet.getRange("C:C");
  const newColumn = bcRange.insert(ExcelScript.InsertShiftDirection.right);
  
  // Set the column width of the new column to 100 pixels.
  newColumn.getFormat().setColumnWidth(100);
}

setHorizontalAlignment(horizontalAlignment)

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

setHorizontalAlignment(horizontalAlignment: HorizontalAlignment): void;

パラメーター

horizontalAlignment
ExcelScript.HorizontalAlignment

戻り値

void

/**
 * This script centers the text in a table's header row cells.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table on the current worksheet.
  const currentSheet = workbook.getActiveWorksheet();
  const table = currentSheet.getTables()[0];

  // Get the header range.
  const headerRange = table.getHeaderRowRange();

  // Set the horizontal text alignment to `center`.
  headerRange.getFormat().setHorizontalAlignment(ExcelScript.HorizontalAlignment.center);
}

setIndentLevel(indentLevel)

インデント レベルを示す 0 から 250 までの整数。

setIndentLevel(indentLevel: number): void;

パラメーター

indentLevel

number

戻り値

void

setRangeBorderTintAndShade(rangeBorderTintAndShade)

範囲の境界線の色を明るくまたは暗くする倍精度浮動小数点型 (double) を指定します。 値は -1 (最も暗い) から 1 (最も明るい) の間で、元の色の場合は 0 です。 値は null 、罫線コレクション全体に均一 tintAndShade な設定がないことを示します。

setRangeBorderTintAndShade(rangeBorderTintAndShade: number): void;

パラメーター

rangeBorderTintAndShade

number

戻り値

void

setReadingOrder(readingOrder)

範囲に適用される読み上げ順序。

setReadingOrder(readingOrder: ReadingOrder): void;

パラメーター

戻り値

void

setRowHeight(rowHeight)

範囲内のすべての行の高さを指定します。

setRowHeight(rowHeight: number): void;

パラメーター

rowHeight

number

戻り値

void

/**
 * This script inserts a new row and sets that row's width to 100 pixels tall.
 */
function main(workbook: ExcelScript.Workbook) {
  const currentSheet = workbook.getActiveWorksheet();

  // Insert a new row between the current 2 and 3 rows.
  const bcRange = currentSheet.getRange("3:3");
  const newRow = bcRange.insert(ExcelScript.InsertShiftDirection.down);
  
  // Set the row height of the new row to 100 pixels.
  newRow.getFormat().setRowHeight(100);
}

setShrinkToFit(shrinkToFit)

使用可能な列幅に合わせてテキストを自動的に縮小するかどうかを指定します。

setShrinkToFit(shrinkToFit: boolean): void;

パラメーター

shrinkToFit

boolean

戻り値

void

setTextOrientation(textOrientation)

範囲内のすべてのセルのテキストの向き。 テキストの向きは、-90 ~ 90 の整数、または垂直方向のテキストの場合は 180 である必要があります。 範囲内の向きが一様でない場合は、 null 返されます。

setTextOrientation(textOrientation: number): void;

パラメーター

textOrientation

number

戻り値

void

setUseStandardHeight(useStandardHeight)

オブジェクトの行の高さがシートの Range 標準の高さと等しいかどうかを判断します。 注: このプロパティは、 に設定 trueのみを目的としています。 に false 設定しても効果はありません。

setUseStandardHeight(useStandardHeight: boolean): void;

パラメーター

useStandardHeight

boolean

戻り値

void

setUseStandardWidth(useStandardWidth)

オブジェクトの列幅がシートの Range 標準幅と等しいかどうかを指定します。 注: このプロパティは、 に設定 trueのみを目的としています。 に false 設定しても効果はありません。

setUseStandardWidth(useStandardWidth: boolean): void;

パラメーター

useStandardWidth

boolean

戻り値

void

setVerticalAlignment(verticalAlignment)

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

setVerticalAlignment(verticalAlignment: VerticalAlignment): void;

パラメーター

verticalAlignment
ExcelScript.VerticalAlignment

戻り値

void

/**
 * This script sets the vertical alignment formatting to "top"
 * for every cell in the row.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get row 1 for the current worksheet.
  const sheet = workbook.getActiveWorksheet();
  const firstRow = sheet.getRange("1:1");

  // Set the vertical alignment formatting on the row.
  firstRow.getFormat().setVerticalAlignment(ExcelScript.VerticalAlignment.top);
}

setWrapText(wrapText)

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

setWrapText(wrapText: boolean): void;

パラメーター

wrapText

boolean

戻り値

void

/**
 * This script turns on the text wrapping for a column.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the E column in current worksheet.
  const column = workbook.getActiveWorksheet().getRange("E:E");

  // Set wrap text to true for the column.
  column.getFormat().setWrapText(true);
}