Accessing Table from Cell and Adding Values inside it using Row and Column Offsets with Node.js via C++
Normally, you add values inside the Table or List Object using Cell.putValue(boolean) method. But sometimes, you might need to add values inside the Table or List Object using the row and column offsets.
In order to access Table or List Object from a cell, use the Cell.getTable() method. To add values inside it using the row and column offsets, use the ListObject.putCellValue(number, number, object) method.
The following screenshot shows the source Excel file used inside the code. It contains the empty table and highlights the cell D5 which lies inside the table. We will access this table from cell D5 using Cell.getTable() method and then add the values inside it using both Cell.putValue(boolean) and ListObject.putCellValue(number, number, object) methods.
Example
Screenshots comparing the source and output files
![]() |
---|
The following screenshot shows the output Excel file generated by the code. As you can see cell D5 has a value and cell F6 which is at the offset 2,2 of the table has a value.
![]() |
---|
Node.js code to access table from cell and to add values inside it using row and column offsets
The following sample code loads the source Excel file as shown in the above screenshot and adds values inside the table and generates the output Excel file as shown above.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Create workbook from source Excel file
const workbook = new AsposeCells.Workbook(path.join(dataDir, "Accessing_Table.xlsx"));
// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Access cell D5 which lies inside the table
const cell = worksheet.getCells().get("D5");
// Put value inside the cell D5
cell.putValue("D5 Data");
// Access the Table from this cell
const table = cell.getTable();
// Add some value using Row and Column Offset
table.putCellValue(2, 2, "Offset [2,2]");
// Save the workbook
workbook.save(path.join(dataDir, "output_out.xlsx"));