Utilizing JavaScript to interact with MATLAB as a COM Automation Server

Struggling to create a link between Matlab and a Javascript (specifically typescript) program using a COM automation server, as recommended on the MathWorks website. While the documentation provides examples for certain languages supported by Microsoft, there is limited guidance for implementing this connection in JavaScript.

The challenge lies in establishing a COM connection with JavaScript, particularly given its association with Internet Explorer, an outdated feature from the past. This poses an issue since I am developing a VS Code extension that does not rely on Internet Explorer or ActiveXObjects.

Dilemma
My main concern is finding an alternative method to connect my typescript code to the Matlab instance without depending on deprecated technologies like ActiveXObjects.

Objective
The objective is to execute Matlab scripts in the VS Code terminal without launching a separate Matlab interface. The desired output should also be displayed within the VS Code terminal itself. Although this can be achieved effortlessly on MacOS and Linux through CLI tools, Windows presents compatibility challenges due to the platform-specific differences.

Answer №1

My experience with TypeScript is limited, as I haven't used it much and the little exposure I had was a while back when it was still new.

Despite that, I discovered that the NPM package win32ole is compatible with NodeJS, leading me to believe it should work with TypeScript as well, possibly with some adjustments to the code or by creating a small wrapper around it.

win32ole npm page

This code snippet from the page demonstrates how to utilize win32ole to interact with Excel for creating and saving a worksheet.

