Cell just below a selected cell

Hi,

I've populated my sheet with some headers, eg,

FirstName LastName Age

Now, I want to get the cell from where I will start populating the data. Is there a simple way to do that.

An example would be; Lets say

A1 has FirstName, B1 has LastName, and C1 has Age. Ideally I would like to start populating data from datatable from (A1 + 1) A2 onwards. But at runtime, to find where the data should be populated would be; I can take the following approach,

1. Find the cell number where FirstName exist

2. The cell from where, I should be populating the data would be Cellnumber in step 1 + (Number of rows I would ideally like to leave blank).

Is there any existing property which exposes this?


This message was posted using Aspose.Live 2 Forum

Hi,

I think your approach is OK. You should find the cell containing the data “FirstName” first, then get the row of that cell, you may add number of rows to that cell to get your start index for filling the data table and finally, import the data table starting at your desired position in the sheet.

Here is the sample code if it helps you implement your desired task. I have also attached the input file here.

Sample code:

DataTable dt = new DataTable(“Customers”);
dt.Columns.Add(“C_FName”);
dt.Columns.Add(“C_LName”);
dt.Columns.Add(“C_Age”, typeof(decimal));
DataRow dr = dt.NewRow();
dr[“C_FName”] = “Richard”;
dr[“C_LName”] = “Milton”;
dr[“C_Age”] = 45;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[“C_FName”] = “Micheal”;
dr[“C_LName”] = “Dowdan”;
dr[“C_Age”] = 41;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[“C_FName”] = “ABC”;
dr[“C_LName”] = “DEF”;
dr[“C_Age”] = 39;
dt.Rows.Add(dr);

Workbook workbook = new Workbook();
workbook.Open(@“e:\test\MySpecificBook.xls”);
Worksheet worksheet = workbook.Worksheets[0];

//Search the “FirstName” cell in the first sheet.
Aspose.Cells.Cell fcell = worksheet.Cells.FindString(“FirstName”, null);

//Populate the data starting from the row next to the “FirstName” cell in the same column.
worksheet.Cells.ImportDataTable(dt, false, fcell.Row +1,fcell.Column);

workbook.Save(“e:\test\out_MySpecificBook.xls”);


Thank you.