Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Normally, you add values inside the Table or List Object using the Cell.PutValue() method. But sometimes, you might need to add values inside the Table or List Object using row and column offsets.
In order to access a Table or List Object from a cell, use the Cell.GetTable() method. To add values inside it using row and column offsets, use the ListObject.PutCellValue method.
The following screenshot shows the source Excel file used in the code. It contains an empty table and highlights cell D5, which lies inside the table. We will access this table from cell D5 using the Cell.GetTable() method and then add values inside it using both the Cell.PutValue() and ListObject.PutCellValue methods.
![]() |
|---|
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, also has a value.
![]() |
|---|
The following sample code loads the source Excel file as shown in the above screenshot, adds values inside the table, and generates the output Excel file as shown above.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Create workbook from source Excel file
Workbook workbook(srcDir + u"source.xlsx");
// Access first worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Access cell D5 which lies inside the table
Cell cell = worksheet.GetCells().Get(u"D5");
// Put a value inside cell D5
cell.PutValue(u"D5 Data");
// Access the table from this cell
ListObject table = cell.GetTable();
// Add a value using row and column offset
table.PutCellValue(2, 2, u"Offset [2,2]");
// Save the workbook
workbook.Save(outDir + u"output_out.xlsx");
std::cout << "Workbook saved successfully." << std::endl;
Aspose::Cells::Cleanup();
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.