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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:45:04+00:00 2026-05-23T10:45:04+00:00

How to evaluate an Excel format string programmatically? I am programmatically creating Excel cells

  • 0

How to evaluate an Excel format string programmatically?

I am programmatically creating Excel cells based on data in a certain format, e.g xml in
some of the the cells; there are format strings that need to be applied to them.

e.g “[Red] #,##0.00” for 987564.63635

before filling into the cell, I want to check (basically only colors) for the cell or text.
In case it is won’t display well to the user, e.g light yellow is very bad, a user can hardly see this color.

So it comes to before creating the cell, I need to know the color from the format string
e.g “[Red] #,##0.00” or “[Color 32] dd/mm/yyyy” or an even more complex Excel format string.

I want to know. Is there some kind of library that can do this job?
or does .net have this kind of function already?
or i have to do it by myself?

Sample

e.g
if format string is “[Red] #,##0,00”,
i want to know the corresponding Sysmte.draw.Color for the [Red] base on the string.
or the corresponding web color, ff0000, for [Red] base on the string
or corresponding RGB values

  • 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-23T10:45:04+00:00Added an answer on May 23, 2026 at 10:45 am

    You can use the Excel range object to access all the cell’s configuration setup.

    for example:

    Worksheet sheet = excelApp.ActiveWorkbook.ActiveSheet;
    Range r = sheet.Cells[1, 1];
    MessageBox.Show(r.Value2 + "\n" + r.Text + "\n" + r.NumberFormat);
    

    r.Value2 holds the underline value of the cell (the formula).

    r.Text holds the visible (user) value of the cell (the result).

    r.NumberFormat holds the format string – in your example it will hold the “[Red] #,##0.00”.

    From there you’ll need to use any string manipulation techniques on the NumberFormat member (i recommend a regular expression) to find the color you are looking for or any other thing.

    EDIT, here is some usage of regExp and TypeCovertor to accomplish the string to Color object conversion. (with a continue to the above source)

    string formatString = r.NumberFormat;
    Regex colorRegExp = new Regex(@"^\[(?<color>\S+)\]", RegexOptions.Compiled);
    
    Color resultColor;
    System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(new Color());
    
    Match m = colorRegExp .Match(formatString);
    if (true == m.Success)
    {
       string colorString = m.Groups["color"].Value;
       resultColor = (Color)converter.ConvertFromString(colorString);
    }
    

    The regular expression object is compiled to the assembly for performance. I assume using the Color resultColor object is something you can figure yourself (it has ARGB and other members to examine).

    And last comment, you can easily reduce the number of lines in this example, i just wanted to emphasize each step on the way.

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

Sidebar

Related Questions

I have a problem with some excel code that I am having trouble getting
I have some fairly old code that runs just fine in Excel versions before
I have an Excel 2007 workbook that contains tables of data that I'm importing
I have about 50 or so Excel workbooks that I need to pull data
I have a subroutine in excel that I would like to write data to
For some reasons I evaluate the option to exchange data between my iOS-App and
A few questions have come up recently involving the Application.Evaluate method callable from Excel
I need to evaluate a mathmatical expression that is presented to me as a
Whey does this evaluate to true? <?php $val2=0; //outputs that is an error123 if($val2=='error123'){
I am trying to evaluate the following from a string boolean value = evaluate(false

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.