Forum Discussion

endorium's avatar
endorium
Frequent Contributor
6 years ago

Retrieving specific value from excel

I have a function where I am trying to get the last value from the data in column 'A' in an excel spreadsheet. Still fairly new to this. Below it was i have but I cannot get it to work. I know It w...
  • shankar_r's avatar
    6 years ago

    Below code will retrieve you the last row 's column A value.

     

     

    function testas() {
        var strFileName = "D:\\Users\\sramasamy\\Desktop\\mass.xlsx";
        var sName = "Version";
    
        exObj = Sys.OleObject("Excel.Application");
        if (exObj == null) return;
        try {
            exObj.Workbooks.Open(strFileName);
            var sheetObj = exObj.Sheets(sName);
            var rCount = sheetObj.UsedRange.Rows.Count;
            Log.Message(sheetObj.Range("A" + rCount));
        } catch (ex) {
            Log.Error(ex.stack);
        } finally {
            if (exObj != null) exObj.Quit();
        }
    }