Ranges

Hi,

I need to create a range consisting of a column so that I can change the cell format to custom to enable me to set dd/mm/yyyy. However the first row is a header row so I'm guessing I don't want to change that to a date/time format. What is the best way to do this?

Thanks

Steve


Hi,


Well, it does not matter if you also set the custom date formatting to header cell, your header text would look fine. Anyways, see the sample code below:
//…
//Define a style object adding a new style
//to the collection list.
Style stl5 = workbook.Styles[workbook.Styles.Add()];
//Set custom number format.
stl5.Custom = “dd/mm/yyyy”;
StyleFlag flag = new StyleFlag();
flag.NumberFormat = true;

//Create a named range of cells (B2:B100)in the first worksheet.
Range range = workbook.Worksheets[0].Cells.CreateRange(“B2”, “B100”);
//Apply the style to cells in the named range.
range.ApplyStyle(stl5, flag);

Thank you.