How to export an XLS file with JavaScript without relying on Active X controls

Is there a universal way to export an HTML page to XLS using JavaScript that will work on all three latest versions of browsers? I have found methods for exporting in Internet Explorer, Mozilla and Chrome.

In Internet Explorer:
window.clipboardData.setData("Text", vTable);
var objExcel = new ActiveXObject("Excel.Application");
objExcel.visible = false; 
var objWorkbook = objExcel.Workbooks.Add; 
var objWorksheet = objWorkbook.Worksheets(1); 
objWorksheet.Paste; 
objExcel.visible = true;
In Mozilla and Chrome:
var url='data:application/vnd.ms-excel,' + encodeURIComponent($('#divExport').html()) ;
location.href=url;

Answer №1

To specify the page content-type as

Content-type: application/vnd.ms-excel

Alternatively, for .xlsx files, you can use

Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

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

Searching for text within a PDF document using the Internet Explorer version 9 browser by

When a link is clicked in our application, it opens a new window with a secure PDF file. We are looking to validate this using Selenium in Ruby. However, we encountered an issue in IE9 where there is no HTML/DOM element for validation. We were able to suc ...

Vue throwing ReferenceError when accessing uninitialized variable in Safari browser

Recently, I've encountered a perplexing error message that has me scratching my head. The error message reads as follows: ReferenceError: Cannot access uninitialized variable. This error specifically points to the line of code: const app = createApp(A ...

"Typescript throws a mysterious 'Undefined value' error post-assignment

I'm currently working on a task to fetch my customer's branding information based on their Id using Angular. First, I retrieve all the customer data: this.subscription = this.burstService.getBurst().subscribe(async(response) => { if (r ...

In PHP, show the restore button if the status is 0; otherwise, display the delete button

I have a single button labeled "Delete." When the admin clicks on this button, the record is updated in the database and the button changes to "Restore," and vice versa. If the status of the record is 0, then the "Restore" button should be displayed. I a ...

Waiting for the UI data filter to be available in Selenium

Within an application, numerous fields are present with individual filters (text boxes). As soon as a user enters a value in any of the filters, the UI data (in a table) immediately refreshes. I prefer to wait for the UI data to load before applying anoth ...

Clicking on the following link will initiate the process of submitting a form

I'm encountering an issue with the following code snippet: <a href='javascript:jQuery("#questionnaire").show();'>haha</a> When this code is placed inside a form, it mysteriously causes the form to submit upon clicking the link. ...

eval$ encountered a surprising change from const to null

shelfCategoryLinks is an array of links to specific categories. Despite using await page.waitForSelector('.itemCount');, the itemCounter sometimes returns null, causing the app to break. for (let shelf of shelfCategoryLinks) { l ...

This error message is indicating that the 'csrf_token' property cannot be found within the 'Object' type

This is a straightforward query. I am attempting to set up a login system using Angular 5 for the front end and Drupal 8 for the backend. The connection is established successfully, I can send JSON data to the Drupal site, and it returns a CSRF token to m ...

Embracing Efficiency with Asynchronous Requests in a React Redux App Utilizing Redux Thunk

Challenge I am currently facing a dilemma in implementing an AJAX request that needs to be triggered by various UI elements on a webpage. The AJAX request is consistently directed towards the same endpoint and always sends identical properties from the re ...

Prevent the function from being repeatedly triggered as the user continues to scroll

I am facing an issue with my app where new content is fetched from the API using the infinity scroll method when the user reaches near the bottom of the screen. However, if the user scrolls too fast or continuously scrolls to the bottom while new content i ...

Troubleshooting: CSS Styles not loading when passed as property in MUI withStyles

I am currently working on a react component that has a specific style defined as shown below: const StyledInnerItem = withStyles((theme) => ({ bgColor: { backgroundColor: (props) => { console.log('styledInnerItem color: ', props ...

Tips for inserting a button under a div when clicked

I am working on a layout where I have several div cards aligned side by side using the display: inline-block property. What I want to achieve is that when I click on a card, a button is added below the respective div. To accomplish this, I tried using jqu ...

Displaying the name of the file in a text area

I'm trying to create a functionality where the filename of an input file is displayed in a textarea when the file is selected. However, I've encountered an issue where this only works for the first selection and subsequent file selections do not ...

A Fresh Approach for Generating Unique UUIDs without Bitwise Operators

To generate UUIDs in TypeScript, I have implemented a method inspired by the solution provided on Stack Overflow. The code effectively converts JavaScript to TypeScript. generateUUID(): string { let date = new Date().getTime(); if (window.performa ...

After updating next.config, the NextJS + NextAuth middleware doesn't seem to be triggered

I'm currently utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b0ded5c8c49dd1c5c4d8f0849e81889e87">[email protected]</a> & <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemai ...

Simulation was designed to be executed on a single node, but none was discovered during the process

Having trouble understanding why the onChange function is not being called. I have added an id but it seems unable to locate the element. File.test.js it("expects onChange event to be triggered on renderToDropdown ", () => { baseProps.onChange.moc ...

Show a different image with a matching title each time the page loads

I need help creating a JavaScript script that will display a random image from an array along with an associated title each time the page loads. Is there a way to do this without using an onload function placed in the body tag? Currently, my code relies o ...

The onreadystatechange function does not get triggered in Firefox

Below are the codes I have written: Function for sending an AJAX request and getting a value in return: function myAjaxCall(){ var myValue=0; var async = false; //I need to make a synchronized request, otherwise the return value is 0 xmlhttp.ope ...

Issue with Bing Maps Infobox mouseout event: Problem arises when attempting to change the htmlContent asynchronously

Can anyone provide assistance? I am currently utilizing the latest Bing Maps version (v8), and I have encountered an issue. When creating a custom Infobox and populating its contents using an async request such as setTimeout/ajax, the mouseout event is tr ...

Function in Vue for calculating the number of duplicate elements in an array

I have successfully created a new array containing only unique values, but I am facing issues with my count function. The desired result is to display the number of items in the array for each color. The expected outcome would be: 4 red 10 blue 1 green ...