excel - 接口(interface)和扩展ApplicationClass

标签 excel f# office-interop excel-interop

我正在尝试用 F# 编写一个模块,通过提取行、列等以及类型转换等,使使用 Excel 变得更容易。我想做的第一件事就是扩展各种类/类型来实现 IDisposable 接口(interface)。我尝试写如下内容

type Excel.ApplicationClass with
    interface IDisposable with
        member this.Dispose() =
            this.excel.Quit()
            Marshal.ReleaseComObject(this.excel) |> ignore

我没有意识到的是,我会收到以下错误“所有实现的接口(interface)都应该在类型的初始声明中声明”。

我的问题如下:由于我不允许使用接口(interface)扩展类型 - 我还能做什么?

最佳答案

如果你从基类继承它就可以工作,就像这样

type myAppClass() =
    inherit Excel.ApplicationClass() //may not be correct signature - you need to match the base constructor
    interface IDisposable with
        member this.Dispose() =
            //function body

关于excel - 接口(interface)和扩展ApplicationClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21230188/

相关文章:

vba - 交换字符在单元格中的位置

excel - 如何将图像从另一张表复制到事件表

f# - 为什么 "-1"减1不起作用?

c# - 使用 PowerPoint 2010 互操作的笔和记号笔

powershell - Excel自动化速度慢?

excel - Inno Setup - 将组件注册为管理员

Excel VBA : cannot Sum() over Range()

f# - FSharpPlus : the fsi blocks when I try to combine two transformers

f# - 如何从 FAKE 执行 powershell 脚本 - F#MAKE

c# - 从 STA 线程调用 COM 对象导致某些机器上出现 TYPE_E_LIBNOTREGISTERED