1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to add ":" to xls filename after download using angular - ":" gets replaced by "_"

Discussão em 'Angular' iniciado por Nancy, Novembro 1, 2024 às 14:42.

  1. Nancy

    Nancy Guest

    I have the angular code below to download xls file from API response, I am trying to change the file name to filenameDD_HH:MM . For some reason, the ":" is replaced with "" after download. Tried regex to replace ":" with "" , doesnt work as well.

    downloadFile() {
    this.servcie.downloadReport().subscribe({
    next:(response)=>{
    const blob = new Blob([response], {type: 'application/octet-stream'});
    const url = window.URL.createObjectURL(blob);
    const anchor = document.createElement('a');
    anchor.href=url;
    var today = new Date();
    let hours = today.getHours() + ":";
    let minuted = today.getMinutes() + ":";
    anchor.download = "myfile_" + hours + minutes + ".xls";
    anchor.click();
    window.URL.revokeObjectURL(url);
    }
    })

    }

    Continue reading...

Compartilhe esta Página