Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2005

Tip: Looking for answers? Try searching our database.

Excel Automation Range Background color

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Olan - 24 Aug 2005 22:37 GMT
Hi,

I would like to set the cell background color (and font color later) for a
range of cells in excel using a c# application.

First I set the BackColor of a textbox on a windows form to the color I
would like to apply to the Excel cell/range. the color in this case is
RGB(255,128,128) or {RGB=0xffff8080} from the colorDialog.

The following works fine but I need to replace the "255" with the Backcolor
of the textbox.

rng = (Excel.Range)ws.Cells[2,2];
ws.get_Range(rng,rng).Interior.Color  = 255;  Red
or
ws.get_Range(rng,rng).Interior.Color  = 65535;  Yellow

In vba I can use :

Cells(1, 1).Interior.Color = RGB(255, 128, 128)

But I haven't managed to get the automation from c# to work.

Any assistance welcome :-)

Cheers
Olan
Dirk Behnke - 26 Aug 2005 19:16 GMT
> Hi,
>
[quoted text clipped - 23 lines]
> Cheers
> Olan

Hi,
use
Cells(1.1).Interior.Color=System.Drawing.Color.FromArgb(yourTextBox.BackColor.R,yourTextBox..BackColor.G,yourTextBox..BackColor.B);

Regards,
Dirk
sprasad - 14 Nov 2005 07:49 GMT
Hi,
  I have tried setting the color using System.Drawing.Color.FromArgb,but it
gives type mismatch..

Regards,
Prasad

> > Hi,
> >
[quoted text clipped - 30 lines]
> Regards,
> Dirk
Dirk Behnke - 18 Nov 2005 13:22 GMT
> Hi,
>    I have tried setting the color using System.Drawing.Color.FromArgb,but it
[quoted text clipped - 37 lines]
>>Regards,
>>Dirk

Just
Cells(1.1).Interior.Color=System.Drawing.Color.FromArgb(yourTextBox.BackColor.R,yourTextBox.BackColor.G,yourTextBox..BackColor.B).ToArgb;

I'm now just wondering if there is an easier way to achieve that. Seems
to be some duplication

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.