dsoframer是微软提供一款开源的基于web的office ActiveX控件,国内有达人在源码的基础上做了很多修改,增强了控件的功能。其实基于web的office是一个很鸡肋的东西,没有什么存在的意义。唯一的一点就是看上去比较花哨,你瞧,在浏览器上打开word文档,多吊啊。不知道原版dsoframer是否带有直接保存文档至服务器的功能,不过我手头上的一个改良版本的确是有此功能。

控件附带说明给出了保存文档至服务器的javascript函数,如:

function SaveToWeb()
{
  document.all.FramerControl1.HttpInit();
  document.all.FramerControl1.HttpAddPostCurrFile("FileData", "mydoc.doc");
  var err = document.all.FramerControl1.HttpPost("Http://202.114.12.137/newvan/pm/auxi/SaveDoc.aspx");
  if (!err)
  alert('保存失败!');
  else
  alert('保存成功!');
}

由此可见,关键问题是如何实现SaveDoc.aspx模块。于是乎在网上搜索相应的解决方案,但没有一个能在服务器上成功保存正确的文件。失望之余索性将原文档和上传文档用UltraEdit打开进行二进制级比较,然后抓包分析POST数据时http数据包的格式,最后终于找到了解决的办法,贴出来供遇到同样问题的朋友参考,代码如下:

BinaryReader bReader = new BinaryReader(Request.InputStream);
string strTemp = Encoding.GetEncoding("iso-8859-1").GetString(
bReader.ReadBytes((int)bReader.BaseStream.Length), 0, (int)bReader.BaseStream.Length);
string match = "Content-Type: application/msword\r\n\r\n";
int pos = strTemp.IndexOf(match) + match.Length;
bReader.BaseStream.Seek(pos, SeekOrigin.Begin);

string newFile = Server.MapPath(".") + "\\MyFile2.doc";
FileStream newDoc = new FileStream(newFile, FileMode.Create, FileAccess.Write);
BinaryWriter bWriter = new BinaryWriter(newDoc);
bWriter.BaseStream.Seek(0, SeekOrigin.End);

while (bReader.BaseStream.Position < bReader.BaseStream.Length - 38)
  bWriter.Write(bReader.ReadByte());

bReader.Close();
bWriter.Flush();
bWriter.Close();

这里应该注意的是,从字节流中获取字符串时一定要采用iso-8859-1的编码方式,不要采用utf-8或其他,因为utf-8会将asci字符也扩展成相应的unicode双字节形式。原理很简单,代码面前了无秘密。

DSOFramer原有的接口说明
===================================================================
DSOFramer原有的接口说明
1.void CreateNew(BSTR ProgIdOrTemplate)
  新建文档,
  其中: ProgIdOrTemplate参数:
