Ho do we find closest value from column wise of all cell instead of row wise of all cell using C#

  • Thread starter Thread starter Gani tpt
  • Start date Start date
G

Gani tpt

Guest
How do we find closest value from column wise of all cell instead of row wise of all cell using c#.

below is the code working find and it searches row wise. if we are using row wise, i may get some inappropriate values.

so we thought and need to change column wise. How do we change the below code.


Application xlApp = new Excel.Application();
Workbook xlWorkbook = xlApp.Workbooks.Open(@"D:\test\excel\4.xlsx");
Worksheet sheet = xlWorkbook.ActiveSheet;
try
{

//search row wise cell, but need column wise cell
object[,] data = sheet.Range[sheet.Cells[startRow, startColumn.ToString()], sheet.Cells[endRow, endColumn.ToString()]].Cells.Value2; // checking row wise

double closest = SearchArray(num, data);
Console.WriteLine(closest);

int intStartY = (int)startColumn - 64;
int intEndY = (int)endColumn - 64;
for (int j = intStartY; j <= intEndY; j++)
{
for (int i = startRow; i <= endRow; i++)
{
if (double.Parse(sheet.Cells[i, j].Value == null ? "0.0" : sheet.Cells[i, j].Value.ToString()) == closest)
{
int row = i;
char column = (char)(j + 64);
Console.WriteLine(row + " " + column);
break;
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
xlWorkbook.Close();
xlApp.Quit();
}

Continue reading...
 
Back
Top