Forum Discussion

shane_manjunath's avatar
shane_manjunath
Occasional Contributor
9 years ago
Solved

How to write into excel file using Javascript?

I have written the following javascript to write into excel.However "book.Sheets" doesn't seem to exist so I am unable to create sheet object

 

Also when It tries to execute the code - app.Cells(1,1) = "test"; --- get the error that the function does not exist

 

var fileName = "C:\\Files\\test.xlsx";
var sheetName = "Sheet1";

 

var app = Sys.OleObject("Excel.Application")

app.Visible = "True";

var book = app.Workbooks.Open(fileName);

var sheet = book.Sheets(sheetName);

 

rowCount = app.ActiveSheet.UsedRange.Rows.Count + 1;
colCount = 1;

app.Cells(1,1) = "test";

 

Please suggest if I am missing anything?Thanks in advance