首页 .NET/Web Asp.net如何将office文档转换为SWF格式类似豆丁网,百度文库控件

Asp.net如何将office文档转换为SWF格式类似豆丁网,百度文库控件

作者:胡同里的砖头 围观群众:1054 更新于:2013-12-19

 

将doc、xls、Txt等文档转换为类似于百度文库的形式,实际上就是把文档转换为Flash,通过Flash播放器进行浏览,通过这种方式在网页呈现文档具有很多优点,特别是在OA系统设计中阅读起来更加便捷。下面简要介绍一下转换和呈现的方法。

一、下载FlashPaper,并进行正确安装。

二、在VS2008中新建一个网站,名称为FlashPaper。

三、修改Web.Config文件。

在<configuration>配置节中添加下面的代码,指定FlashPrinter.exe文件所在的位置。
 <appSettings>
  <add key="FlashPaper" value="D:\\Program Files\\FlashPaper\\FlashPaper2.2\\FlashPrinter.exe"/>

<!--D:\\Program Files\\FlashPaper\\FlashPaper2.2\\FlashPrinter.exe,FlashPrinter.exe文件安装在D盘-->
 </appSettings>
 <connectionStrings/>

四、新建一个页面文件Default.aspx,拖放一个FileUpload控件和一个命令按钮Button1控件到页面。双击命令按钮,添加下面的代码。

 string flashpaper = System.Configuration.ConfigurationManager.AppSettings["FlashPaper"].ToString();//获取Web.config文件中FlashPrinter.exe所在的路径。
            string fn = DateTime.Now.ToFileTime().ToString().Trim() + ".swf";//指定文件名名称
            string FPath = Server.MapPath("/swf/");
            this.Label1.Text = FPath + fn;

            System.Text.StringBuilder command = new System.Text.StringBuilder();
            command.Append("\"").Append(flashpaper).Append("\" ").Append(this.FileUpload1.PostedFile.FileName).Append(" -o ").Append(FPath).Append(fn);
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            //p.StartInfo.FileName = command.ToString();
           
            p.StartInfo.FileName = "cmd";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = false;
            //p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            try
            {
                p.Start();
                string strOutput = null;
                p.StandardInput.WriteLine(command.ToString());
                p.StandardInput.WriteLine("exit");
                strOutput = p.StandardOutput.ReadToEnd();
                //Console.WriteLine(strOutput);
                p.WaitForExit();
                p.Close();
                Response.Redirect("a.aspx?swfname=" + fn);
               

            }
            catch (Exception ex)
            {
                Response.Write("wring:"+ex.ToString());
            }


        }

五、呈现Flash文档。

新建一个页面a.aspx,在页面中添加插入Falsh代码。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="a.aspx.cs" Inherits="FlashPaper.a" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
            codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"
            style="height: 601px; width: 899px">
      
       <param name="movie" value="<%= swfname %>"/>
      
       <param name="quality" value="high"/>
      
       <param name="SCALE" value="exactfit"/>
      
       <embed src="<%= swfname %>" width="500" height="500" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" scale="exactfit"></embed>
      
       </object>
    </div>
    </form>
</body>
</html>

在页面的Load事件中添加

namespace FlashPaper
{
    public partial class a : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                swfname ="/swf/"+ Request.QueryString["swfname"].ToString();
 
            }
        }
        public string swfname = "";
    }
}

实现的功能是选择一个文档,单击Button1按钮开始进行转换,转换后通过a.aspx页面呈现。

/**************注意事项***********************/
1.运行之前必须先执行项目下面有个"WenXian\WebUI\FlashPaper\初始化\初始化.bat",双击。
2.必须要将项目解压到D盘或E盘,且项目路径中不能带有任何一个中文
3.期刊转换的时候,要转换的word或excel等office文件所在路径必须也不能含有中文,且文件命名也不能带有中文例如“C:\Documents and Settings\Administrator\桌面\WenXian”路径中包含了中文

切记以上三点,否则转换将不能正常运行

思路:如果想解决上传文档不限的话,可以先将文档上传到项目下面,这样可以解决路径中带有中文的问题,然后在转换上传后的文件

  • 本文标题: Asp.net如何将office文档转换为SWF格式类似豆丁网,百度文库控件
  • 文章分类:【.NET/Web】
  • 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
留言评论
站点声明:
1、本站【胡同里的砖头】个人博客,借鉴网上一些博客模板,取其各优点模块自行拼装开发,本博客开发纯属个人爱好。
2、所有笔记提供给广大用户交流使用,可转载,可复制,纯个人开发所遇问题锦集记录使用
Copyright © huzlblog.com All Rights Reserved. 备案号:苏ICP备2021056683号-8