Free Support Forum - aspose.com

Style Problem with dates

I have set the style.number property to 14 (Date), it apprears that the last cell that gets written out is still in general format and the cell shos the date as a number, not in date format. I am Setting the stlye before the putvalue:

cell.Style.Number = 14

cell = xlCells(CellLetter & (CellNumber + rowCounter))

cell.PutValue(ROL.Item(CellData(1)))

Any help would be great

Hi,

Well, you have to convert your string value to datetime value using the overloaded version of the method i.e., Cell.PutValue(stringval, isConverted), isConverted should be true if you want to automatically convert the value to its related format. I think you can try to change the line of code to:

e.g.,

cell.Style.Number = 14

cell = xlCells(CellLetter & (CellNumber + rowCounter))

cell.PutValue(ROL.Item(CellData(1)), True)

My Sample code:

Dim workbook As Workbook = New Workbook()
Dim worksheet As Worksheet = workbook.Worksheets(0)
Dim cells As Cells = worksheet.Cells
cells("A1").PutValue("9-2-2003",True)
cells("A1").Style.Number = 14
workbook.Save("d:\test\ot_format_cells.xls")

Thank you.