Microsoft.Office.Interop.Excel.Worksheet.Cells[x,y].Style?

33,689

you have to cast the object as a Range.

The Range interface/object contains all the style and value information for the cell or range that you are specifying.

some examples:

((Excel.Range)ws.Cells[r, c]).NumberFormat = format;
((Excel.Range)ws.Cells[r, c]).Value2 = cellVal;
((Excel.Range)ws.Cells[r, c]).Interior.Color = ColorTranslator.ToOle(Color.Red);
((Excel.Range)ws.Cells[r, c]).Style.Name = "Normal"

etc etc and so on.

Have a link: https://docs.microsoft.com/en-us/office/vba/api/Excel.Range.Style

Share:
33,689
King King
Author by

King King

I was so lucky when reaching this reputation point :) Mainly focus on .NET (C#), program in all possible platforms using .NET technology: WPF for desktop development, ASP.NET MVC/Core for web development and Xamarin Forms for mobile development. It's true that you have to spend your whole life just to learn everything about .NET not even other fields of programming, software development and information technology. Feeling buried in the colossal world of IT. My contacts e: [email protected] Facebook LinkedIn For those who prefer the so-called FireFox (tested on v.33.0.2), just try this Flying flag effect to see how fast it is, also try that demo on Chrome, Opera and IE to see the difference. Now it's time for webkit-based browsers SUCKing. So technically all the browsers suck their own problems. Here is the test demo showing that. This time, IE 11 and FireFox 31 pass the test while all webkit-based browsers (Google Chrome 38, Opera 25, Maxthon 4.4.1.5000) suck.

Updated on April 23, 2021

Comments

  • King King
    King King almost 3 years

    I found some code which uses Style property of Microsoft.Office.Interop.Excel.Worksheet.Cells[x,y] but it is treated as an object in my Visual Studo code editor:

    Workbook wb = new Application.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
    Worksheet ws = wb.Sheets[1];
    ws.Cells[x,y] is simply treated as an object so how can I use its Style property?
    

    I'm using Microsoft Excel 15.0 Objects Library (goes with Microsoft Office 2013). Does that matter?

    Could you please explain this to me? Thank you.