Forum Discussion

jcatayong's avatar
jcatayong
Contributor
7 years ago

Error on running the JScript to write data on Excel

function Main()
{
  var fileName = "<Path_To_The_File>";
  var sheetName = "Sheet1";
 
  WriteExcelSheet(fileName, sheetName)
}
 
function WriteExcelSheet(fname, sheetName)
{
  var maxcol = 5, maxrow = 5;
 
  var app = Sys.OleObject("Excel.Application");
 
  var book = app.Workbooks.Open(fname);
  var sheet = book.Sheets(sheetName);
  app.DisplayAlerts = false;
 
  // Write an index of the current row and column to a cell
  var rowCount = sheet.UsedRange.Rows.Count + 1;
  for(var row = rowCount; row < rowCount + maxrow; row++)
    for(var col = 1; col <= maxcol; col++)
      sheet.Cells(row, col) = row + ", " + col;
 
  book.Save();
  app.Quit();
}


Error book.Sheets is not a function.

 

1 Reply