c#:将swf对象作为图像导出到Word

时间:2010-03-28 09:44:03

标签: c# asp.net flex ms-word flash

在我的Asp.net网页(后端的C#)中我使用了一个Repeater,它的项目包括一个标题和一个Flex图表(嵌入的.swf文件)。我试图将Repeater的内容导出到Word文档。我的问题是将SWF文件转换为图像并将其传递给Word文档。

swf对象有一个public函数,它返回一个自己的byteArray表示形式(public function grabScreen():ByteArray),但我不知道如何直接从c#中调用它。 我可以访问mxml文件,因此如果需要,我可以对swf文件进行修改。

代码如下所示,感谢您的帮助:)

的.aspx

<asp:Button ID="Button1" runat="server" text="export to Word" onclick="print2"/>

<asp:Repeater ID="rptrQuestions" runat="server"   OnItemDataBound="rptrQuestions_ItemDataBound" >
...
<ItemTemplate>
<tr>  
<td>  
<div align="center">
  <asp:Label class="text" Text='<%#DataBinder.Eval(Container.DataItem, "Question_title")%>' runat="server" ID="lbl_title" NAME="lbl_title"/>
<br>
</div>
</td>
</tr>
<tr><td>


  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="result_survey"  width="100%" height="100%" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
       <param name="movie" value="result_survey.swf" />
       <param name="quality" value="high" />
       <param name="bgcolor" value="#ffffff" />
       <param name="allowScriptAccess" value="sameDomain" />
       <param name="flashvars" value='<%#DataBinder.Eval(Container.DataItem, "rank_order")%>' />  
       <embed src="result_survey.swf?rankOrder='<%#DataBinder.Eval(Container.DataItem, "rank_order")%>' quality="high" bgcolor="#ffffff" width="100%" height="100%"
         name="result_survey" align="middle" play="true" loop="false"  allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer">
        </embed>
     </object>


</td></tr>
</ItemTemplate>
</asp:Repeater> 

C#

protected void print2(object sender, EventArgs e)
{
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.Charset = "";
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7;
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.ContentType = "application/msword";
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + "Report.doc");
    EnableViewState = false;
    System.IO.StringWriter sw = new System.IO.StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    // Here I render the Repeater
    foreach (RepeaterItem row in rptrQuestions.Items)
    {
        row.RenderControl(htw);
    }
    StringBuilder sb1 = new StringBuilder();
    sb1 = sb1.Append("<table>" + sw.ToString() + "</table>");
    HttpContext.Current.Response.Write(sb1.ToString());
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();
}

的.mxml

//##################################################
// grabScreen  (return image representation of the SWF movie (snapshot)
//######################################################
public function grabScreen() : ByteArray
{
return ImageSnapshot.captureImage( boxMain, 0, new   PNGEncoder()  ).data();
}

1 个答案:

答案 0 :(得分:0)

让Flash将数据传递给JavaScript值。然后,JavaScript可以对ASP.Net代码进行AJAX调用,发送图像的字节,然后您的C#代码就可以处理它。