Skip to main content
Office

Excel

Excel

IMPORTANT

To use this category it is MANDATORY to have the Office suite installed on your computer.

The Excel module is responsible for performing handling actions on Excel spreadsheet files. Its methods can be accessed as in the example below:

js
const excel = await Office.Excel.openWorkbook["v1_0_0"]({
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
});

Methods

openWorkbook

Method responsible for opening an Excel file.

js
await Office.Excel.openWorkbook["v1_0_0"]({
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
});

Required parameters

  • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

  • saveOnClose:Boolean - expects a boolean value indicating whether the spreadsheet will be saved after it is closed.
  • name:String - expects a string with the name of the spreadsheet tab.
  • options:Object - expects an object for the opening configuration of the Excel spreadsheet.
    • readOnly:Boolean - expects a boolean value.

Return

This method has no return.

createWorkbook

Method responsible for creating an Excel file.

js
await Office.Excel.createWorkbook["v1_0_0"]({
name: "Planilha",
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste2.xlsx",
},
});

Required parameters

  • name:String - expects a string with the name of the tab of the Excel spreadsheet.
  • workbook:Object - expects an object referring to the Excel spreadsheet.
    • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

saveWorkbook

Method responsible for saving an Excel file.

js
await Office.Excel.saveWorkbook["v1_0_0"]({
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
});

Required parameters

  • workbook:Object - expects an object referring to the Excel spreadsheet.
    • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

closeWorkbook

Method responsible for closing an Excel file.

js
await Office.Excel.closeWorkbook["v1_0_0"]({
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
});

Required parameters

  • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

createWorksheet

Method responsible for creating a tab in an Excel file.

js
await Office.Excel.createWorksheet["v1_0_0"]({
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
name: "teste",
});

Required parameters

  • name:String - expects a string with the name of the tab of the Excel spreadsheet.
  • workbook:Object - expects an object referring to the Excel spreadsheet.
    • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

renameWorksheet

Method responsible for renaming a tab of an Excel file.

js
await Office.Excel.renameWorksheet["v1_0_0"]({
newName: "teste2",
worksheet: {
name: "teste",
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
});

Required parameters

  • newName:String - expects a string with the new name of the tab of the Excel spreadsheet.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

selectWorksheet

Method responsible for selecting a tab of an Excel file.

js
const selectWorksheet = await Office.Excel.selectWorksheet["v1_0_0"]({
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
});

Required parameters

  • name:String - expects a string with the name of the tab of the Excel spreadsheet.
  • workbook:Object - expects an object referring to the Excel spreadsheet.
    • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return, but the constant created as selectWorksheet can be used in the other Excel actions to indicate which the target tab is.

getTableValues

Method responsible for getting every value of a table of an Excel tab.

js
const getAllTableValues = await actions.Office.Excel.getTableValues["v1_0_1"]({
name: `Table 1`,
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\igors\\Desktop\\teste.xlsx",
},
},
});

Required parameters

  • name:String - expects a string with the name of the table.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the getAllTableValues constant shown in the previous example, returns the values method, which receives a list with the values of the table.

js
actions.getAllTableValues.values;

getRawValuesFromWorksheet

Method responsible for getting every raw value of an Excel tab.

js
const getRawValuesFromWorksheet = await Office.Excel.getRawValuesFromWorksheet["v1_0_0"]({
worksheet: {
name: "Plan1",
workbook: {
filePath: "C:\\Users\\Roberty\\Desktop\\teste.xlsx",
},
},
ignoreEmptyRows: true,
});

Required parameters

  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.
  • ignoreEmptyRows:Boolean - expects a boolean value representing whether empty rows will be ignored or not.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the getRawValuesFromWorksheet constant shown in the previous example, returns the values method, which receives a list with the values of the table.

js
actions.getRawValuesFromWorksheet.values;

getAllValuesFromWorksheet

Method responsible for getting every value of an Excel tab.

js
const getAllCellValues = await Office.Excel.getAllValuesFromWorksheet["v1_0_0"](
{
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
}
);

