Excel.TableRow class
Represents a row in a table.
Note that unlike ranges or columns, which will adjust if new rows or columns are added before them, a TableRow
object represents the physical location of the table row, but not the data. That is, if the data is sorted or if new rows are added, a table row will continue to point at the index for which it was created.
- Extends
Remarks
Properties
context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
index | Returns the index number of the row within the rows collection of the table. Zero-indexed. |
values | Represents the raw values of the specified range. The data returned could be a string, number, or boolean. Cells that contain an error will return the error string. If the returned value starts with a plus ("+"), minus ("-"), or equal sign ("="), Excel interprets this value as a formula. |
values |
A JSON representation of the values in the cells in this table row. Unlike |
values |
A JSON representation of the values in the cells in this table row. Unlike |
Methods
delete() | Deletes the row from the table. |
get |
Returns the range object associated with the entire row. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
set(properties, options) | Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type. |
set(properties) | Sets multiple properties on the object at the same time, based on an existing loaded object. |
toJSON() | Overrides the JavaScript |
Property Details
context
The request context associated with the object. This connects the add-in's process to the Office host application's process.
context: RequestContext;
Property Value
index
Returns the index number of the row within the rows collection of the table. Zero-indexed.
readonly index: number;
Property Value
number
Remarks
values
Represents the raw values of the specified range. The data returned could be a string, number, or boolean. Cells that contain an error will return the error string. If the returned value starts with a plus ("+"), minus ("-"), or equal sign ("="), Excel interprets this value as a formula.
values: any[][];
Property Value
any[][]
Remarks
valuesAsJson
A JSON representation of the values in the cells in this table row. Unlike TableRow.values
, TableRow.valuesAsJson
supports all data types which can be in a cell. Examples include formatted number values and web images, in addition to the standard boolean, number, and string values. Data returned from this API always aligns with the en-US locale. To retrieve data in the user's display locale, use TableRow.valuesAsJsonLocal
.
valuesAsJson: CellValue[][];
Property Value
Excel.CellValue[][]
Remarks
valuesAsJsonLocal
A JSON representation of the values in the cells in this table row. Unlike TableRow.values
, TableRow.valuesAsJsonLocal
supports all data types which can be in a cell. Examples include formatted number values and web images, in addition to the standard boolean, number, and string values. Data returned from this API always aligns with the user's display locale. To retrieve data independent of locale, use TableRow.valuesAsJson
.
valuesAsJsonLocal: CellValue[][];
Property Value
Excel.CellValue[][]
Remarks
Method Details
delete()
Deletes the row from the table.
delete(): void;
Returns
void
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const row = context.workbook.tables.getItem(tableName).rows.getItemAt(2);
row.delete();
await context.sync();
});
getRange()
Returns the range object associated with the entire row.
getRange(): Excel.Range;
Returns
Remarks
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const row = context.workbook.tables.getItem(tableName).rows.getItemAt(0);
const rowRange = row.getRange();
rowRange.load('address');
await context.sync();
console.log(rowRange.address);
});
load(options)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(options?: Excel.Interfaces.TableRowLoadOptions): Excel.TableRow;
Parameters
Provides options for which properties of the object to load.
Returns
load(propertyNames)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNames?: string | string[]): Excel.TableRow;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
Examples
await Excel.run(async (context) => {
const tableName = 'Table1';
const row = context.workbook.tables.getItem(tableName).rows.getItemAt(0);
row.load('index');
await context.sync();
console.log(row.index);
});
load(propertyNamesAndPaths)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Excel.TableRow;
Parameters
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select
is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand
is a comma-delimited string that specifies the navigation properties to load.
Returns
set(properties, options)
Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.
set(properties: Interfaces.TableRowUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Excel.Interfaces.TableRowUpdateData
A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.
- options
- OfficeExtension.UpdateOptions
Provides an option to suppress errors if the properties object tries to set any read-only properties.
Returns
void
set(properties)
Sets multiple properties on the object at the same time, based on an existing loaded object.
set(properties: Excel.TableRow): void;
Parameters
- properties
- Excel.TableRow
Returns
void
toJSON()
Overrides the JavaScript toJSON()
method in order to provide more useful output when an API object is passed to JSON.stringify()
. (JSON.stringify
, in turn, calls the toJSON
method of the object that is passed to it.) Whereas the original Excel.TableRow
object is an API object, the toJSON
method returns a plain JavaScript object (typed as Excel.Interfaces.TableRowData
) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Excel.Interfaces.TableRowData;
Returns
Office Add-ins