xlApp = new Microsoft.Office.Interop.Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 2; cCnt <= range.Columns.Count; cCnt++)
{
if (Convert.ToString((range.Cells[rCnt, cCnt] as Microsoft.Office.Interop.Excel.Range).Value2) == productId) //condition to ge only those fields
{
Microsoft.Office.Interop.Excel.Range rng = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.get_Range(xlWorkSheet.Cells[rCnt - 1, 2], xlWorkSheet.Cells[rCnt, cCnt]); // getting those range cells
foreach (Range c in rng.Cells)
{
string changedCell = c.get_Address(Type.Missing, Type.Missing, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);
if (Convert.ToString(c.Value2) == "SomeValue")
{
}
}
}
I have an excel sheet where I'm retrieving a range of cells based on a condition,now in the if condition equals the somevalue and say the cell is B3, I want to get the value of B4 in that if condition,how can I do it
Aucun commentaire:
Enregistrer un commentaire