Required parameters

  • name:String - expects a string with the name of the tab of the Excel spreadsheet.
  • workbook:Object - expects an object referring to the Excel spreadsheet.
    • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the getAllCellValues constant shown in the previous example, returns the values method, which receives a list with the values of the table.

js
actions.getAllCellValues.values;

getAllWorksheetName

Method responsible for getting every tab name of an Excel file.

js
const getAllWorksheets = await Office.Excel.getAllWorksheetName["v1_0_0"]({
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
});

Required parameters

  • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the getAllWorksheets constant shown in the previous example, returns the worksheets method, which receives a list with the values of the table.

js
actions.getAllWorksheets.values;

cloneWorksheet

Method responsible for cloning a tab of an Excel file.

js
await Office.Excel.cloneWorksheet["v1_0_0"]({
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
newName: `novaAba`,
});

Required parameters

  • newName:String - expects a string with the new name of the tab of the Excel spreadsheet.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

deleteWorksheet

Method responsible for deleting a tab of an Excel file.

js
await Office.Excel.deleteWorksheet["v1_0_0"]({
name: `novaAba`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
});

Required parameters

  • name:String - expects a string with the name of the tab of the Excel spreadsheet.
  • workbook:Object - expects an object referring to the Excel spreadsheet.
    • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

setCellValue

Method responsible for setting a value for a cell of an Excel file.

js
await Office.Excel.setCellValue["v1_0_0"]({
value: {
value: `teste`,
},
cell: {
position: {
column: `A`,
row: 1,
},
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
},
});

Required parameters

  • value:Object - expects an object referring to the value to be inserted into the cell.
    • value:String - expects a string with the value that will be inserted into the cell.
  • cell:Object - expects an object referring to the Excel spreadsheet.
    • position:Object - expects an object referring to the Excel spreadsheet.
      • column:String - expects a string with the new name of the tab of the Excel spreadsheet.
      • row:Number - expects a string with the new name of the tab of the Excel spreadsheet.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

  • value:Object - expects an object referring to the value to be inserted into the cell.
    • formula:String - expects a string with the formula that will be inserted into the cell.
  • lastRowColumn: Boolean - expects a true or false value; if true, it always fills in after the last filled cell of the column passed by the user in the column field.

Return

This method has no return.

setRowValues

Method responsible for setting a value for a cell of an Excel file.

js
await Office.Excel.setRowValues["v1_0_0"]({
values: [{value: `teste-1`},{value: `teste-2`}]
cell: {
position: {
column: `A`,
row: 1,
},
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
}
});

Required parameters

  • values:Array - expects an array of objects referring to the values to be inserted into each cell of the row. The object must contain the property below:
    • value:String - expects a string with the value that will be inserted into the cell. It is worth noting that it also works with formulas.
  • cell:Object - expects an object referring to the Excel spreadsheet.
    • position:Object - expects an object referring to the information necessary to fill in the row.
      • column:String - expects a string with the letter of the column where the filling will start.
      • row:Number - expects a number representing the row where the filling will start.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters:

  • lastRow: Boolean - expects a true or false value; if true, it always fills in after the last filled row of the spreadsheet.
  • lastRowColumn: Boolean - expects a true or false value; if true, it always fills in after the last filled row of the COLUMN passed by the user in the column field.

Return

This method has no return.

getCellValue

Method responsible for getting the value of a cell of an Excel file.

js
const getCellValue = await Office.Excel.getCellValue["v1_0_0"]({
position: {
column: `A`,
row: 1,
},
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
});

Required parameters

  • position:Object - expects an object referring to the cell position.
    • column:String - expects a string with the name of the desired column.
    • row:Number - expects a number referring to the value of the desired row.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created to receive the return of the method, such as the getCellValue constant shown in the previous example, returns the value and formula methods, which receive the value corresponding to the value in the cell.

js
actions.getCellValue.value;
actions.getCellValue.formula;

deleteColumn

Method responsible for deleting a column of a tab of an Excel file.

js
await Office.Excel.deleteColumn["v1_0_0"]({
column: `A`,
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
});

Required parameters

  • column:String - expects a string with the name of the desired column.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

