Embedding ms-office in C# Forms (from http://www.cube316.net)

I encounter this problem in my project recently. It is not an easy work to embed office documents for interoperability purposes in C# winform. Basically we have the following candidates:

ActiveDocumentHost

This is supposed to be the ideal solution for the topic, but due to some unknown reason, Microsoft has dropped it off after VS.NET version 2.0 Alpha. I didn’t have the chance to have a try because there’s no alpha version available on the internet nowadays. Hope the future version of VS will provide an alternative work around.

WebBrowser

This is the working solution now Microsoft recommends. You can find more information here.
But to me, this control is a bit heavy-weighted. One can not easily have accurate control over the toolbars and other components neither.

Office Web Controls (OWC)

The OWC can be added to the Visual Studio.NET toolbox (from the COM Components tab) and dragged onto your WinForm designer. But it only contains a subset of the office application functionality (i.e.: Excel) thus is not under consideration any more.

dsoFramer

This is the important control on which I have spent lots of time doing investigation. It is originally developed by Microsoft as a C++ ActiveX control sample to host/embed ms-office documents (download here). But unfortunately it also have several bugs:

  1. The title of the host application will go garbled when the control is disposed. (Fixed here)
  2. Event can not be fired correctly when embedded directly in a winform control. (Fixed here)
  3. Events can not be fired when wrapped in a C# user-control. (not fixed)
  4. Call DSOFramer to handle word in IE cause IE crash.(Fixed here)
  5. Word 2007 files will be deleted after saving. (Fixed here)
  6. Files are locked so the upload action will always fail. (Fixed here)
  7. Can not start a separate office process to handle the documents if there is already an existing one. This may lead to miscellaneous bugs such as: no response of toolbar, can not start office externally after control is initialized, redo/undo influence all the instances instead of the active one, etc. (not fixed)

Here I provide a pre-combined version for download, which fixes the above-mentioned 1,2,4,5 items. But item 6 seems to be a big headache.
For someone who may concern about the modified source code, please leave your email address here so that I can send it to you.

Further more, we are currently trying another method.

Some hint: starting individual office process in our application and have its lifetime under control. But this is still experimental and nothing is guaranteed.

This post is written in a hurry so please point it out if you find anything wrong, and any information or suggestions is always welcomed.

Important update:

Several days after this post, I found Microsoft has released a new version of DsoFramer (1.3) while the download address is still the old one.

The above-mentioned version I modified is based on 1.2, thus maybe it’s not compatible with 1.3. And I haven’t done full test to this new version yet. So use at your own risk. Please see this update article for comments on version 1.3.

References:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值