Download Excel with pivot table IE appending [1] t

2019-09-06 02:57发布

问题:

Currently I am face this issue.

when I am directly opening from IE with out saving , IE adding [1]/Version to file name

Example: Test.xlsx file in backend but when i am opening the file its renamed to Test[1].xlsx.And this is creating the issue.

Can any one suggest what I am doing wrong here.

//res.setContentType("application/vnd.ms-excel");
               //res.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
               //res.reset();
               //res.setHeader("Expires", "0");

      myDownloadTask{
              //res.setHeader("Cache-Control","must-revalidate,post-check=0, pre-check=0");
               //res.setHeader("Pragma", "public");
               //res.setContentType("application/force-download");
               //res.setHeader("Content-Transfer-Encoding", "binary");
               res.setContentType("application/ms-excel; charset=UTF-8");
               res.setCharacterEncoding("UTF-8");

               fileName=EncodeFileName(fileName);

               res.setHeader("Content-Disposition","attachment; filename="+fileName);
       }

回答1:

You have a file with Test.xlsx already on your hard disk, this is why IE rename it to Test[1].xlsx.

I think you can not handle it, you can create a unique file name on the server every time, or gently prompt to user to make sure he does not have a file with same name on his hard disk !