Excel Spreadsheet "Excel.Sheet" 
Excel Chart "Excel.Chart" 
PowerPoint Presentation "PowerPoint.Show" 
Project Project "MSProject.Project" 
Visio Drawing "Visio.Drawing" 
Word Document "Word.Document" 
2. HRESULT Open([in] VARIANT Document, [in, optional] VARIANT ReadOnly, 
[in, optional] VARIANT ProgId, [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword)
  打开文档,可以是本地文件或者是服务器文件
参数:
Document 文档路径
ReadOnly 是否已只读模式打开
ProgId OLE类型
WebUsername 用户名(访问网络的文件时候,有可能需要)
WebPassword 密码
例子:
DsoFramer1.Open "C:\TestBook.xls"
DsoFramer1.Open "C:\Plain.txt", , "Word.Document" //用Word来打开c:\plain.txt文件
DsoFramer1.Open "https://secureserver/test/mytest.asp?id=123", True, "Excel.Sheet", "MyUserAccount", "MyPassword"

3.HRESULT Save([in, optional] VARIANT SaveAsDocument, [in, optional] VARIANT OverwriteExisting, 
  [in, optional] VARIANT WebUsername, [in, optional] VARIANT WebPassword);
保存文件在本地
DsoFramer1.Save "c:\1.doc"

4.Activate
激活当前文档,没搞明白有什么用
5. HRESULT ActiveDocument([out,retval] IDispatch** ppdisp);
返回当前活动文档的Dispatch接口,这个接口很重要,可以通过这个接口,操作所有的文档接口。
如:下面 javascript 语句调用Office内置的对话框
var obj;
obj = new Object(document.all.FramerControl1.ActiveDocument);
if(obj !=null){
var dd;
dd = obj.Application.Dialogs(84).Show();
//... ... 
//delete it
delete obj;
}
6. HRESULT Close();
关闭当前文档,建议在页面关闭的时候调用。
MS的原来的版本,有时候关不掉Word,已经修复了。
7. HRESULT Caption([out,retval] BSTR* pbstr);
属性,获取|设置窗口标题
8. HRESULT Titlebar([in] boolean vbool);
  HRESULT Titlebar([out,retval] boolean* pbool);
  显示或者隐藏标题栏
9. HRESULT Toolbars([in] boolean vbool);
  HRESULT Toolbars([out,retval] boolean* pbool);
  显示或者隐藏工具栏
10. HRESULT ModalState([in] boolean vbool);
  HRESULT ModalState([out,retval] boolean* pbool);

11.HRESULT ShowDialog([in] dsoShowDialogType DlgType);
  显示对话框
12.HRESULT EnableFileCommand([in] dsoFileCommandType Item, [in] boolean vbool);
  HRESULT EnableFileCommand([in] dsoFileCommandType Item, [out,retval] boolean* pbool);

13. HRESULT BorderStyle([in] dsoBorderStyle style);
  HRESULT BorderStyle([out, retval] dsoBorderStyle* pstyle);

14. HRESULT BorderColor([in] OLE_COLOR clr);
  HRESULT BorderColor([out,retval] OLE_COLOR* pclr);

15. HRESULT BackColor([in] OLE_COLOR clr);
  HRESULT BackColor([out,retval] OLE_COLOR* pclr);

16.HRESULT ForeColor([in]OLE_COLOR clr);
  HRESULT ForeColor([out,retval]OLE_COLOR* pclr);

17.HRESULT TitlebarColor([in] OLE_COLOR clr);
HRESULT TitlebarColor([out,retval] OLE_COLOR* pclr);

18.HRESULT TitlebarTextColor([in] OLE_COLOR clr);
  HRESULT TitlebarTextColor([out,retval] OLE_COLOR* pclr);

19.HRESULT ExecOleCommand([in] LONG OLECMDID, [in, optional] VARIANT Options, [in, optional] VARIANT* vInParam, [in, out, optional] VARIANT* vInOutParam);

20.HRESULT Menubar([in] boolean vbool);
  HRESULT Menubar([out,retval] boolean* pbool);
21.HRESULT HostName([in] BSTR bstr);
  HRESULT HostName([out,retval] BSTR* pbstr);
  
22. HRESULT DocumentFullName([out,retval] BSTR* pbstr);
  文档的路径
23.HRESULT PrintOut([in, optional] VARIANT PromptUser, [in, optional] VARIANT PrinterName, [in, optional] VARIANT Copies,
  [in, optional] VARIANT FromPage, [in, optional] VARIANT ToPage, [in, optional] VARIANT OutputFile);

24.HRESULT PrintPreview();
   
25.HRESULT PrintPreviewExit();
26.HRESULT IsReadOnly([out,retval] boolean* pbool);
  是否为只读的。
27.HRESULT IsDirty([out,retval] boolean* pbool);
  是否保存了,实际可以用来判读文档有没有修改
  oframer.IsDirty = TRUE //文档没有保存,处于修改状态
  oframer.IsDirty = FALSE //文档已经保存,没有修改
新加的接口说明(开发接口)
[color=red]当前版本:V2.2.0.8 2007-02-07
[/color]下载控件需要登录
说明:
控件未经大批量测试,难免有Bug,
发现 Bug,请及时发帖或者Mail:wanhhf@gmail.com
版本修改记录:
V2.2.0.8修改:
  增加了N多个事件,挺不错的东西
  [id(DSOF_DISPID_WORD_DocumentChange), helpstring("DSOF_DISPID_WORD_DocumentChange")]
  HRESULT WORD_DocumentChange();
  [id(DSOF_DISPID_WORD_DocumentBeforePrint), helpstring("DSOF_DISPID_WORD_DocumentBeforePrint")]
  HRESULT WORD_DocumentBeforePrint();
  [id(DSOF_DISPID_WORD_WindowActivate), helpstring("DSOF_DISPID_WORD_WindowActivate")]
  HRESULT WORD_WindowActivate();
  [id(DSOF_DISPID_WORD_WindowSelectionChange), helpstring("DSOF_DISPID_WORD_WindowSelectionChange")]
  HRESULT WORD_WindowSelectionChange();
  [id(DSOF_DISPID_WORD_WindowBeforeRightClick), helpstring("DSOF_DISPID_WORD_WindowBeforeRightClick")]
  HRESULT WORD_WindowBeforeRightClick();
  [id(DSOF_DISPID_WORD_WindowBeforeDoubleClick), helpstring("DSOF_DISPID_WORD_WindowBeforeDoubleClick")]
  HRESULT WORD_WindowBeforeDoubleClick();
V2.2.0.6修改: 
  修改Open,参数为空时候,一个小 Bug
  修改了URL过长时候一个Bug
  增加了一个替换文字的接口
  long ReplaceText(BSTR strSearchText, BSTR strReplaceText, long lGradation);
V2.2.0.2修改:
  修改了HttpPost相对路径的一些问题。  
V2.2.0.0增加:
  [id(0x00010041), helpstring("Get Rev Index")]
  HRESULT GetRevCount( [out,retval] long * pbool);
  [id(0x00010042), helpstring("Get Rev Index Info")]
  HRESULT GetRevInfo([in] long lIndex, [in] long lType, [out,retval] BSTR* pbool);
  [id(0x00010043), helpstring("Set Doc Prop")]
  HRESULT SetValue([in] BSTR strValue, [in] BSTR strName, [out,retval] long* pbool);
  [id(0x00010044), helpstring("Set Doc Variable")]
  HRESULT SetDocVariable([in] BSTR strVarName, [in] BSTR strValue,[in] long lOpt, [out,retval] long* pbool);
  [id(0x00010045), helpstring("Save page To Doc")]
  HRESULT SetPageAs([in] BSTR strLocalFile, [in] long lPageNum, [in] long lType,[out,retval] long* pbool);
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
LoadDso.js
var s = ""
s += "<OBJECT id=DSOFramer align='middle' style='LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%'"
s += "classid=clsid:00460182-9E5E-11D5-B7C8-B8269041DD57 codeBase=DSOFramer.ocx#Version=2,2,0,6' >"
s += "</OBJECT>"
document.write(s) 
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
接口文档:

/*
1.新建
*/
//新建Word
document.all.FramerControl1.CreateNew("Word.Document");
//新建Excel
document.all.FramerControl1.CreateNew("Excel.Sheet");
/*
2.打开文件
*/
//打开制定的本地文件
document.all.FramerControl1.Open("C:\\TestBook.xls");
//制定用Word来打开c:\plain.txt文件
document.all.FramerControl1.Open("C:\\Plain.txt",false, "Word.Document");
//打开服务器的文件
document.all.FramerControl1.Open "https://secureserver/test/mytest.asp?id=123",true, "Excel.Sheet", "MyUserAccount", "MyPassword");
//打开服务器的文件
document.all.FramerControl1.Open("http://localhost/1.doc", true);
/*
3.保存文件
*/
//到本地
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);
*/
//初始化Http引擎
document.all.FramerControl1.HttpInit();
//增加Post变量
document.all.FramerControl1.HttpAddPostString("RecordID","20060102200");
document.all.FramerControl1.HttpAddPostString("UserID","李局长");
//上传打开的文件
document.all.FramerControl1.HttpAddPostCurrFile("FileData", "文档名.doc");
//执行上传动作
document.all.FramerControl1.HttpPost("http://xxxx.com/uploadfile.asp");
/*
4.修订留痕
*/
//进入留痕状态
document.all.FramerControl1.SetTrackRevisions(1);
//进入非留痕状态
document.all.FramerControl1.SetTrackRevisions(0);
//接受当前修订
document.all.FramerControl1.SetTrackRevisions(4);
/*
5.设置当前用户
*/
document.all.FramerControl1.SetCurrUserName("张三");
/*
6.设置当前时间(笔迹留痕会显示("Like 2006:02:07 11:11:11")
*/
document.all.FramerControl1.SetCurrTime("2006:02:07 11:11:11");
/*
7.设置和创建书签,此功能比较强大,设置书签数据、添加书签和添加红头文件就靠他了
SetFieldValue(BSTR strFieldName, BSTR strValue, BSTR strCmdOrSheetName)
strFieldName:书签名
strValue:要设置的值
strCmdOrSheetName:
命令
::ADDMARK:: 添加BookMark
::DELMARK:: 删除这个BookMark
::GETMARK:: 定位到这个BookMark
::FILE:: 插入的是文件
::JPG:: 插入的是图片
一般来说:WORD中书签是做好的,可以通过此接口把外界数据设置进书签中去。
*/
//在当前WORD位置插入标签,标签名为"book1",数值为"test"
document.all.FramerControl1.SetFieldValue("book1","test","::ADDMARK::");
//设置书签"Time",数值为"2006-03-16 22:22:22"
document.all.FramerControl1.SetFieldValue("Time","2006-03-16 22:22:22","");
//在书签位置"hongtou",插入红头文件"http://222.222.222.222/hongtou1.doc" 这样,红头就自动插进去了
document.all.FramerControl1.SetFieldValue("hongtou","http://222.222.222.222/hongtou1.doc","::FILE::");
/*
8.设置菜单显示情况
BOOL SetMenuDisplay(long lMenuFlag)
lMenuFlag为以下数值的组合
#define MNU_NEW 0x01
#define MNU_OPEN 0x02
#define MNU_CLOSE 0x04
#define MNU_SAVE 0x08
#define MNU_SAVEAS 0x16
#define MNU_PGSETUP 0x64
#define MNU_PRINT 0x256
#define MNU_PROPS 0x32
#define MNU_PRINTPV 0x126
*/
//只有“新建”菜单可用
document.all.FramerControl1..SetMenuDisplay(1);
//只有“打开”菜单可用
document.all.FramerControl1.SetMenuDisplay(2);
//只有“打开”和“新建”菜单可用
document.all.FramerControl1.SetMenuDisplay(3);
/*

dsoframer用法相关推荐

  1. DSO(dsoframer)的接口文档在VC++使用

    下面是别人的文章,读下面文章可大体了解DSOFramer接口,用的是.net版本的用法.不过了解后可以在VC++工程中导入DSOFramer的控件.自动生成的头文件做一个对比,然后就比较好使用这个控件 ...

  2. c语言中external,static关键字用法

    static用法: 在C中,static主要定义全局静态变量.定义局部静态变量.定义静态函数. 1.定义全局静态变量:在全局变量前面加上关键字static,该全局变量变成了全局静态变量.全局静态变量有 ...

  3. Pandas_transform的用法

    先来看一个实例问题. 如下销售数据中展现了三笔订单,每笔订单买了多种商品,求每种商品销售额占该笔订单总金额的比例.例如第一条数据的最终结果为:235.83 / (235.83+232.32+107.9 ...

  4. Python中yield和yield from的用法

    yield 后面接的是 future 对象 调用方 委托生成器 yield from 直接给出循环后的结果 yield from 委托者和子生成器直接通信 yield from 直接处理stopIte ...

  5. pytorch学习 中 torch.squeeze() 和torch.unsqueeze()的用法

    squeeze的用法主要就是对数据的维度进行压缩或者解压. 先看torch.squeeze() 这个函数主要对数据的维度进行压缩,去掉维数为1的的维度,比如是一行或者一列这种,一个一行三列(1,3)的 ...

  6. python yield 和 yield from用法总结

    #例1. 简单输出斐波那契數列前 N 个数 #缺点:该函数可复用性较差,因为 fab 函数返回 None,其他函数无法获得该函数生成的数列 #要提高 fab 函数的可复用性,最好不要直接打印出数列,而 ...

  7. tf.nn.embedding_lookup()的用法

    函数: tf.nn.embedding_lookup( params, ids, partition_strategy='mod', name=None, validate_indices=True, ...

  8. OpenMP用法大全

    OpenMP基本概念 OpenMP是一种用于共享内存并行系统的多线程程序设计方案,支持的编程语言包括C.C++和Fortran.OpenMP提供了对并行算法的高层抽象描述,特别适合在多核CPU机器上的 ...

  9. Dorado用法与示例

    Dorado用法与示例 dorado用后总结 一.dorado概念 dorado的产品全名是"dorado展现中间件".从产品形态上dorado由两部分组成,第一部分是一个具有AJ ...

最新文章

  1. 在 Windows XP 中,无法使用 Windows 图片和传真查看器来查看图片
  2. Win10打不开jar程序的解决方法 [转载]
  3. citespace与mysql_科学网—如何用CiteSpace整理数据 - 陈超美的博文
  4. 6、删除视图(DORP VIEW)
  5. Android 应用程序发布流程注意事项(整理)
  6. 开心哲理---您的妻子! --转by yp
  7. JScript多语言语法加亮引擎改进(修正多行注释识别)
  8. Linux入门:PuTTY实现Linux和Windows文件互传
  9. python 给定n,返回n以内的斐波那契数列
  10. 试用DreamWeaver CS6
  11. JavaScript数组方法整理
  12. java SE部分以及数据库学习笔记
  13. 项目方案及推进项目的基本流程思路
  14. L2-003 月饼 作者 陈越单位 浙江大学
  15. 域名防劫持 稳定快速。
  16. 【Python3.6爬虫学习记录】(十五)Scrapy爬虫框架的应用及马赛克拼图生成
  17. vc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 ‘context:property-placeholder‘ 的声明。
  18. 程序数据的集散地:数据库
  19. 【LInux】后台执行命令 nohup 以及强制结束进程命令 kill
  20. ubantu14.04装机

热门文章

  1. jquery.slimScroll插件 div添加滚动条
  2. 华为M6平板在录屏的时候报错SIGABRT
  3. html 遍历对象属性,for/in 循环遍历对象的属性
  4. error: utf8mb4_0900_ai_ci
  5. 华为ROADS是什么?
  6. Android源码解析之Bitmap占用内存正确的计算公式 你知道吗
  7. 最懂你的服装设计师是AI?让用户 “凭心意” 生成数字服装#Adidas OZWORLD
  8. SQL语句查询年龄分段分组查询
  9. centos 7 网络设置
  10. 华东师范学院大学计算机考研,华东师范大学-825-2018-计算机考研-真题.pdf