Ask a Question

Read table from windows application and write to file

kaivi
Contributor

Read table from windows application and write to file

Hey,

 

i wanna read a table from a windows application and write it to a .txt file. What i have for now is following:

function list_to_String(){
  var row = Aliases.XXX.MainForm.radPanel1.MainPageView.tabCylinder.gvCylinder.wRowCount;
  var column = Aliases.XXX.MainForm.radPanel1.MainPageView.tabCylinder.gvCylinder.wColumnCount;
  Log.Message(row);
  Log.Message(column);
  for(var x = 0; x <= row-1; x++){
    for(var y = 0; y <= column-1; y++){
      cellContent = Aliases.CES_CyproAssist_TBInfo.MainForm.radPanel1.MainPageView.tabCylinder.gvCylinder.wValue(x,y);
      Log.Message(cellContent);
      aqFile.WriteToTextFile("C:\\Users\\XXX\\Desktop\\TestComplete.txt", cellContent, aqFile.ctANSI, false);
      aqFile.WriteToTextFile("C:\\Users\\XXX\\Desktop\\TestComplete.txt", ";", aqFile.ctANSI, false);
    }
  } 
}

So i have a file with the values from all cells in one .txt row.

 

Question:

Is there a better way to do it?

How can i add a [Enter] after each row?

aqFile.WriteToTextFile("C:\\Users\\XXX\\Desktop\\TestComplete.txt", '\r\n', aqFile.ctANSI, false);

 

best regards

 

Kai

 

1 REPLY 1
shankar_r
Community Hero

One suggestion would be 

 

function list_to_String(){
  var row = Aliases.XXX.MainForm.radPanel1.MainPageView.tabCylinder.gvCylinder.wRowCount;
  var column = Aliases.XXX.MainForm.radPanel1.MainPageView.tabCylinder.gvCylinder.wColumnCount;
  Log.Message(row);
  Log.Message(column);
  for(var x = 0; x <= row-1; x++){
  for(var x = 0; x < row; x++){
    for(var y = 0; y <= column-1; y++){
    for(var y = 0; y < column; y++){
      cellContent = Aliases.CES_CyproAssist_TBInfo.MainForm.radPanel1.MainPageView.tabCylinder.gvCylinder.wValue(x,y);
      Log.Message(cellContent);
      aqFile.WriteToTextFile("C:\\Users\\XXX\\Desktop\\TestComplete.txt", cellContent, aqFile.ctANSI, false);
      aqFile.WriteToTextFile("C:\\Users\\XXX\\Desktop\\TestComplete.txt", ";", aqFile.ctANSI, false);
      aqFile.WriteToTextFile("C:\\Users\\XXX\\Desktop\\TestComplete.txt", cellContent + ";\r\n", aqFile.ctANSI, false);
    }
  } 
}

 Also, if you are creating functions like this then make dynamic like below,

 

function testmyCode(){
	uTableToTextFile(Aliases.XXX.MainForm.radPanel1.MainPageView.tabCylinder.gvCylinder,"C:\\Users\\XXX\\Desktop\\TestComplete.txt");
}
function uTableToTextFile(tblObject,filePath){
  if(tblObject.Exists){
	  Log.Message("Row count " + tblObject.wRowCount);
	  Log.Message("Column count " + tblObject.wColumnCount);
	  var resultStr = "";
	  //To print column names
	  for(var c = 0; c < tblObject.wColumnCount; c++){
		resultStr += tblObject.ColumnName(c) + "|";
	  }
	  for(var x = 0; x < tblObject.wRowCount; x++){
		resultStr += "\r\n";
		for(var y = 0; y < tblObject.wColumnCount; y++){
		  resultStr += tblObject.wValue(x,y) + ",";
		}
	  } 
	  aqFile.WriteToTextFile(filePath, resultStr, aqFile.ctANSI, true);
  }
}

 


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

cancel
Showing results for 
Search instead for 
Did you mean: