views:

211

answers:

1

Hi,

I have an XSL file that I am generating from CSV from and Object etc. etc. Everything is done except that I need to highlight particular rows in the xsl file. I don't want to have to open Excel and use Macros.

Is there a way to do this in C#?

+1  A: 

Do you mean XLS and not XSL?

If so, here's a link that explains the basics of how to use Excel as an object. Since you're opening it as an object, it won't be visible (unless you want it to be), but you'll have full access to navigate, highlight rows, and do whatever else you would normally do in Excel. When done, dispose the object.

Connecting to and navigating Excel through C#

Sarkazein
Thanks I will check out the link right now and see if it works for me. At first glance I don't see the ability to highlight rows though.
Proximo
When connecting to Excel as an object, each piece of Excel is also an object, including rows, cells, etc. That's how you expose their properties. Search for "get_Range" on MSDN and then look at the "Worksheet Members" link at the bottom and you'll see all the exposed members. Keep in mind that the worksheet itself is an object. Therefore, something like this used in the example code linked above would work:Console.WriteLine("Number of Rows: " + excelWorksheet.Rows.Count.ToString());Play with IntelliSense and you should be able to figure it out.
Sarkazein
Sweet, it worked very well. Thanks!
Proximo