简体   繁体   English

如何在C#winforms中使用Microsoft Excel作为网格控件?

[英]How to use Microsoft Excel as a Grid control in C# winforms?

Are there any good samples of using Microsoft Excel as a grid control in a typical winform C# application. 在典型的winform C#应用程序中是否有使用Microsoft Excel作为网格控件的良好示例。

I have come across a lot of threads talking about excel 'like' control or grid controls with functionality similar to Excel etc. 我遇到过很多关于excel'喜欢'控件或网格控件的线程,其功能类似于Excel等。

Why not use excel as a GRID control , it has all the goodies in build ( formula engine , sorting, filtering etc ) 为什么不使用excel作为GRID控件,它具有构建中的所有好处(公式引擎,排序,过滤等)

You certainly can host Excel as a control within a WinForm application, so part of what you want is possible (with major caveats). 您当然可以将Excel作为控件托管在WinForm应用程序中,因此您可能需要部分内容(主要注意事项)。 However, to wire up the rest of the functionality seen in many of the 3rd party grid libraries takes a lot of work, and has many pitfalls. 但是,要连接许多第三方网格库中看到的其余功能需要大量工作,并且存在许多缺陷。

The prime reason for this is that Excel is a native Windows application, and is not running under the .Net framework. 主要原因是Excel是本机Windows应用程序,并且不在.Net框架下运行。 Therefore, all of the manipulation has to be done at arms length - you have to instantiate the application, instantiate a sheet, try and subscribe to certain events (many of which may not be available as Excel was not designed for this purpose), and, of course, try and propertly manage all of the COM references to avoid memory leaks. 因此,所有操作都必须在一定距离内完成 - 您必须实例化应用程序,实例化工作表,尝试并订阅某些事件(其中许多事件可能不可用,因为Excel 不是为此目的而设计的),以及当然,尝试并有效地管理所有COM引用以避免内存泄漏。

The grid controls you mention have all been built from the ground up as controls to be hosted within .Net applications, and therefore expose properties and events around the type of grid style interactions that people want - remember, Excel is more than a grid. 您提到的网格控件都是从头开始构建的,作为控件托管在.Net应用程序中,因此可以根据人们想要的网格样式交互类型公开属性和事件 - 记住,Excel不仅仅是一个网格。

However, as if to acknowledge that Excel can be a powerful tool when leveraged programmatically, Microsoft provided VSTO - a runtime that allows you to develop Excel (and other office applications) using .Net 但是,似乎承认Excel在编程时可以成为一个强大的工具,Microsoft提供了VSTO - 一个允许您使用.Net开发Excel(和其他办公应用程序)的运行时。

As far as I know, there are no .NET controls for embedding Office applications. 据我所知,没有用于嵌入Office应用程序的.NET控件。

Earlier you could use the DSOFramer to achieve what you want but then it was discontinued. 之前你可以使用DSOFramer来达到你想要的效果,但之后就停止了。 I believe it still works though (I am not sure). 我相信它仍然有用(我不确定)。 The Web Browser (COM) control is an alternative to DSOFramer, but has its own drawbacks. Web浏览器(COM)控件是DSOFramer的替代品,但也有其自身的缺点。 For example, you cannot use the inbuilt "Goodies". 例如,您不能使用内置的“好东西”。

The below is just my personal opinion 以下只是个人的意见

I doubt that MS will never support embedded Office applications and the reason is very simple. 我怀疑MS永远不会支持嵌入式Office应用程序,原因很简单。 MS-Office Applications are "End-User-Targeted" products. MS-Office应用程序是“最终用户目标”产品。 You need separate licenses for it and from a business perspective they wouldn't want to loose on that :) Like I mentioned earlier these are just my personal thoughts and do not echo MS's views. 你需要单独的许可证,从业务的角度来看,他们不想放弃它:)就像我之前提到的,这些只是我个人的想法而不是回应MS的观点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM