获得C#中的当前工作簿对象 [英] Get the current Workbook Object in C#

查看:232
本文介绍了获得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屋!

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