Thanks for your posting and using Aspose.Cells.
You can use ApplyStyle() method for this purpose. Please see the following sample code and its output excel file. As you can see in the output excel file, the entire column F has now Date format.
I have attached both the source and output excel files for your reference.
string filePath = @“D:\Downloads\sample.xlsx”;
//Load excel workbook
Workbook workbook = new Workbook(filePath);
//Access first worksheet
Worksheet worksheet = workbook.Worksheets;
//Create style object
Style style = workbook.CreateStyle();
//Number 14 means Date format
style.Number = 14;
StyleFlag flag = new StyleFlag();
flag.NumberFormat = true;
//Apply style on column F
//Save the workbook
Thanks Shakeel, it works.
Thanks for your feedback and using Aspose.Cells.
Please let me explain how you can find it for yourself. There are two properties relating to it. Style.Number and Style.Custom. The number property deals with built-in Excel formats like number, currency, date etc. The custom property deals with the customize formats which you set yourself using Microsoft Excel.
Whenever you want to find the values of any Number or Custom property, then please first create your desired format in your excel file manually using Microsoft Excel and then load it using Aspose.Cells and observe the values of these properties in Quick Watch or Debug Windows.
Suppose you have set the cell A1 format manually using Microsoft Excel now you can find the values of custom and number properties like the following.
For StyleFlag, all the properties names explain itself. If you are not sure which of them you need to use, then please use StyleFlag.All property.
Please also see the following documentation relating to it for your reference.
( http://www.aspose.com/docs/display/cellsnet/Setting+Display+Formats+of+Numbers+and+Dates )
Cell cell = worksheet.Cells[“A1”];
Style style = cell.GetStyle();
//Now observe the style properties in Quick Watch