deleteRow

Method responsible for deleting a row of a tab of an Excel file.

js
await Office.Excel.deleteRow["v1_0_0"]({
row: 1,
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
});

Required parameters

  • row:Number - expects a number referring to the value of the desired row.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

setCellStyle

Action responsible for creating a style for a cell of an Excel spreadsheet.

js
await Office.Excel.setCellComment["v1_0_0"]({
cell: {
position: {
column: 'A',
row: 1,
},
worksheet: {
name: 'teste',
workbook: {
filePath: 'C:/Users/nome-de-usuario/Desktop/teste.xlsx',
},
},
},
color: '#0fd3b1',
backgroundColor: '#473bfa',
});

Required parameters

  • color:String - expects a string with the hexadecimal value of the color of the text that will be inserted into the cell.
  • backgroundColor:String - expects a string with the hexadecimal value of the background color that will be inserted into the cell.
  • cell:Object - expects an object referring to the Excel spreadsheet.
    • position:Object - expects an object referring to the Excel spreadsheet.
      • column:String - expects a string with the new name of the tab of the Excel spreadsheet.
      • row:Number - expects a string with the new name of the tab of the Excel spreadsheet.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Return

This method has no return.

setCellComment

Action responsible for creating a comment in an Excel spreadsheet.

js
await Office.Excel.setCellComment["v1_0_0"]({
cell: {
position: {
column: 'A',
row: 1,
},
worksheet: {
name: 'teste',
workbook: {
filePath: 'C:/Users/nome-de-usuario/Desktop/teste.xlsx',
},
},
},
comment: 'teste',
});

Required parameters

  • comment:String - expects a string with the comment that will be inserted into the cell.
  • cell:Object - expects an object referring to the Excel spreadsheet.
    • position:Object - expects an object referring to the Excel spreadsheet.
      • column:String - expects a string with the new name of the tab of the Excel spreadsheet.
      • row:Number - expects a string with the new name of the tab of the Excel spreadsheet.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Return

This method has no return.

deleteCellComment

Action responsible for removing the comment from a cell of an Excel file.

js
await Office.Excel.deleteCellComment["v1_0_0"]({
cell:{
position: {
column: 'A',
row: 1,
},
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
}
});

Required parameters

  • cell:Object - expects an object referring to the cell whose comment will be removed.
    • position:Object - expects an object with the cell position.
      • column:String - expects a string with the name of the column (e.g. A, B, C).
      • row:Number - expects a number with the index of the row.
    • worksheet:Object - expects an object referring to the tab of the Excel spreadsheet.
      • name:String - expects a string with the name of the tab of the Excel spreadsheet.
      • workbook:Object - expects an object referring to the Excel spreadsheet.
        • filePath:String - expects a string with the path of the Excel spreadsheet.

Return

This method has no return.

addPicture

Method responsible for adding an image to a cell of an Excel file.

js
await Office.Excel.addPicture["v1_0_0"]({
cell: {
position: {
column: `A`,
row: 1,
},
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
},
name: `picture1`,
path: `C:\\Users\\nome-de-usuario\\Desktop\\teste.png`,
});

Required parameters

  • cell:Object - expects an object referring to the cell position.
    • position:Object - expects an object referring to the cell position.
      • column:String - expects a string with the name of the desired column.
      • row:Number - expects a number referring to the value of the desired row.
    • worksheet:Object - expects an object referring to the Excel spreadsheet.
      • name:String - expects a string with the name of the tab of the Excel spreadsheet.
      • workbook:Object - expects an object referring to the Excel spreadsheet.
        • filePath:String - expects a string with the path of the Excel spreadsheet.
  • name:String - expects a string with the desired name for the image.
  • path:String - expects a string with the path of the image that will be inserted.

Optional parameters

  • percentSize:Number - expects a number referring to the size, in percentage, the picture will have.

Return

This method has no return.

removeAllPictures

Method responsible for closing an Excel file.

js
await Office.Excel.removeAllPictures["v1_0_0"]({
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
});

Required parameters

  • name:String - expects a string with the name of the tab of the Excel spreadsheet.
  • workbook:Object - expects an object referring to the Excel spreadsheet.
    • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

