Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

487
Visualizações
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?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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");
}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda