Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

502
Views
How to open a excel file after it gets downloaded in javascript?

I download an excel file (.xls) by using below code:

JavaScript Code:

window.location = result.filename;

After downloading, I want to open a excel file automatically without clicking on it. I want JavaScript code for opening excel file automatically.

I tested with following function code. But it runs only in Internet Explorer, not in Mozilla, Chrome...

function openExcelFile(strFilePath) {
var objExcel;
objExcel = new ActiveXObject("Excel.Application");
objExcel.Visible = true;
objExcel.Workbooks.Open(strFilePath);
}

By using above code, the excel file open automatically after it gets downloaded in Internet Explorer.

I want JavaScript code for opening excel file automatically after downloaded by working in all browsers.

How can I achieve this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

pass the excel file path to the controller. it will works fine with all browsers.

public ActionResult GetFile(string path)
{

    string extension = new FileInfo(path).Extension;
    if (extension != null || extension != string.Empty)
    {
        switch (extension)
        {
            case ".xls":
                return File(path, "application/vnd.ms-excel");
            case ".xlsx":
                return File(path, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        }
    }
    return View("Index");
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!