[vue] 엑셀 업로드, 다운로드

Edward Hyun·2022년 9월 19일
0

app&web-dev

목록 보기
147/178
// excel Download
const excelFileDownload = async () => {
  // eslint-disable-next-line max-len
  const fileUrl = 'aaa.xlsx';
  const res = await axios({
    method: 'get',
    url: fileUrl,
    responseType: 'blob',
  });
  const newUrl = window.URL.createObjectURL(res.data);
  const a = document.createElement('a');
  a.href = newUrl;
  a.download = 'aaa.xlsx';
  a.click();
  a.remove();
  window.URL.revokeObjectURL(newUrl);
};

// excel Upload
const inputFileUpload = ref();
const fileUpload = () => {
  const input = inputFileUpload.value as HTMLInputElement;
  input.click();
};
const readFile = async () => {
  const input = inputFileUpload.value as HTMLInputElement;
  if (input && input.files) {
    const targetFile = input.files[0];
    const formData = new FormData();
    formData.append('file', targetFile);
    const res = await custom_api({
      params: formData,
    });
    if (res.isOK) {
		// 데이터 처리
    }
  }
};
profile
앱&웹개발(flutter, vuejs, typescript, react), 인공지능(nlp, asr, rl), 백엔드(nodejs, flask, golang, grpc, webrtc, aws, msa, nft, spring cloud, nest.js), 함수형 프로그래밍(scala, erlang)을 공부하며 정리합니다.

0개의 댓글