hello sir
How to read dynamic rows and there cell from excel using CLosedXml using asp.net
i am facing an issue while reading data from excel using closedXml. i have a requirement suppose i have an excel if the excel rows will start from first row then no issue is there but suppose in excel i want to read from 4th row or any starting row that row will read and read that rows cell also not first rows cell in my code i am able to access from 3'rd row but cell is reading from first row. in my case i want to give dynamic rows like row will read from 3rd row and there 3rd row cell ignore 1 and 2nd row data even in first or second rows have data.
Please give me solution
foreach (IXLRow row in rows)
{
if (FirstRow == Rnumber)
{
AddQuery += "IF OBJECT_ID('dbo." + map.FileName + "', 'U') IS NULL ";
AddQuery += "BEGIN ";
AddQuery += "CREATE TABLE [dbo].[" + map.FileName + "](";
// AddQuery += "id int identity , ";
try
{
//foreach (IXLCell cell in row.Cells())
foreach (IXLCell cell in row.Cells(row.FirstCellUsed().Address.ColumnNumber, row.LastCellUsed().Address.ColumnNumber))
{
if (cell.Value.ToString() != "")
{
dt.Columns.Add(cell.Value.ToString());
//AddQuery += "[" + cell.Value.ToString() + "]" + " VARCHAR(MAX),";
AddQuery += "[" + RemoveSpecialCharacters(cell.Value.ToString()) + "]" + " VARCHAR(MAX),";
var DtMsrcFld = obj.InsertMainSrcField(map.FileName, RemoveSpecialCharacters(cell.Value.ToString()), cell.Value.ToString());
}
}
AddQuery = AddQuery.TrimEnd(',');
AddQuery += ")";
AddQuery += " END";
//RowNumber++;
//firstRow = false;
FirstRow++;
}
catch (Exception e)
{
FirstRow++;
errrornum = 1;
var response = e.Message;
}
}
else
{
if (errrornum==1)
{
break;
}
dt.Rows.Add();
int i = 0;
try
{
//foreach (IXLCell cell in row.Cells())
foreach (IXLCell cell in row.Cells(row.FirstCellUsed().Address.ColumnNumber, row.LastCellUsed().Address.ColumnNumber))
{
i = (int)GetColumnIndexFromName(GetColumnName(cell.Address.ToString()));
dt.Rows[dt.Rows.Count - 1][i - 1] = cell.Value.ToString();
}
}
catch (Exception ee)
{
ee.ToString();
}
}
}
Rnumber is coming from textbox that is row number from which row i am going to read data.