ExcelScript.DatetimeFormatInfo interface

Define o formato culturalmente apropriado de exibir números. Isso se baseia nas configurações atuais de cultura do sistema.

Comentários

Exemplos

/**
 * This script sets the value of a cell to a date string for January 2, 2023.
 * It writes the day or month first in the string based on system settings.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first cell in the current worksheet.
  const cell = workbook.getActiveWorksheet().getCell(0,0);

  // Get the date format.
  const cultureInfo : ExcelScript.CultureInfo = workbook.getApplication().getCultureInfo();
  const systemDateTimeFormat : ExcelScript.DatetimeFormatInfo = cultureInfo.getDatetimeFormat();
  const shortDatePattern : string = systemDateTimeFormat.getShortDatePattern();

  // Determine if the date should start with the month or day.
  if (shortDatePattern.startsWith("m")) {
    cell.setValue("1/2/2023");
  } else {
    cell.setValue("2/1/2023");
  }
}

Métodos

getDateSeparator()

Obtém a cadeia de caracteres usada como separador de data. Isso se baseia nas configurações atuais do sistema.

getLongDatePattern()

Obtém a cadeia de caracteres de formato para um valor de data longa. Isso se baseia nas configurações atuais do sistema.

getLongTimePattern()

Obtém a cadeia de caracteres de formato por um valor de longo tempo. Isso se baseia nas configurações atuais do sistema.

getShortDatePattern()

Obtém a cadeia de caracteres de formato para um valor de data curta. Isso se baseia nas configurações atuais do sistema.

getTimeSeparator()

Obtém a cadeia de caracteres usada como separador de tempo. Isso se baseia nas configurações atuais do sistema.

Detalhes do método

getDateSeparator()

Obtém a cadeia de caracteres usada como separador de data. Isso se baseia nas configurações atuais do sistema.

getDateSeparator(): string;

Retornos

string

Exemplos

/**
 * This script writes the current date, month, and year.
 * It uses the system's date separator character.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first cell in the current worksheet.
  const cell = workbook.getActiveWorksheet().getCell(0,0);

  // Get the date separation string.
  const cultureInfo = workbook.getApplication().getCultureInfo();
  const systemDateTimeFormat = cultureInfo.getDatetimeFormat();
  const separator = systemDateTimeFormat.getDateSeparator();

  // Get the current date.
  const currentDate = new Date(Date.now());

  // Write the date using the system's separator character.
  cell.setValue(`${currentDate.getMonth()}${separator}${currentDate.getDate()}${separator}${currentDate.getFullYear()}`);
}

getLongDatePattern()

Obtém a cadeia de caracteres de formato para um valor de data longa. Isso se baseia nas configurações atuais do sistema.

getLongDatePattern(): string;

Retornos

string

Exemplos

/**
 * This script returns the system's long date pattern. 
 * This could be used in a Power Automate flow to keep date formatting consistent.
 */
function main(workbook: ExcelScript.Workbook) : string {
    const cultureInfo = workbook.getApplication().getCultureInfo();
    const dateTimeInfo =  cultureInfo.getDatetimeFormat();
    
    return dateTimeInfo.getLongDatePattern();
}

getLongTimePattern()

Obtém a cadeia de caracteres de formato por um valor de longo tempo. Isso se baseia nas configurações atuais do sistema.

getLongTimePattern(): string;

Retornos

string

getShortDatePattern()

Obtém a cadeia de caracteres de formato para um valor de data curta. Isso se baseia nas configurações atuais do sistema.

getShortDatePattern(): string;

Retornos

string

getTimeSeparator()

Obtém a cadeia de caracteres usada como separador de tempo. Isso se baseia nas configurações atuais do sistema.

getTimeSeparator(): string;

Retornos

string

Exemplos

/**
 * This script writes the current hour, minute, and second.
 * It uses the system's time separator character.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first cell in the current worksheet.
  const cell = workbook.getActiveWorksheet().getCell(0, 0);

  // Get the date separation string.
  const cultureInfo = workbook.getApplication().getCultureInfo();
  const systemDateTimeFormat = cultureInfo.getDatetimeFormat();
  const separator = systemDateTimeFormat.getTimeSeparator();

  // Get the current time.
  const currentTime = new Date(Date.now());

  // Write the date using the system's separator character.
  cell.setValue(`${currentTime.getHours()}${separator}${currentTime.getMinutes()}${separator}${currentTime.getSeconds()}`);
}