Forum Discussion

deepa_samota's avatar
deepa_samota
Contributor
2 years ago

Getting error message when trying to read CSV and XLSX file

I am using following script code for reading CSV and XLSX file.

Issue with Excel File :

JavaScript runtime error.
External table is not in the expected format


function GetCol1Unique()
{
var MyExcelRecords;
var fileName = "C:\\Users\\"+Sys.UserName+"\\Downloads\\data.xlsx";
MyExcelRecords = DDT.ExcelDriver(fileName,"Export",true)
MyExcelRecords.ADOCommandObject.CommandText = "SELECT DISTINCT [Policy ID] from [Export$]";
var rowCount=0;
while (!MyExcelRecords.EOF())
{
rowCount++;
MyExcelRecords.Next();
}
Log.Message(rowCount);
DDT.CloseDriver(MyExcelRecords.Name);
}

 

Issue with CSV File
In CSV file reading we are getting error :Database object is read only”.

var latestFile.Path = "C:\\Users\\"+Sys.UserName+"\\Downloads\\data.csv";

if (aqFile.Exists(latestFile.Path))
{
var csvFile =DDT.CSVDriver(latestFile.Path)
var count =0;
while (!csvFile.EOF())
{
count++;
csvFile.Next();
}

Log.Message(count);
DDT.CloseDriver(csvFile.Name);
}

 

16 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    There's nothing wrong with the file, it opens fine in Excel.

     

    • deepa_samota's avatar
      deepa_samota
      Contributor

      After saving file trying to open that time getting error

       

      aqFile.WriteToTextFile(latestFile.ParentFolder.Path+ "\\test.xls", m, aqFile.ctUTF8);
      myFile.Close();
      var excelFile = Excel.Open("C:\\temp\\3359398_a978ca61-4470-42ba-83fe-73c98ca22748\\test.xls");

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    An Excel file (.xls) is different from a text file. They are two different formats

     

    WriteToTextFile method opens a text file using the specified character encoding and writes text to it either appending to or replacing the current contents.