使用c#写入excel中的单元格 [英] Write to cell in excel using c#

查看:133
本文介绍了使用c#写入excel中的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含ThisWorkbook类的视觉工作室excel工作簿项目,然后我包含一个函数类,以便我可以创建自己的excel函数。我正在尝试通过使用该函数使用c#向单元格写入一个值。我可以通过函数类写入excel单元格,但只能通过创建一个新的应用程序/工作簿。所以每次我使用这个excel函数,它都会打开新的excel实例。有没有办法写入目前已经打开的excel工作簿中的单元格?

解决方案

你可能会创建一个新的Excel应用程序,而不是连接到活动的Excel应用程序。



使用 GetActiveObject 以获取对Excel应用程序对象的引用。


I created a visual studio excel workbook project which contains ThisWorkbook class and I then included a functions class so that I can create my own excel function. I am trying to write a value to a cell using c# through the use of the function. I can write to the excel cell through the function class but only by creating a new application/workbook. So everytime I use this excel function, it will open new instance of excel. Is there a way I can write to a cell in the current excel workbook that is already opened?

解决方案

You probably create a new Excel application, instead of connecting to the active Excel application.

Use the GetActiveObject to get your reference to the Excel application object.

这篇关于使用c#写入excel中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