When exporting an Excel file, the file name is garbled

Source: Internet
Author: User

Refer to Meng xianhui's answer at the Microsoft Forum (http://social.microsoft.com/Forums/zh-CN/1761/thread/61df2773-c8ad-416e-9797-f28201145f8d)
The key is to specify the encoding method for the file name to solve this problem.
In addition, if the file name and suffix are not specified in content-disposition, the output format is automatically changed to. Zip.
The relevant information is explained as follows :(Http://blog.minidx.com/2008/01/24/436.html)
Previous office documents were in the binary format of 100%. Third-party tools are very inconvenient to operate, while office2007 is based on XML format as a whole. This does not mean that office2007 documents can be saved in XML format. The default document format of office2007 is XML (Word docx and Excel XLSX ). Some may be surprised that after opening docx in a text editor, the binary format is still displayed, and it is not XML. In fact, docx is not a common XML format. Of course, it is not just an XML file. docx is essentially a zip file with a series of XML, directories, and other files. If we change docx to zip. You can use software such as WinZip to unbind it.

String vfullname = gazoudt [0]. filepath;
String vextendname = "";
String voutputname = gazoudt [0]. reference;

Switch (Int. parse (type ))
{
Case excle:
Case excle_2007:

If (vfullname. endswith ("XLSX "))
{
Vextendname = voutputname. endswith (". XLSX ")? "": ". XLSX ";

Response. contenttype = "application/vnd. openxmlformats-officedocument.spreadsheetml.sheet ";
}
Else
{
Vextendname = voutputname. endswith (". xls ")? "": ". Xls ";

Response. contenttype = "application/vnd. MS-excel ";
}

Response. appendheader ("content-disposition", String. format ("attachment; filename = {0} {1}", httputility. urlencode (voutputname, system. text. utf8encoding. utf8), vextendname ));

Break;
Case PDF:
Response. contenttype = "application/pdf ";
Response. appendheader ("content-disposition", "attachment ");
Break;
Case word:
Case word_2007:

If (vfullname. endswith ("docx "))
{
Vextendname = voutputname. endswith (". docx ")? "": ". Docx ";

Response. contenttype = "application/vnd.openxmlformats-officedocument.wordprocessingml.doc ument ";
}
Else
{
Vextendname = voutputname. endswith (". Doc ")? "": ". Doc ";

Response. contenttype = "application/MSWord ";
}

Response. appendheader ("content-disposition", String. format ("attachment; filename = {0} {1}", httputility. urlencode (voutputname, system. text. utf8encoding. utf8), vextendname ));

Break;

}

Response. charset = "UTF-8 ";
Response. transmitfile (gazoudt [0]. filepath );
Response. End ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.