How to get Excel cell fill pattern using c#?

Within an Excel file, how do I go about retrieving a cell's fill pattern? Based on whether a cell has a fill pattern, I want to populate data. Below is what I have tried so far, but "xlPatternNone" is always returned no matter what the cell looks like. Thanks.

Excel.Worksheet workSheet = (Excel.Worksheet)workBook.Sheets[sheetName];
        Excel.Range cell = (Excel.Range)workSheet.Range[column + row.ToString()];
        if ((Excel.XlPattern)((Excel.Style)cell.Style).Interior.Pattern == Excel.XlPattern.xlPatternNone)
            cell.Value = value;

Info: Excel 2007, c#, Microsoft Interop libraries


This definitely works:

var workSheet = (Worksheet) workBook.Sheets["Sheet1"];
var cell = workSheet.Range["A1"];
var style = (XlPattern) cell.Interior.Pattern;

I'd therefore suggest that you ignore the Style property on the cell and just access the cell's Interior directly. If that doesn't work, I'd suggest making sure that column + row.ToString() is definitely pointing at the correct cell.

Need Your Help

When does a cookie with expiration time 'At end of session' expire?

php cookies

There is a session cookie with expiration time which says 'At end of session'.

Java - For loop not executing when trying to search ArrayList

java loops for-loop arraylist

this is my first question on stack overflow but I have some experience in Java. I am making a Java application at the moment (575 lines and counting!) and am trying to search through an ArrayList f...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.