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 6824577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:55:05+00:00 2026-05-26T21:55:05+00:00

Inside a c# UDF for excel 2007, I need to evaluate the value of

  • 0

Inside a c# UDF for excel 2007, I need to evaluate the value of Excel function parameters (don’t ask why, long story).

Let’s say we have this Excel function to evaluate :

=afunctionname(“2009-01-01” ; “B4” ; “foo” ; concatenate(“a”;”b”) )

My goal is to get a string with :

=afunctionname(“2009-01-01” ; “value of B4 cell” ; “foo” ; “ab” )

I evaluate the value of the params thank to this snippet :

Object comObject = app.Evaluate(param); //app = Microsoft.Office.Interop.Excel.Application
String value = getValueFromComObject(comObject);

getValueFromComObject detail :

private static String getValueFromComObject(Object comObject)        {
    if ((comObject as Range) != null)
                {
                    Range rge = ((Range)comObject);

                    switch (Type.GetTypeCode(rge.Value.GetType()))
                    {
                        case TypeCode.DateTime:
                            return ((DateTime)rge.Value).ToShortDateString();
                        default:
                            return rge.Value.ToString().Trim();
                    }
                }
                else
                {
                    return comObject.ToString();
                }
}

The fist and third params of our example directly return as String by application.Evaluate . The second param is return as a range and correctly managed thank to the type casting.

The problem is for the fourth param, I dont know witch cast type I have to apply on the evaluation of the concatenation function, it’s obviously not a range and the toString() gives me the reference : -2146826273

Any idea?

  • 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-05-26T21:55:06+00:00Added an answer on May 26, 2026 at 9:55 pm

    Ok I found the problem 🙂 !

    First of all the return type is an Int32 and the return value correspond to the error code #value according to this page : How to know if a cell has an error in the formula in C#

    Actually, the lengh of the Strings were too long for the concatenate function in eval mode, I have try in Excel it works but with eval it gives me an error. So I just had to reduce the lengh of each string in concatenate method (add more params) and it works.

    Thank you all for your help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inside my template function I have the following code: TypeName myFunction() { TypeName result;
Inside a function I have created, I have this loop that checks if the
Inside a function of mine I construct a result set by filling a new
Hi I have created an udf function in sqlserver 2008... when i try to
I need to write a UDF that would try to cast a varchar to
Inside my php I have a function which creates a connection to my db,
// inside $(document).ready function... var name = ''; function test() { $.post('/student/get-info', function(data) {
Inside phpMyAdmin, I am working with custom meta fields in WordPress. Say I have
Inside my function there is an if() statement like this: if(passedValue < staticValue) But
Inside a django template I'm trying to call the split function on one of

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.