I need to compare data of my excel file to the data shown in the web app as if they are matched or not. How can I do that?

  • Thread starter Thread starter Amna Khalid 001
  • Start date Start date
A

Amna Khalid 001

Guest
I have web application having a section report. I downloaded the report from report section in excel format. I want to open that downloaded file at the run time and compare the data of that excel to the values passing in my list. What I have done is to open already downloaded file which does not full fill my requirement. Want to open the downloaded file at the runtime and read values from that file and compare that values with the values passing in the list. How Can I do that?
bool control = true;
private bool show_messages = true;

[TestMethod]
public void TestExcel_RunExceldownload_OK()
{


//Arrange
List<string> lst1 = new List<string>() { 14/04/12020, "118585", "00:02", "A", "", "", "Social life", "Social life" };
show_messages = true;

//Acts
bool returnValue = Exceldownload(lst1);

//Assert
//Debug.Assert(returnValue == true);
}


private bool Exceldownload(List<string> lst)
{



string str;
int rw = 0;
int cl = 0;
bool returnValue = false;

Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
{
xlApp.Visible = true;
xlApp.DisplayAlerts = false;
}

Microsoft.Office.Interop.Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"path", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", false, false, 0, true, false, false);
xlApp.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMaximized;

Microsoft.Office.Interop.Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];

Microsoft.Office.Interop.Excel.Range xlRange = xlWorksheet.UsedRange;
rw = xlRange.Rows.Count;
cl = xlRange.Columns.Count;

for (int i = 1; i <= cl; i++)
{
str = Convert.ToString((xlRange.Cells[2, i] as Microsoft.Office.Interop.Excel.Range).Value2);
if (!lst[i - 1].Equals(str))
{
if (show_messages)
MessageBox.Show($"Not match in column: {i}");
control = false;
returnValue = false;
}
}
if (control)
{
returnValue = true;
if (show_messages)
MessageBox.Show($"All match");
}

xlWorkbook.Close(0);
xlApp.Quit();
return returnValue;
}

Continue reading...
 
Back
Top