none
How to add underlined and strikethru text in cell RRS feed

  • Question

  • Hello,

    I am looking to add some text to a cell in an Excel Worksheet using C#, and i am not sure how to do it.

    For example, if i would want to add "hello, world" (only the word hello as underlined, and the word world as stricken thru), how can this be done?

    Thanks,

    Steve

    Monday, June 11, 2012 7:45 PM

Answers

  • Hello Steve,

    if I understood you correctly, you are looking for the following snippet:

    Excel.Application Application = Globals.ThisAddIn.Application as Excel.Application;
    Excel.Range exRange = Application.get_Range("A1", "A1");
    exRange.Value2 = "Hallo World";
    exRange.Characters[1,5].Font.Underline = true;
    exRange.Characters[6, 5].Font.Strikethrough = true;

    Regards

    Viktor

    Monday, June 11, 2012 8:43 PM
  • What project type and template you used to create your project? What version of Visual Studio, Framework, Office etc?

    As an example, if you use Visual Studio 2010, framework 4.0, Office 2010 and 'Excel 2010 Add-In' template, you should get similar results as mentioned earlier in this post by Viktor.

    kr

    Wednesday, June 13, 2012 4:06 PM

All replies

  • Hello Steve,

    if I understood you correctly, you are looking for the following snippet:

    Excel.Application Application = Globals.ThisAddIn.Application as Excel.Application;
    Excel.Range exRange = Application.get_Range("A1", "A1");
    exRange.Value2 = "Hallo World";
    exRange.Characters[1,5].Font.Underline = true;
    exRange.Characters[6, 5].Font.Strikethrough = true;

    Regards

    Viktor

    Monday, June 11, 2012 8:43 PM
  • Viktor,

    Thank you for the info.  Unfortunately, Intellisense doesn't recognize "Characters" as a member of Range (exRange). Not sure what i'm

    going wrong.

    Monday, June 11, 2012 9:29 PM
  • Hello Steve,

    do you use the namespace Microsoft.Office.Interop.Excel?

    Regards

    Viktor

    Tuesday, June 12, 2012 5:33 AM
  • Yes, i have the following statement in my code:

    using Excel = Microsoft.Office.Interop.Excel;

    Tuesday, June 12, 2012 2:29 PM
  • What is weird is that my application runs and processes the Excel files with no problems.
    Tuesday, June 12, 2012 2:49 PM
  • Sorry, I don't have an idea for your problem. May be someone else has a answer?
    Tuesday, June 12, 2012 4:01 PM
  • What project type and template you used to create your project? What version of Visual Studio, Framework, Office etc?

    As an example, if you use Visual Studio 2010, framework 4.0, Office 2010 and 'Excel 2010 Add-In' template, you should get similar results as mentioned earlier in this post by Viktor.

    kr

    Wednesday, June 13, 2012 4:06 PM