简体   繁体   English

如何从C#控件复制并将链接粘贴到Excel中

[英]How to copy from C# control and paste link into excel

I have an application that I want to link to excel. 我有一个要链接到excel的应用程序。 I have no preference which control is used as long as I can copy the data or control, and paste link into excel. 我不喜欢使用哪个控件,只要我可以复制数据或控件,然后将链接粘贴到excel中即可。 When the data changes in my application, I want the cell to change in excel. 当数据在我的应用程序中更改时,我希望单元格在excel中更改。

I have a client that claims it is possible and he has seen it, but has no proof and may be confused. 我有一个客户声称这是可能的,他已经看到了,但是没有证据,可能会感到困惑。

I have searched the internet and have come up with a number of half-solutions, and people who want the opposite of what I want. 我搜索了互联网,并提出了许多解决方案,有些人想要与我想要的相反。 Does anyone know the full solution? 有人知道完整的解决方案吗?

I think you're looking for the IDataObject COM interface. 我认为您正在寻找IDataObject COM接口。

If you expose your data as an OLE object, you can use IDataObject::DAdvise to notify Excel when the data in your application is changing. 如果将数据公开为OLE对象,则可以在应用程序中的数据发生更改时使用IDataObject::DAdvise通知Excel。

This takes some effort, as you have to implement the IDataObject interface (along with a few others) to allow Excel to properly display and host the information you are exposing. 这需要一些努力,因为您必须实现IDataObject接口(以及其他一些接口),以允许Excel正确显示和承载您要公开的信息。

If this is what you're after, here are some links you may find helpful: 如果您要这样做,这里的一些链接可能会有所帮助:

http://winapi.freetechsecrets.com/ole/OLEIDataObjectDAdvise.htm http://winapi.freetechsecrets.com/ole/OLEIDataObjectDAdvise.htm

http://www.catch22.net/tuts/dragdrop/1 (mostly deals with Drag/Drop) http://www.catch22.net/tuts/dragdrop/1 (主要用于拖放)

http://www.catch22.net/tuts/dragdrop/2 (mostly deals with Drag/Drop) http://www.catch22.net/tuts/dragdrop/2 (主要用于拖放)

http://www.catch22.net/tuts/dragdrop/3 (mostly deals with Drag/Drop) http://www.catch22.net/tuts/dragdrop/3 (主要用于拖放)

http://us.generation-nt.com/answer/support-iadvisesink-word-excel-powerpoint-help-26654252.html http://us.generation-nt.com/answer/support-iadvisesink-word-excel-powerpoint-help-26654252.html

http://www.tenouk.com/visualcplusmfc/mfcsupp/ioleobject.html http://www.tenouk.com/visualcplusmfc/mfcsupp/ioleobject.html

Another option would be to develop an Excel plug-in using VSTO. 另一个选择是使用VSTO开发Excel插件。 The difficult part of this architecture would be that you have to implement your own IPC between the source application and the plug in. However, I'd choose this over IDataObject (DDE Emulation) based on prior experience with DDE. 该体系结构的困难之处在于,您必须在源应用程序和插件之间实现自己的IPC。但是,我会根据先前对DDE的经验,选择IDataObject(DDE仿真)为基础。

The advantage of the IDataObject approach is that a typical old school Excel power user will be comfortable with it; IDataObject方法的优点是,典型的老式Excel高级用户会对此感到满意。 and it doesn't require any plug-ins to function. 并且不需要任何插件即可运行。 If the act of dragging the control and dropping onto Excel is an important part of the scenario, then it's probably worth implementing a COM server. 如果将控件拖放到Excel上的行为是该方案的重要组成部分,则可能值得实现COM服务器。 However, if your client isn't familiar with DDE and just wants to have Excel updated dynamically, that's probably not worth the effort. 但是,如果您的客户不熟悉DDE,而只是想动态更新Excel,那可能就不值得付出努力。

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

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