Working with dates

I am creating a spreasdsheet


Inserts the date into the column ok. But I can't figure out how to change the cell/ column from General (which shows the date as a number) to ShortDate

I need the final spreadsheet to be opened in Excel with the dates showing as dates.

Normally the easiest way to answer this kind of questions is to use APIMate. Just create an empty file in Excel, write a date in A1, save the file and open it in APIMate (search for apimate in the start menu)

This is the code I get here:

  fmt := xls.GetCellVisibleFormatDef(1, 1);
  fmt.Format := TFlxNumberFormat.RegionalDateString;
  xls.SetCellFormat(1, 1, xls.AddFormat(fmt));
  xls.SetCellValue(1, 1, TFlxDateTime.ToOADate(EncodeDate(2000, 1, 1), xls.OptionsDates1904));

Note that you can also set the format and the value in a single call, to make it a little more efficient. For that, you need to specify the XF in the SetCellValue call (see )

So the final code could be:

  fmt := xls.GetCellVisibleFormatDef(row, 10);
  fmt.Format := TFlxNumberFormat.RegionalDateString;

  xls.SetCellValue(1, 1, psAdjtDate.AsDateTime, xls.AddFormat(fmt));

Thanks. Worked Perfectly