dsoframer.ocx 应用思路

本文详细介绍了dsoframer.ocx控件的基本应用,包括如何在页面中放置控件、设置其属性,以及如何实现文档的创建、打开、保存等功能。此外,还提供了与数据库交互的具体实现思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   其实,dsoframer.ocx  的应用很简单,基本上都是固定的。一般的应用都是和数据库数据的操作联系在了一起。比如医院的病历-每个病人除了对应一个word文档病历外,病人的一些其他信息都是从数据库调用出来的。而且一个病人只能调用相应的病历文档。这也许就增加了操作的难度,其实是很容易变通的。 我这里只将思路,不给案例。

      首先说一下dsoframer.ocx  的基本应用:

      1. 在页面中放置这个控件。

       代码如下:

       <object id="FramerControl1" codebase="dsoframer.ocx" height="550px"
                                                classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" width="910px">
                                                <param name="_ExtentX" value="16960">
                                                <param name="_ExtentY" value="13600">
                                                <param name="BorderColor" value="-2147483632">
                                                <param name="BackColor" value="-2147483643">
                                                <param name="ForeColor" value="-2147483640">
                                                <param name="TitlebarColor" value="-2147483635">
                                                <param name="TitlebarTextColor" value="-2147483634">
                                                <param name="BorderStyle" value="1">
                                                <param name="Titlebar" value="0">
                                                <param name="Toolbars" value="1">
                                                <param name="Menubar" value="1">
                                            </object>

 

         这里可以设置该控件的id,长宽,前景,背景等基本属性,没啥说的。

     2.  当页面初始化加载的时候,是否让该控件自动加载一个空文档或不空的word文件。

         这需要在页面加载事件里做<body onload="fuc()">--这些都是js操作哦!

         document.all.FramerControl1.CreateNew('Word.Document');--------------------这是创建新的文档。

       

 

           if(virpath!="" && reset=="")
             {
                if(virpath.toLowerCase().indexOf(".doc")>1)
                {
                document.all.FramerControl1.Open(virpath, true);
                }
                else
                {
                    alert("数据维护出错,没有找到……");
                    window.close();
                }
             }

              - ----------------------------------------------------这个我是从数据库中得到的 virpath (asp.net  --先从.cs得到virpath 然后输出到前台)

 

         3 对这个控件的一些常用的操作:

     //   创建新文档:

         document.all.FramerControl1.CreateNew('Word.Document');

 

        //打开制定的本地文件
        document.all.FramerControl1.Open("C://mywod.doc");
        //制定用Word来打开c:/mytxt.txt文件
         document.all.FramerControl1.Open("C://mytxt.txt",false, "Word.Document");
         //打开服务器的文件
         document.all.FramerControl1.Open "https://secureserver/test/myword.aspx?id=123",true, "Excel.Sheet", "MyUserAccount",        "MyPassword");

        document.all.FramerControl1.Open("http://localhost/myword.doc", true);

 

 

 

         保存文件

       //到本地
        document.all.FramerControl1.Save("c://1.doc",true);
       //服务器  
       /*增加Http协议Post上传接口,可以Post一个动态页面(jsp,asp,php...),由动态页面负责解析数据
        bool HttpInit();
        bool HttpAddPostString(BSTR strName, BSTR strValue);
        bool HttpAddPostCurrFile(BSTR strFileID, BSTR strFileName);
        BSTR HttpPost(BSTR bstr); 

 

 

         这里有个重点就是  怎么具体处理增加的word文档。       

         下面给出具体的代码(asp.net )

 

                    var url = window.location.protocol+"//"+window.location.host+"/"+"MrCLAS/Case_History_Save.aspx";

//这个是我动态的得到当前的域名 + 需要传递的页面


                    document.all.FramerControl1.HttpInit();

//http初始化
                    document.all.FramerControl1.HttpAddPostString("RecordID","无");
                    document.all.FramerControl1.HttpAddPostString("UserID","无");
                    document.all.FramerControl1.HttpAddPostCurrFile("FileData", "11.doc");

 

//这些都是 word文档需要的一些属性值, 可以自己定义,但是不可以不要哦!
                    document.all.FramerControl1.HttpPost(url+str);

 

//传递过去。 其实可以在url+str 总的 str传递一些界面元素值,到处理页面保存到数据库中。

word文档是通过http post 方面传递过去的。

 

                   4. 保存处理页面(*关键哦!)

                   在保存处理页面如果又有数据库又有word文档的,最好用事务处理。等数据库中的保存成功后,在执行word文档的保存。 但有一个问题是,如果数据库保存成功,但word文档不成功 ,,,,目前我是没有找到好方法(希望大家有的话告诉我一下呵呵。)

 

                 数据库部分我就不说了,关键是看看word文档的保存部分:

               BinaryReader br = new BinaryReader(Request.InputStream);

                是接收word二进制文档的代码:

 

 

                //写入文件  这是关键处理代码:

      br 是在处理页面接受到的二进制对象, newFile 是保存的路径。
        protected static bool Create_doc(BinaryReader br, string newFile)
        {
          
            try
            {
                int enterCount = 12;
                br.BaseStream.Seek(0, SeekOrigin.Begin);

                int enterNo = 0;
                int streamHeadLen = 0;
                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    streamHeadLen++;
                    char c = (char)br.ReadByte();
                    if (enterNo < enterCount)
                    {
                        if (c == '/n')
                        {
                            enterNo++;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                br.BaseStream.Seek(0, SeekOrigin.Begin);
                string strTemp = System.Text.UTF8Encoding.Default.GetString(br.ReadBytes(streamHeadLen - 1));

                FileStream newDoc = new FileStream(newFile, FileMode.Create, FileAccess.Write);
                BinaryWriter bw = new BinaryWriter(newDoc);
                bw.BaseStream.Seek(0, SeekOrigin.End);
                while (br.BaseStream.Position < br.BaseStream.Length - 38)
                {
                    bw.Write(br.ReadByte());
                }
                br.Close();
                bw.Flush();
                bw.Close();
                return true;
            }
            catch (Exception err)
            {
                return false;
            }

        }

 

 

到此为止, word文档也就算保存成功了。

 

          还有一个问题就是删除word文档的问题:

这就是基本的io 操作了,给大家一个通用的类:

                  //删除病历

        public static bool DeleteFile(string FilePath)
        {
            try
            {
                string strPath = FilePath;
                if (System.IO.File.Exists(strPath))
                {
                    System.IO.File.Delete(strPath);
                }
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
            }
        }

 

 

好了,就到这里吧,以后我将不断的给大家一些自己的经验。如果有不好的地方,希望大家给我提出宝贵意见。

        

    

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值