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

  • 相关阅读:
    duilib布局
    C++中嵌入网页(duilib编辑框的实现)
    拖拽的实现
    调试URL(写文件)
    如何使用DataBinder.Eval()方法进行数据绑定
    GridVew,DataList,Repeater分页用户控件(第一版)
    关于何种情况下使用DataGrid、DataList或Repeater的一些讨论(转)
    使用PagedDataSource类实现DataList和Repeater控件的分页显示功能
    一个取得数据控件模板中输入框值的类
    在GridView中自定按钮,实现删除和更新
  • 原文地址:https://www.cnblogs.com/y0umer/p/3839098.html
Copyright © 2011-2022 走看看