Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:28:02+00:00 2026-06-16T03:28:02+00:00

I am trying to process data in an Excel worksheet passed from a C#

  • 0

I am trying to process data in an Excel worksheet passed from a C# class to an F# class library.
The C# project is an Excel AddIn project the F# class is this.

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

So if I call the class from C# like this

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
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:28:03+00:00Added an answer on June 16, 2026 at 3:28 am

    Interop between F# and C# isn’t a problem. You have various errors in your F# class:

    1. You cast an Object sh to Worksheet sht, but mistakenly use sh instead of sht later.

    2. Range doesn’t have Item property.

    3. You add virtually everything related to Excel programming into the project. You only need Microsoft.Office.Interop.Excel in this example. It’s better to remove unnecessary open commands, especially Microsoft.Office.Tools.Excel which is opened after Interop.Excel could have objects of the same names but have incompatible fields/interfaces.

    4. You should pass a Worksheet instead of an obj to avoid downcasting.

    A minimal F# example that works:

    namespace DataLib
    
    open Microsoft.Office.Interop.Excel
    
    type Class1() = 
        member this.X = "F#"
        member this.Readsheet (sh: Worksheet) =
            let v = sh.Cells.[1, 1]
            sh.Range(1, 1).ToString()
    

    Moreover, your C# syntax is a bit off, you need something like:

    // Add "using Microsoft.Office.Interop.Excel;" 
    // and "using DataLib;" to namespace declarations
    public void useExcel(Worksheet sh) // Worksheet is Excel Interop object
    {
        Class1 one = new Class1();
        one.Readsheet(sh);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read data from an Excel sheet using Office.Interoperability.Excel namespace. I'd like
I'm trying to process data obtained from a run of diff to an instance
So I'm trying to automate a pretty tedious data gathering process from hundreds of
While trying to process and obtain data from an XML document, I want to
I am trying to import data from excel to Sql Server using Import wizard.
I am trying to insert some data from excel file into a table. I
Trying to find a standard. The CmdLet will process data - multiple input, defined
I am trying to process the submitted results for a form, containing data for
I am trying to process 114,000 rows in a dataset (populated from an oracle
I'm trying to process this array, first testing for the presence of a check,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.