How to add underlined and strikethru text in cell
-
Monday, June 11, 2012 7:45 PM
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
All Replies
-
Monday, June 11, 2012 8:43 PM
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
- Marked As Answer by Quist ZhangMicrosoft Contingent Staff, Moderator Monday, June 25, 2012 9:49 AM
-
Monday, June 11, 2012 9:29 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.
-
Tuesday, June 12, 2012 5:33 AM
Hello Steve,
do you use the namespace Microsoft.Office.Interop.Excel?
Regards
Viktor
-
Tuesday, June 12, 2012 2:29 PM
Yes, i have the following statement in my code:
using Excel = Microsoft.Office.Interop.Excel;
-
Tuesday, June 12, 2012 2:49 PMWhat is weird is that my application runs and processes the Excel files with no problems.
-
Tuesday, June 12, 2012 4:01 PMSorry, I don't have an idea for your problem. May be someone else has a answer?
-
Wednesday, June 13, 2012 4:06 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
- Marked As Answer by Quist ZhangMicrosoft Contingent Staff, Moderator Monday, June 25, 2012 9:49 AM

