Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2009, 12:04 AM
Registered User
 
Join Date: May 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I get two different fonts/color in one cell in Excel

I need to Display something like this:


This is ALL in one cell


HELP - How do I do that?


The best reference I have is:


Code:
Microsoft.Office.Tools.Excel.NamedRange charactersRange;
private void FormatCharacters()
{
charactersRange = this.Controls.AddNamedRange(
this.Range["A1", "A1"], "charactersRange");
this.charactersRange.Value2 = "Smith";
this.charactersRange.Characters[1, 1].Font.Bold = true;
this.charactersRange.Characters[1, 1].Font.Size = 14;
}
From: http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.namedrange.characters (VS.80).aspx


But I can't seem to get the namespace/Reference correct....
I can change any cell to any color/font/size/alignment/ect.. even add hyperlink correctly but can't seem to get two fonts or color type in same cell.....
It's gotta lie with "NamedRange" / "Character" reference..
.just can't get it to compile or work.... PLZ help.....

Sample Working Code from my project:

Code:
 
((Excel.Range)oSheet.Columns["A:M", Type.Missing]).Font.Size = 9;
oSheet.get_Range("L1", "L1").Interior.ColorIndex = 15;
oSheet.get_Range("A1", "L1").EntireColumn.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
oSheet.get_Range("A:A", "L:L").VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
oSheet.get_Range("A:A", "L:L").HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
 
oSheet.Hyperlinks.Add(oSheet.get_Range("A" + tempRowCount, Type.Missing), tempHyperLink, Type.Missing, "Reference to:" + listView3.Items[row].SubItems[col].Text.ToString(), listView3.Items[row].SubItems[col].Text.ToString());
 
Old May 19th, 2009, 01:20 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Can you try something similar to

Code:
Excel.Range range;
range = objSheet.get_Range("A1", Missing.Value);
range.Characters[19, 4].Font.Bold = true
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get Excel Cell color populate .NET Framework 2.0 2 March 3rd, 2014 04:25 AM
Filling a Oval in a Excel Cell with Color sinajs Excel VBA 0 January 22nd, 2007 01:47 PM
Change Cell Color phungleon HTML Code Clinic 2 April 9th, 2006 12:36 AM
Fill color in Excel Cell Anantsharma Excel VBA 14 October 25th, 2004 07:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.