CalculationData.CellColumn
CalculationData.CellColumn property
Gets the column index of the cell where the function is.
public int CellColumn { get; }
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using System;
public class CalculationDataPropertyCellColumnDemo
{
public static void Run()
{
try
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
// Add sample data with formulas in different columns
worksheet.Cells["A1"].PutValue(10);
worksheet.Cells["B1"].PutValue(20);
worksheet.Cells["C1"].Formula = "=SUM(A1:B1)";
// Create calculation options with custom engine
CalculationOptions options = new CalculationOptions();
options.CustomEngine = new CellColumnDemoEngine();
// Calculate formulas
workbook.CalculateFormula(options);
// Display the calculated result
Console.WriteLine("Calculated value in C1: " + worksheet.Cells["C1"].Value);
// Save the result
workbook.Save("CellColumnDemo.xlsx");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
public class CellColumnDemoEngine : AbstractCalculationEngine
{
public override void Calculate(CalculationData data)
{
if (data != null)
{
// Access the read-only CellColumn property
int columnIndex = data.CellColumn;
Console.WriteLine($"Function is in column index: {columnIndex}");
// Demonstrate using the column information
if (data.FunctionName == "SUM")
{
double sum = 0;
for (int i = 0; i < data.ParamCount; i++)
{
object arg = data.GetParamValue(i);
if (arg is double)
{
sum += (double)arg;
}
}
data.CalculatedValue = sum;
}
}
}
}
}
See Also
- class CalculationData
- namespace Aspose.Cells
- assembly Aspose.Cells