我正在尝试处理从 C# 类传递到 F# 类库的 Excel 工作表中的数据。C# 项目是一个 Excel AddIn 项目,F# 类是这个。
namespace DataLib
open System
open System.Reflection
open System.Collections.Generic
open FSharpx.TypeProviders.Excel
open Microsoft.FSharp.Core.CompilerServices
open System.IO
open System.Linq
open System.Text
open System.Windows.Forms
open Microsoft.Office.Core
open Microsoft.Office.Interop.Excel
open Microsoft.Office.Tools.Excel
type sheet = Microsoft.Office.Interop.Excel.Worksheet
type Class1() =
member this.X = "F#"
member this.Readsheet (sh:obj)=
let sht = sh:?>Worksheet// exception here
let v=sh.Cells.[1,1] // Exception COM object does not have Cells property etc...
sh.Range.Item(1,1).ToString() //error here ca
所以如果我像这样从 C# 调用类
using DataLib;
public void useExcel(sh as Excel.Worksheet) //Excel.Worksheet is Excel Interop object
{
Class1 one = new Class1()
one.Readsheet(sh) //Exception thrown here in F# class
}