2013-01-11 73 views
0

我希望gridview的出口powerpoint.I有以下code.But我有以下問題:導出GridView控件的Microsoft PowerPoint在C#

  1. 當我使用它的MS Office 2010.its給錯誤:

    Powerpoint cannot read c:\users\filename.ppt. The presentation cannot be opened. Your antivirus program may prevent you from opening the presentation. To fix this problem, make sure your antivirus program is current and working correctly. If the problem persists and the presentation is from someone that you trust, turn off your antivirus program, and then try to open the presentation again. If you do this, make sure you turn on your antivirus program again after you open the presentation.

  2. 當我使用它的MS Office 2007,它的開頭,但沒有gridview的

CODE:

 Response.Clear(); 

     Response.Buffer = true; 

     Response.AddHeader("content-disposition", "attachment;filename=FileName.ppt"); 

     Response.Cache.SetCacheability(HttpCacheability.NoCache); 
     Response.Charset = ""; 
    // this.Response.ContentType = "application/vnd.openxmlformats-  officedocument.presentationml.presentation"; 

     this.Response.ContentType = "application/vnd.ms-powerpoint.presentation.macroEnabled.12"; 

     this.Response.ContentType = "application/vnd.ms-powerpoint"; 

    //Response.ContentType = "application/vnd.ppt"; 

    GridView2.AllowPaging = false; 

    GridView2.DataBind(); 

    System.IO.StringWriter stringWrite = new System.IO.StringWriter(); 
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); 
    GridView2.RenderControl(htmlWrite); 

    Response.Write(stringWrite.ToString()); 

    Response.End(); 
    Response.Flush(); 

回答

0

嘗試使用外部庫來生成您的ppt或pptx。 像aspose.net或Open XML一樣。

+0

:謝謝你的時間。但請你解釋一下你的觀點 - 我的意思是我該如何修改上面的代碼或其他。 –

+0

請如果你不想使用外部庫,請參閱此頁http://forums.asp.net/p/1123406/1763138.aspx#1763138 – GeorgesD

+0

嗨GeorgesD,我已經試過這個代碼,但它給了我以上同樣的問題。我已經試用過ms字輸出成功了,但是對於powerpoint輸出來說似乎有點痛苦。請幫忙解決問題。提前感謝。 :) –