LoginSignup
14
12

More than 5 years have passed since last update.

Excelファイルをaxiosで扱うときのメモ

Last updated at Posted at 2018-09-10

ハマったポイント

サーバ処理

return c.Blob(http.StatusOK, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", buf.Bytes())

上記のレスポンスをaxiosでExcelデータとして取得し,処理する時

axios.get('/ex').then(res=>{
    let blob = new Blob([res.data]);
     ....
});

これだと,ファイルは文字化けしてしまう.

ミス

axios.getはデフォルトが一度文字列として,処理する.

解決策

getでファイルタイプを選択しておく.

axios.get('/ex',{
    responseType:'blob',
    dataType:'binary',
}).then(res=>{
    let blob = new Blob([res.data]);
     ....
});
14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12