ExcelScript.RangeFormat interface

Objeto de formato que encapsula la fuente, el relleno, los bordes, la alineación y otras propiedades del intervalo.

Comentarios

Ejemplos

/**
 * 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);
}

Métodos

adjustIndent(amount)

Ajusta la sangría del formato de intervalo. El valor de sangría oscila entre 0 y 250 y se mide en caracteres.

autofitColumns()

Cambia el ancho de las columnas del rango actual para obtener el ajuste perfecto (según los datos actuales de las columnas).

autofitRows()

Cambia el alto de las filas del rango actual para obtener el ajuste perfecto (según los datos actuales de las columnas).

getAutoIndent()

Especifica si el texto se aplica sangría automáticamente cuando la alineación del texto se establece en la misma distribución.

getBorders()

Colección de objetos de borde que se aplica al rango global seleccionado.

getColumnWidth()

Especifica el ancho de todas las columnas del intervalo. Si los anchos de columna no son uniformes, null se devolverá.

getFill()

Devuelve el objeto de relleno definido en el intervalo global.

getFont()

Devuelve el objeto de fuente definido en el rango global.

getHorizontalAlignment()

Representa la alineación horizontal del objeto especificado. Vea ExcelScript.HorizontalAlignment para más información.

getIndentLevel()

Un número entero entre 0 y 250 que indica el nivel de sangría.

getProtection()

Devuelve el objeto de protección de formato de un rango.

getRangeBorder(index)

Obtiene un objeto de borde mediante su nombre.

getRangeBorderTintAndShade()

Especifica un doble que aclara u oscurece un color para los bordes de intervalo. El valor está entre -1 (más oscuro) y 1 (más brillante), con 0 para el color original. Un null valor indica que toda la colección de bordes no tiene una configuración uniforme tintAndShade .

getReadingOrder()

El orden de lectura para el intervalo.

getRowHeight()

Alto de todas las filas del intervalo. Si los altos de fila no son uniformes, null se devolverá.

getShrinkToFit()

Especifica si el texto se reduce automáticamente para ajustarse al ancho de columna disponible.

getTextOrientation()

Orientación del texto de todas las celdas dentro del rango. La orientación del texto debe ser un entero de -90 a 90 o 180 para texto orientado verticalmente. Si la orientación dentro de un intervalo no es uniforme, null se devolverá.

getUseStandardHeight()

Determina si el alto de fila del Range objeto es igual al alto estándar de la hoja. Devuelve true si el alto de fila del Range objeto es igual al alto estándar de la hoja. Devuelve null si el intervalo contiene más de una fila y las filas no tienen el mismo alto. Devuelve false lo contrario.

getUseStandardWidth()

Especifica si el ancho de columna del Range objeto es igual al ancho estándar de la hoja. Devuelve true si el ancho de columna del Range objeto es igual al ancho estándar de la hoja. Devuelve null si el intervalo contiene más de una columna y las columnas no tienen el mismo alto. Devuelve false lo contrario.

getVerticalAlignment()

Representa la alineación vertical del objeto especificado. Vea ExcelScript.VerticalAlignment para más información.

getWrapText()

Especifica si Excel ajusta el texto del objeto. Un null valor indica que todo el intervalo no tiene una configuración de ajuste uniforme

setAutoIndent(autoIndent)

Especifica si el texto se aplica sangría automáticamente cuando la alineación del texto se establece en la misma distribución.

setColumnWidth(columnWidth)

Especifica el ancho de todas las columnas del intervalo.

setHorizontalAlignment(horizontalAlignment)

Representa la alineación horizontal del objeto especificado. Vea ExcelScript.HorizontalAlignment para más información.

setIndentLevel(indentLevel)

Un número entero entre 0 y 250 que indica el nivel de sangría.

setRangeBorderTintAndShade(rangeBorderTintAndShade)

Especifica un doble que aclara u oscurece un color para los bordes de intervalo. El valor está entre -1 (más oscuro) y 1 (más brillante), con 0 para el color original. Un null valor indica que toda la colección de bordes no tiene una configuración uniforme tintAndShade .

setReadingOrder(readingOrder)

El orden de lectura para el intervalo.

setRowHeight(rowHeight)

Especifica el alto de todas las filas del intervalo.

setShrinkToFit(shrinkToFit)

Especifica si el texto se reduce automáticamente para ajustarse al ancho de columna disponible.

setTextOrientation(textOrientation)

Orientación del texto de todas las celdas dentro del rango. La orientación del texto debe ser un entero de -90 a 90 o 180 para texto orientado verticalmente. Si la orientación dentro de un intervalo no es uniforme, null se devolverá.

setUseStandardHeight(useStandardHeight)

Determina si el alto de fila del Range objeto es igual al alto estándar de la hoja. Nota: Esta propiedad solo está pensada para establecerse en true. Establecerlo en false no tiene ningún efecto.

setUseStandardWidth(useStandardWidth)

Especifica si el ancho de columna del Range objeto es igual al ancho estándar de la hoja. Nota: Esta propiedad solo está pensada para establecerse en true. Establecerlo en false no tiene ningún efecto.

setVerticalAlignment(verticalAlignment)

Representa la alineación vertical del objeto especificado. Vea ExcelScript.VerticalAlignment para más información.

setWrapText(wrapText)

Especifica si Excel ajusta el texto del objeto. Un null valor indica que todo el intervalo no tiene una configuración de ajuste uniforme

Detalles del método

adjustIndent(amount)

Ajusta la sangría del formato de intervalo. El valor de sangría oscila entre 0 y 250 y se mide en caracteres.

adjustIndent(amount: number): void;

Parámetros

amount

number

Número de espacios de caracteres por el que se ajusta la sangría actual. Este valor debe estar entre -250 y 250. Nota: Si la cantidad elevaría el nivel de sangría por encima de 250, el nivel de sangría se mantiene con 250. De forma similar, si la cantidad reduciría el nivel de sangría por debajo de 0, el nivel de sangría permanece 0.

Devoluciones

void

Ejemplos

/**
 * 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()

Cambia el ancho de las columnas del rango actual para obtener el ajuste perfecto (según los datos actuales de las columnas).

autofitColumns(): void;

Devoluciones

void

Ejemplos

/**
 * 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()

Cambia el alto de las filas del rango actual para obtener el ajuste perfecto (según los datos actuales de las columnas).

autofitRows(): void;

Devoluciones

void

Ejemplos

/**
 * 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()

Especifica si el texto se aplica sangría automáticamente cuando la alineación del texto se establece en la misma distribución.

getAutoIndent(): boolean;

Devoluciones

boolean

getBorders()

Colección de objetos de borde que se aplica al rango global seleccionado.

getBorders(): RangeBorder[];

Devoluciones

getColumnWidth()

Especifica el ancho de todas las columnas del intervalo. Si los anchos de columna no son uniformes, null se devolverá.

getColumnWidth(): number;

Devoluciones

number

Ejemplos

/**
 * 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()

Devuelve el objeto de relleno definido en el intervalo global.

getFill(): RangeFill;

Devoluciones

Ejemplos

/**
 * 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()

Devuelve el objeto de fuente definido en el rango global.

getFont(): RangeFont;

Devoluciones

Ejemplos

/**
 * 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()

Representa la alineación horizontal del objeto especificado. Vea ExcelScript.HorizontalAlignment para más información.

getHorizontalAlignment(): HorizontalAlignment;

Devoluciones

getIndentLevel()

Un número entero entre 0 y 250 que indica el nivel de sangría.

getIndentLevel(): number;

Devoluciones

number

getProtection()

Devuelve el objeto de protección de formato de un rango.

getProtection(): FormatProtection;

Devoluciones

getRangeBorder(index)

Obtiene un objeto de borde mediante su nombre.

getRangeBorder(index: BorderIndex): RangeBorder;

Parámetros

index
ExcelScript.BorderIndex

Valor de índice del objeto de borde que va a recuperarse. Vea ExcelScript.BorderIndex para más información.

Devoluciones

Ejemplos

/**
 * 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()

Especifica un doble que aclara u oscurece un color para los bordes de intervalo. El valor está entre -1 (más oscuro) y 1 (más brillante), con 0 para el color original. Un null valor indica que toda la colección de bordes no tiene una configuración uniforme tintAndShade .

getRangeBorderTintAndShade(): number;

Devoluciones

number

getReadingOrder()

El orden de lectura para el intervalo.

getReadingOrder(): ReadingOrder;

Devoluciones

getRowHeight()

Alto de todas las filas del intervalo. Si los altos de fila no son uniformes, null se devolverá.

getRowHeight(): number;

Devoluciones

number

Ejemplos

/**
 * 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()

Especifica si el texto se reduce automáticamente para ajustarse al ancho de columna disponible.

getShrinkToFit(): boolean;

Devoluciones

boolean

getTextOrientation()

Orientación del texto de todas las celdas dentro del rango. La orientación del texto debe ser un entero de -90 a 90 o 180 para texto orientado verticalmente. Si la orientación dentro de un intervalo no es uniforme, null se devolverá.

getTextOrientation(): number;

Devoluciones

number

getUseStandardHeight()

Determina si el alto de fila del Range objeto es igual al alto estándar de la hoja. Devuelve true si el alto de fila del Range objeto es igual al alto estándar de la hoja. Devuelve null si el intervalo contiene más de una fila y las filas no tienen el mismo alto. Devuelve false lo contrario.

getUseStandardHeight(): boolean;

Devoluciones

boolean

getUseStandardWidth()

Especifica si el ancho de columna del Range objeto es igual al ancho estándar de la hoja. Devuelve true si el ancho de columna del Range objeto es igual al ancho estándar de la hoja. Devuelve null si el intervalo contiene más de una columna y las columnas no tienen el mismo alto. Devuelve false lo contrario.

getUseStandardWidth(): boolean;

Devoluciones

boolean

getVerticalAlignment()

Representa la alineación vertical del objeto especificado. Vea ExcelScript.VerticalAlignment para más información.

getVerticalAlignment(): VerticalAlignment;

Devoluciones

getWrapText()

Especifica si Excel ajusta el texto del objeto. Un null valor indica que todo el intervalo no tiene una configuración de ajuste uniforme

getWrapText(): boolean;

Devoluciones

boolean

setAutoIndent(autoIndent)

Especifica si el texto se aplica sangría automáticamente cuando la alineación del texto se establece en la misma distribución.

setAutoIndent(autoIndent: boolean): void;

Parámetros

autoIndent

boolean

Devoluciones

void

setColumnWidth(columnWidth)

Especifica el ancho de todas las columnas del intervalo.

setColumnWidth(columnWidth: number): void;

Parámetros

columnWidth

number

Devoluciones

void

Ejemplos

/**
 * 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)

Representa la alineación horizontal del objeto especificado. Vea ExcelScript.HorizontalAlignment para más información.

setHorizontalAlignment(horizontalAlignment: HorizontalAlignment): void;

Parámetros

horizontalAlignment
ExcelScript.HorizontalAlignment

Devoluciones

void

Ejemplos

/**
 * 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)

Un número entero entre 0 y 250 que indica el nivel de sangría.

setIndentLevel(indentLevel: number): void;

Parámetros

indentLevel

number

Devoluciones

void

setRangeBorderTintAndShade(rangeBorderTintAndShade)

Especifica un doble que aclara u oscurece un color para los bordes de intervalo. El valor está entre -1 (más oscuro) y 1 (más brillante), con 0 para el color original. Un null valor indica que toda la colección de bordes no tiene una configuración uniforme tintAndShade .

setRangeBorderTintAndShade(rangeBorderTintAndShade: number): void;

Parámetros

rangeBorderTintAndShade

number

Devoluciones

void

setReadingOrder(readingOrder)

El orden de lectura para el intervalo.

setReadingOrder(readingOrder: ReadingOrder): void;

Parámetros

Devoluciones

void

setRowHeight(rowHeight)

Especifica el alto de todas las filas del intervalo.

setRowHeight(rowHeight: number): void;

Parámetros

rowHeight

number

Devoluciones

void

Ejemplos

/**
 * 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)

Especifica si el texto se reduce automáticamente para ajustarse al ancho de columna disponible.

setShrinkToFit(shrinkToFit: boolean): void;

Parámetros

shrinkToFit

boolean

Devoluciones

void

setTextOrientation(textOrientation)

Orientación del texto de todas las celdas dentro del rango. La orientación del texto debe ser un entero de -90 a 90 o 180 para texto orientado verticalmente. Si la orientación dentro de un intervalo no es uniforme, null se devolverá.

setTextOrientation(textOrientation: number): void;

Parámetros

textOrientation

number

Devoluciones

void

setUseStandardHeight(useStandardHeight)

Determina si el alto de fila del Range objeto es igual al alto estándar de la hoja. Nota: Esta propiedad solo está pensada para establecerse en true. Establecerlo en false no tiene ningún efecto.

setUseStandardHeight(useStandardHeight: boolean): void;

Parámetros

useStandardHeight

boolean

Devoluciones

void

setUseStandardWidth(useStandardWidth)

Especifica si el ancho de columna del Range objeto es igual al ancho estándar de la hoja. Nota: Esta propiedad solo está pensada para establecerse en true. Establecerlo en false no tiene ningún efecto.

setUseStandardWidth(useStandardWidth: boolean): void;

Parámetros

useStandardWidth

boolean

Devoluciones

void

setVerticalAlignment(verticalAlignment)

Representa la alineación vertical del objeto especificado. Vea ExcelScript.VerticalAlignment para más información.

setVerticalAlignment(verticalAlignment: VerticalAlignment): void;

Parámetros

verticalAlignment
ExcelScript.VerticalAlignment

Devoluciones

void

Ejemplos

/**
 * 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)

Especifica si Excel ajusta el texto del objeto. Un null valor indica que todo el intervalo no tiene una configuración de ajuste uniforme

setWrapText(wrapText: boolean): void;

Parámetros

wrapText

boolean

Devoluciones

void

Ejemplos

/**
 * 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);
}