0
我想導出我的中繼器發揮所長,這裏是我的代碼...出口中繼到excel
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
string attachment = "attachment; filename=file.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
rpt.RenderControl(htw);
Response.Write(sw.ToString());
Response.Flush();
Response.End();
當我試圖打開文件收到此錯誤
The file you are trying to open, 'file.xls', is in a different format than specified
by the file extension. Verify that the file is not Corrupted and is from a trusted
source before opening the file. Do you want to open the file now?
Yes No Help option are available
什麼問題在我的代碼或我必須做什麼解決這個問題。 謝謝
當我點擊yes選項,則正確打開罰款和顯示數據。我從互聯網上找到很多文章,發現類似的實現。 Plz檢查這篇文章http://www.aspsnippets.com/Articles/Export-GridView-To-Word-Excel-PDF-CSV-Formats-in-ASP.Net.aspx –