获得C#中的当前工作簿对象 [英] Get the current Workbook Object in C#
问题描述
我已经写在C#这在Excel电子表格中创建自定义文档属性的应用程序,我有这样的函数,它接受一个工作簿对象...
I've been writing an application in C# which creates Custom Document properties in an Excel spreadsheet, I have a function for this which takes in a Workbook Object...
然而,实际上获得当前工作簿对象已经被证明是很烦人,我使用ExcelDNA添加功能,但是,我似乎无法通过我的功能有效的工作簿COM对象。
However, actually getting the current Workbook object is proving to be quite annoying, I am using ExcelDNA to add functionality, however, I can't seem to pass my function a valid Workbook COM object.
推荐答案
这是我目前做的方式似乎工作得很好。
This is the way I am currently doing it it seems to work really well
using Excel = Microsoft.Office.Interop.Excel;
然后你得到活动的工作簿
Then you get active workbook
//Gets Excel and gets Activeworkbook and worksheet
Excel.Application oXL;
Excel.Workbook oWB;
Excel.Worksheet oSheet;
oXL = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
oXL.Visible = true;
oWB = (Excel.Workbook)oXL.ActiveWorkbook;
docProps = oWB.CustomDocumentProperties
那我就试试你有什么,看看它是如何工作的。
Then I would try what you have and see how it works
希望这有助于
这篇关于获得C#中的当前工作簿对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!