views:

1729

answers:

1

I'm using the office 2007 interop assemblies to create some excel spreadsheets.

There are plenty of questions on here about getting started and MSDN contains heaps of articles, like this one.

The API is funky, and sometimes a bit confusing.

When I set a value of a cell, is there a way to set it's format? I'd like to mark particular fields as Date's so my customer can run excel macros on them. Also, numbers would be useful.

Thanks!

A: 

VBA based code. However same should work with c# (ignore the syntax).


cells(1,1).Value = 39875
cells(1,1).NumberFormat = "dd-mmm-yyyy"

The best way to learn Excel Object Model is to create a macro of actions you wish to take, look at the code & modify the parts which require external input. Also, the object model is pretty easy to understand (Application -> Workbook -> Worksheets -> Worksheet -> Range (Cell)).

shahkalpesh