try{
  var win32ole = require('win32ole');
  // var xl = new ActiveXObject('Excel.Application'); // You may write it as:
  var xl = win32ole.client.Dispatch('Excel.Application');
  xl.Visible = true;
  var book = xl.Workbooks.Add();
  var sheet = book.Worksheets(1);
  try{
    sheet.Name = 'sheetnameA utf8';
    sheet.Cells(1, 2).Value = 'test utf8';
    var rg = sheet.Range(sheet.Cells(2, 2), sheet.Cells(4, 4));
    rg.RowHeight = 5.18;
    rg.ColumnWidth = 0.58;
    rg.Interior.ColorIndex = 6; // Yellow
    var result = book.SaveAs('testfileutf8.xls');
    console.log(result);
  }catch(e){
    console.log('(exception cached)\n' + e);
  }
  xl.ScreenUpdating = true;
  xl.Workbooks.Close();
  xl.Quit();
}catch(e){
  console.log('*** exception cached ***\n' + e);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using React with TypeScript to iterate over an array and add corresponding values from an object based on a common key

When working with regular JavaScript, I can achieve the following... var array1 = ['one', 'two', 'three', 'four']; var object = { one: 'apple', two: 'orange', three: 'peach', fo ...

Guide to uploading information when a user enters three characters in the Kendo dropdown menu in Angular

When a user types 3 letters in the search box of my Kendo dropdown, I want to load data into the dropdown using an API call. I've attempted it this way, but it's not working correctly. Can someone provide me with the correct solution? .ts publ ...

Issue encountered while attempting to add .js.map file to AngularJs DateTimepicker within pug template

I am currently using a MEAN stack environment and encountered an issue while attempting to integrate a third-party extension into AngularJS material. Our main view is based on a PUG template where we define all dependencies. Within it, I have included the ...

Can you explain the purpose of the argument provided to @Resolver in type-graphql?

I'm genuinely curious about something. I noticed on the type-graphql documentation website that they include an argument in the @Resolver decorator. You can see this in action on their page here: (look under the "Resolvers" section). Here is a snipp ...

What is the reasoning behind TypeScript's decision to permit implicit downcasting in method parameters?

Consider the following example: interface Vehicle{ mass:number } interface InspectorClass{ inspect(v:Vehicle):void } class Car implements Vehicle{ mass = 2000 wheels = 4 } class Boat implements Vehicle{ mass = 3000 sails = 2 } ...

When an element is appended, its image height may sometimes be mistakenly reported as

I am dynamically adding divs and I need to retrieve the height and width of an image. Based on this information, I have to apply CSS to the MB-Container class. For example: if the image is portrait orientation, set container width to 100%. If it's ...

Issue with vue-template-compiler in Vue.js 3 webpack configuration

I am currently working on integrating vuejs 3 into a project that already utilizes webpack. I have been looking into using vue-loader as part of this process. After consulting the official documentation, I came across the following information: Every new ...

How can I execute a Python script on an HTML webpage by clicking a button?

Below is the HTML code I have written: <script> function goPython(){ $.ajax({ url: "MYSCRIPT.py", context: document.body }).done(function() { alert('finished python script');; ...

Navigate to the Bootstrap Panel body when the relevant link is clicked

I am facing an issue with a long list of panels that are tedious to scroll through. To make navigation easier, I am attempting to create a shortcut link at the top of the page. Below is the code for the shortcut: <a data-toggle="collapse" data-parent ...

Detecting unutilized space in a collection of divs with varying sizes using JavaScript and CSS

To better understand my issue, I created a StackBlitz demo: https://stackblitz.com/edit/angular-aqmahw?file=src/app/tiles-example.css Screenshot My tiles can have four different widths (25%, 50%, 75%, 100%). The tiles must fit on only two lines, so if a ...

Error: Unable to access 'target' property as it is undefined in React JS

I am currently working on capturing the value of a select tag that triggered an event, but I am encountering an issue when changing the tag. An error message pops up saying TypeError: Cannot read property 'target' of undefined. It seems to indica ...

"Switching to the active tab in Bootstrap has been updated

Using Bootstrap, I have implemented this tab: <ul class="nav nav-tabs" id="feedtab"> <li class="active"><a href="#atlass" data-toggle="tab">Atlass</a></li> <li><a href="#avi" data-toggle="tab">Aviation</a&g ...

Stop specific words from being entered on a website

Is there a way to block a specific word from being saved in my database? For example, if I want to prevent the term 'fast car' from being stored, what kind of code should I implement using HTML, JavaScript, or PHP on my website? ...

Using PHP and JQuery to disable a button after the letter "U" is typed

I am looking for a way to disable the button when the term "U" (defined as Unable) appears. How can I achieve this? Below is the button in question: <input type="submit" class="form-control btn-warning" name="search" value="Search Data"></input& ...

Obtain a button located within a div using a JavaScript file

I am currently immersed in a MVC ASP .NET Project. Within my View folder resides the Dashoboard.cshtml file, which contains the following code: <div id="something"> <button type="button" class="btn btn-primary">Export To PDF</b ...

contrasts in regex special characters: .net versus javascript

Here is my current javascript implementation: EscapeForRegex = function(input) { var specials = ["[", "\\", "^", "$", ".", "|", "?", "*", "+", "(", ")", "{", "}"] for (var k in specials) { var special = specials[k]; ...

Show or hide a fixed position div using jQuery when clicked

I am new to jQuery and I am trying to create a "full page menu" on my own. However, I am struggling to hide the menu on the second click. I tried using .toggle() but I found out that it has been deprecated. Can someone assist me with this? Thank you so muc ...

Using dynamic classes within a v-for loop

Edited How can I dynamically assign classes to multiple elements within a v-for loop? Since I cannot utilize a computed property due to the presence of v-for, I attempted using a method by passing the index of the element, but that approach did not yield t ...

The output from the Angular .then function is not showing up on the webpage

Within my stucontrollers.j, I have the following code: /// <reference path="../angular.js" /> var stucontrollers = angular.module("stucontrollers", []); stucontrollers.controller("GetStudentsList", function GetStudentsList($scope, $http) { $ ...

Obtaining zip files using AngularJS

Upon entering the following URL in my browser, I am prompted to download a file: My goal is to download this file using an AngularJS HTTP request. I have created a factory for this purpose, but unfortunately, the download is not successful. Even though ...