Looking for nth column from a certain column

I am writing a program where based on the data I receive I need to look for nth column from a certain column. How can I do that?

Example - column L is the base column. If data is 1, I need to write in column M. If data is 2, column N, data 3 column O, data 10 column V, data 20 column AF, and so on. Hope I painted the picture well.

Appreciate any help. Thanks.

Hi,

Thanks for your posting and using Aspose.Cells.

Please see the following sample code that achieves your requirements. Please change the values of base column and data column and the code will automatically calculate the target column and its name.

I have also attached the output excel file generated by the code for your reference. Please read the comments inside the code for more clarification.

C#

//This is your base column
int baseColumn = CellsHelper.ColumnNameToIndex(“L”);

//This is your data column
int dataColumn = 3;

//Calculate your target column index and name
int targetColumn = baseColumn + dataColumn;
string targetColumnName = CellsHelper.ColumnIndexToName(baseColumn + dataColumn);

//---------------------------------------------

//Create workbook
Workbook workbook = new Workbook();

//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];

//Now you can write to target column with target column index
for(int i=0; i<10; i++)
{
worksheet.Cells[i, targetColumn].PutValue(i);
}

//You can also use target column name to write data into
for (int i=10; i < 20; i++)
{
string cellName = targetColumnName + (i + 1);
worksheet.Cells[cellName].PutValue(i);
}

//Save the workbook
workbook.Save(“output.xlsx”);

Thank you very much Shakeel. Appreciate it!!