anumolu9999
6 years agoContributor
Working With Excel Files via COM: set required sheet as active using javascript
I am using excel, which has two sheets. I have to use COM to read excel because of microsoft access database issue.
I have to access the second sheet in the excel based on its name.
Code is as below
var Excel = getActiveXObject("Excel.Application");
Excel.Workbooks.Open(excelPath);
var excel_sheet = Excel.workbook.worksheets.getItem("sheetname");
excel_sheet.activate();
Log.Message(Excel.Cells.Item(1, 1));
I am getting error at '
var excel_sheet = Excel.workbook.worksheets.getItem("sheetname");
Error is showing as
JavaScript runtime error.
TypeError: Cannot read property 'worksheets' of undefined
TypeError: Cannot read property 'worksheets' of undefined
Thank you,
Anumolu.
Try this out,
filePath="C:\Users\sebastian\Desktop\Sample.xlsx";
SheetName="Sheet2";
Excelbook= Excel.Workbooks.Open(filePath);
var xlsheet = Excel.ActiveWorkBook.WorkSheets.Item(SheetName);I am using the aove and its working