Forum Discussion

weijiang's avatar
weijiang
Occasional Contributor
8 years ago

failed to set value then read value from excel

read several threads about read/set excel, however when I try to do it together, it doesn't work:

 

function _read_data(row,col) {

  var excel = Sys.WaitProcess('EXCEL');

  if (excel.Exists) excel.Terminate();

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

  ......

  app.Quit();

}

 

function _write_data(row,col,value) {

 

var excel = Sys.WaitProcess('EXCEL');

  if (excel.Exists) excel.Terminate();

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

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

  var sheet = book.Sheets("Sheet1");

  sheet.Cells(row,col) = value;

  book.save();

  ......

  app.Quit();

}

 

function read_data() {

  _read_data(1,1);

}

 

function write_data() {

  _write_data(1,1,"hello");

}

 

function test() {

  _write_data(1,1,"hi");

  _read_data(1,1);

}

 

Run read_data() or write_data() separately, it works fine. However when I run test(), it doesn't do anything and no log printed. Please anyone could help?

No RepliesBe the first to reply