zoukankan      html  css  js  c++  java
  • asp.net与word文档在线

    1.通过javascript打开\编辑\根据模板新建word文档           

               //"SharePoint.OpenDocuments.1"可与Office XP兼容
                var openDocObj = new ActiveXObject("SharePoint.OpenDocuments.2");
               
                //打开文档
                openDocObj.ViewDocument(lUrl+"./documents/sample.doc");

                //ViewDocument()方法还有一个重载签名,可以让我们手工指定激活哪个程序来打开文档:     
                openDocObj.ViewDocument(lUrl+"./documents/sample.doc",   要激活的程序的ProgID);  

                //编辑文档
                var lUrl = window.location.href;
                openDocObj.EditDocument(lUrl+"./documents/sample.doc");
               
                //根据模板创建文档(模板,新文档保存路径)
                openDocObj.CreateNewDocument(lUrl+"./documents/sampleTemplate.dot", lUrl+"./documents/"); 

        注:iis必须设置为可写,web服务扩展中的WebDaV应是允许状态,如图:    

    2.直接把文件上传进数据库

    string FileName;
            Stream WordStream = SearchFile.PostedFile.InputStream;
            string FilePath = this.SearchFile.PostedFile.FileName;
            FileName = Path.GetFileName(FilePath);
            if (FileName != null && FileName != "")
            {
                int WordLen = SearchFile.PostedFile.ContentLength;
                string WordType = SearchFile.PostedFile.ContentType;
                byte[] WordData = new Byte[WordLen];
                int n = WordStream.Read(WordData, 0, WordLen);
                WordStream.Close();
                SqlCommand com = new SqlCommand();
                com.CommandText = "insert into MyTable(name,FileBinary) values(@FileName,@FileBinary)";
                com.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FileName", System.Data.SqlDbType.Char, 20, "FileName"));
                com.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FileBinary", System.Data.SqlDbType.Image, WordData.Length, "FileBinary"));
                com.Connection = sqlConnection;
                com.Parameters["@FileName"].Value = FileName;
                com.Parameters["@FileBinary"].Value = WordData;
                com.Connection.Open();
                com.ExecuteNonQuery();
                com.Connection.Close();
            }
            else
            {
                Response.Write(" ");
            }

    3.数据流的方式在浏览器中显示Word文件

    Response.ContentType = "Application/msword";

            this.Response.Clear();
           
            SqlCommand selcom = new SqlCommand();
            selcom.CommandText = "select name,FileBinary from MyTable order by id desc";
            selcom.Connection = sqlConnection;
            selcom.Connection.Open();
            SqlDataReader dr = selcom.ExecuteReader();
            dr.Read();
            Byte[] b = new Byte[(dr.GetBytes(1, 0, null, 0, int.MaxValue))];
            dr.GetBytes(1, 0, b, 0, b.Length);
            dr.Close();
            selcom.Connection.Close();
            System.IO.Stream fs = this.Response.OutputStream;
            fs.Write(b, 0, b.Length);

            fs.Close();
            this.Response.End();

    http://www.cnblogs.com/9who/archive/2008/07/28/1254532.html

  • 相关阅读:
    Python2和3版本对str和bytes类型的处理
    使用Fiddle对夜神模拟器进行抓包的设置
    WebSocket 实现链接 群聊(low low low 版本)
    WebSocket 实现链接 发送消息
    Linux文件操作命令
    Linux命令格式
    FastJson
    JSON语法规则
    Mybatis resultMap支持继承
    Mybatis在xml文件中处理大于号小于号的方法
  • 原文地址:https://www.cnblogs.com/y0umer/p/3839098.html
Copyright © 2011-2022 走看看