ActiveXObject Excel Close Problem

700 views
Skip to first unread message

Niculescu Ionut

unread,
Dec 13, 2017, 6:24:59 AM12/13/17
to Softone Developers Network
Hi guys,

I am trying to use javascript and Excel.Application activeX to read an excel file. Everything works, read the file, read data from sheets but when I try to close the workbook, S1 throws an error.

I tried with the standard javascript commands that works outside S1

ExcelSheet.Application.Quit();
or
    Workbook.Close();
or
    excelApplication.Quit();


It always throws an error: " Could not convert variant of type (Dispatch) into type (OleStr)"

The problem is that the Excel.exe process remains active with the file opened and it is not ok if I do no close the file properly....


Did anyone had the same problem or knows a solution for closing the excel file in S1?

Thank You for your help,
Ionut

Κώστας Βάππας

unread,
Dec 13, 2017, 6:58:35 AM12/13/17
to Softone Developers Network
Hi,

try this


   vExcel=new ActiveXObject('Excel.Application');
   vExcel.Visible=true;
   vWB=vExcel.Workbooks;
   vWB.Open(CCCFXQIMP.FILENAME, false, true);
   //vSheet=vExcel.Sheets(1);
   //vSheet.Select();
   //vMaxRow=GetMaxRow();
   //vDataArray=new Array(vSheet.Range('A'+vFirstRow+':'+vMaxColumnName+vMaxRow));
   //vDataArray=vDataArray[0].Value.toArray();
   vExcel.Application.DisplayAlerts=false;
   vWB.Close();
   vExcel.Application.DisplayAlerts=true;
   vExcel.Application.Quit();

Niculescu Ionut

unread,
Dec 13, 2017, 7:18:33 AM12/13/17
to Softone Developers Network
Hi Kostas,
Thank You for your very quick response to this.

I tried the following:

var excel = new ActiveXObject ("Excel.Application"); 
excel.Visible=true;
book = excel.Workbooks;
// book.Open("D:\\1\\1.xls ", 2, true, null, null, null, false, null, null, false, false, null, null, null, null);

book.Open("D:\\1\\1.xls", false, true);
sheet=excel.Sheets(1);
sheet.Select();
var value = sheet.Range ("A1");
   excel.Application.DisplayAlerts = false;
   book.Close();
   excel.Application.DisplayAlerts=true;
   excel.Application.Quit();
   
X.WARNING (value);

and it throws the same error when it gets to book.Close(); part.... ( Could not convert variant of type (Dispatch) into type (OleStr) )




salesioti...@gmail.com

unread,
Dec 13, 2017, 3:59:08 PM12/13/17
to Softone Developers Network
Hallo Ionut, 

It seems that the problem lies on the line 

X.WARNING (value);

WARNING function is trying to cast "value" variable into a string and apparently this fails. 

Use var value = sheet.Range ("A1").value instead.

Niculescu Ionut

unread,
Dec 14, 2017, 3:55:56 AM12/14/17
to Softone Developers Network
Hi,
Yes indeed, if I leave the range () without .value it throws that error when closing the file. 

Thank You, I would never thought that would be the problem!

All the best,
Ionut


Wednesday, December 13, 2017, 22:59:08 UTC + 2, salesioti ... @ gmail.com wrote:
Hallo Ionut, 

It seems that the problem lies on the line 

X.WARNING (value);

The WARNING function is trying to cast a "value" variable into a string and apparently this fails. 
Reply all
Reply to author
Forward
0 new messages