AXIOS에서 액셀 파일 다운로드 - OhMinsSup/tip-review GitHub Wiki

//GET (1)
downCsList(){                
    axios({
        method: 'GET',
        url: 'http://localhost:9099/list/testDownload',                 
        responseType: 'blob' // 가장 중요함
    })    
    .then(response =>{        
        const url = window.URL.createObjectURL(new Blob([response.data], { type: response.headers['content-type'] }));
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', 'test.xlsx');
        document.body.appendChild(link);
        link.click();
    })                                
}

//GET (2)
axios.get(url, {
    responseType: 'arraybuffer'
}).then(function (response) {
    var blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    var blobURL = window.URL.createObjectURL(blob);
    var tempLink = document.createElement('a');
    tempLink.style.display = 'none';
    tempLink.href = blobURL;
    tempLink.setAttribute('download', 'test.xlsx');
    document.body.appendChild(tempLink);
    tempLink.click();
    document.body.removeChild(tempLink);
    window.URL.revokeObjectURL(blobURL);
})
//POST
axios({
    method: 'POST',
    url: 'http://localhost:9099/list/download',
    responseType: 'blob',
    headers: {
        "Content-Type": "application/json"
    },   
    data: {
        custCode: custCodeVal,
        startTime: startTimeVal,
        endTime: endTimeVal       
    } 
})
.then(response =>{
    const url = window.URL.createObjectURL(new Blob([response.data], { type: response.headers['content-type'] }));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', 'test.xlsx');
    document.body.appendChild(link);
    link.click();
})