简体   繁体   中英

How to call multi-parameter Excel-ActiveX function

I already posted a question about writing a range at once from a Javascript array to an excel sheet through Internet Explorer (using ActiveX objects), because although this can be done cell by cell, this cell-by-cell method is unacceptably slow, so the range has to be written at once.

Unfortunately, though brilliant this site may be, nobody has given me the answer to my problem (sigh!).

So I tried something else: From the aspx sheet, on client side, I write my csv stack (the one I desperately want to write to an instantly opening excel file) as a CSV file on the local client disk. This works all right, and if I open the CSV file through Excel, I can see it immediately and correctly parsed. Good...

But the fact is that I want the user to get this CSV file immediately in an Excel window as soon as he has clicked the Excel icon on my apsx page, instead of having to swap to his file Explorer and borely navigate to fetch the CSV file by himself.

So, I intend to use the "Open" method of the Excel ActiveX object, with parameters precising it has to be csv-parsed with a semicolon: So, I use the following instructions:

<script type='text/javascript'>
   applic = new ActiveXObject("Excel.Application");
   classeur = applic.Workbooks.Open(nomFichier,"","","4");
</script>

And now, another problem occurs (will I have to hate Microsoft in the end?): It seems that with Javascript, I can't use multiparameters call on then ActiveX functions, because I also tried with "OpenText" and had the same problem:

The instruction:

classeur = applic.Workbooks.Open(nomFichier)

works all right, but as soon as I add at least a second parameter, like this:

classeur = applic.Workbooks.Open(nomFichier,"")

My navigator fails!

So I go back to my first problem, still not able to parse my csv stack in an Excel range at once...

So here's my question: Is there a special syntax that I don't know, that allows to pass several parameters from Javascript to an Activex function?

I hope I'll be more lucky this time with you all clever guys out there...

Thank you.

Well, in the end I found the answer to my question about actveX syntax: Though the parameters are defined as "Variant" by Microsoft, one has to notice 2 things: 1) Javascript doesn't allow blank parameters, like this for example:

 classeur = applic.Workbooks.Open(nomFichier,,,4);  // false Javascript syntax 

This is the reason why I placed empty strings. But the other problem comes from the ActiveX call: 2) ActiveX doesn't accept empty string instead of Variant parameters, like this:

 classeur = applic.Workbooks.Open(nomFichier,"","","4"); // false ActiveX syntax

And in fact, when I tried the following syntax, my function worked all right:

classeur = applic.Workbooks.Open(nomFichier,2,false,4);  // accepted syntax

So it was not the number of parameters that raised a problem, but just the combined restrictions of javascript and ActiveX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM