Forum Discussion

iamraj09's avatar
iamraj09
Contributor
10 years ago

How to read and write on the same excel file simultaneously

Hello Everyone,

 

Right now, I am working on few test cases... where it reads the data from an excel and update the results on to the excel file. 

 

Requirement is:

It should read the test input ->perform test case->Update the output(In the same excel file)->read test input->perform test case->Update the output(In the same  excel file).......so on 

 

The problem what I am facing here is, it is not updating the results on to the same excel file instead a copy is been created and the results are saved in that excel file. 

 

________________My Code for reading inputs from Excel________________

 

var TestCount;
var Excel_Launch = Sys["OleObject"]("Excel.Application");

Excel_Launch["Workbooks"]["Open"](ProjectSuite["Path"]+"\\Inputs\\Worksheet.xlsx");
Excel_Launch["Visible"]=true;
Book=Excel_Launch.Sheets("Tabelle1");
Delay(2000);
Excel_Launch.DisplayAlerts=false;
TestCount=Excel_Launch.Cells(2,7).text;              //This line reads the required input ....

 

 

 

___________________Code for Writing Results___________________

 

 

 

Excel_Launch = Sys["OleObject"]("Excel.Application");
Excel_Launch["Visible"]=true;
Delay(2000);
Book=Excel_Launch.Sheets("Tabelle1");

Excel_Launch.DisplayAlerts=false;

var x =Excel_Launch.Cells(2, 7).Text;
Count=x.toString();
Log.Message(Count);

if(Count==1)
{
Book.Cells(40,1)="Time taken for Opening a project is ";
Book.Cells(40,2)= Time;                  // This is the variable ....which hold the time from the Stopwatch.... 
Book["Save"]("Worksheet");
Delay(1000);
}

 

Please guide me through....

 

Thanks

Guru

 

  • I think you need to use the 'SaveAs' method passing in the name of the existing Excel workbook.

    Book["SaveAs"]("c://temp//sample//TEST.xls"); 

  • I think you need to use the 'SaveAs' method passing in the name of the existing Excel workbook.

    Book["SaveAs"]("c://temp//sample//TEST.xls");