removePicture

Method responsible for closing an Excel file.

js
await Office.Excel.removePicture["v1_0_0"]({
name: `picture1`,
worksheet: {
name: `teste`,
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
});

Required parameters

  • name:String - expects a string with the name of the image that will be removed from the Excel spreadsheet.
  • worksheet:Object - expects an object referring to the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

convertExcelToCSV

Method responsible for converting a tab of an excel file (.xlsx) into a comma-separated csv.

js
await Office.Excel.convertExcelToCSV["v1_0_0"]({
workbook: workbook,
saveFilePath: "C:\\Users\\nome-de-usuario\\Desktop\\arquivo.csv",
sheetName: `Plan1`
});

Required parameters

  • workbook: Workbook object - expects a spreadsheet object that can be obtained through the openWorkbook action;
  • saveFilePath: String - expects a path where the .csv file will be created and saved;
  • sheetName: String - expects the name of the tab that already exists in the spreadsheet and that will be turned into .csv.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

convertCSVToExcel

Method responsible for converting a .csv file into a .xslx file with a tab filled in with the CSV information. The tab created has the default name Plan1 in English or Planilha1 in Portuguese, depending on the default language of the user's machine.

js
await Office.Excel.convertCSVToExcel["v1_0_0"]({
csvPath: `C:\\Users\\Roberty\\Downloads\\arquivo.csv`,
excelPath: `C:\\Users\\Roberty\\Downloads\\excel.xlsx`
});

Required parameters

  • csvPath: String - expects a path where the .csv file that will be converted into a tab is.
  • excelPath: String - expects the path where the .xlsx file will be created.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

getRowValues

Method responsible for getting every value of a row of an Excel file.

js
const rowData = await Office.Excel.getRowValues["v1_0_0"]({
row: 1,
worksheet: {
name: "Plan1",
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
});

Required parameters

  • row:Number - expects a number with the index of the row whose values will be obtained.
  • worksheet:Object - expects an object referring to the tab of the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created, such as the rowData of the example shown earlier, receives the values of the row specified.

getRowCount

Method responsible for getting the total of filled rows in a tab of an Excel file.

js
const count = await Office.Excel.getRowCount["v1_0_0"]({
worksheet: {
name: "Plan1",
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
});

Required parameters

  • worksheet:Object - expects an object referring to the tab of the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

This method has no optional parameters.

Return

The constant or variable created, such as the count of the example shown earlier, receives a number representing the total of filled rows in the tab.

sortByRow

Method responsible for sorting the rows of a tab of an Excel file based on a column.

js
await Office.Excel.sortByRow["v1_0_0"]({
column: "A",
order: "ASC",
worksheet: {
name: "Plan1",
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsx",
},
},
});

Required parameters

  • column:String - expects a string with the name of the column that will be used as the sorting reference.
  • worksheet:Object - expects an object referring to the tab of the Excel spreadsheet.
    • name:String - expects a string with the name of the tab of the Excel spreadsheet.
    • workbook:Object - expects an object referring to the Excel spreadsheet.
      • filePath:String - expects a string with the path of the Excel spreadsheet.

Optional parameters

  • ignoreFirstRow:Boolean - when it is true, it ignores the first row (header) during the sorting. Default value: true.
  • order:String - defines the sorting direction. Default value: ASC. The possible values are:
    • ASC: ascending order.
    • DESC: descending order.

Return

This method has no return.

runMacro

Method responsible for executing a macro of an Excel file.

js
await Office.Excel.runMacro["v1_0_0"]({
macro: "NomeDaMacro",
workbook: {
filePath: "C:\\Users\\nome-de-usuario\\Desktop\\teste.xlsm",
},
});

Required parameters

  • macro:String - expects a string with the name of the macro that will be executed.
  • workbook:Object - expects an object referring to the Excel spreadsheet.
    • filePath:String - expects a string with the path of the Excel spreadsheet (it must be a macro-enabled .xlsm file).

Optional parameters

This method has no optional parameters.

Return

This method has no return.