Date value in the cell not received as string

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
ykarapinar
Posts: 22
Joined: Fri May 17, 2013 7:59 am

Date value in the cell not received as string

Post by ykarapinar »

Code: Select all

procedure TForm1.Button_ExportClick(Sender: TObject);
var
  d1, d2: TDate;
begin
  d1:=Now;
  d2:=EncodeDate(2000, 1, 1);
  XLSReadWriteII51.FileName:='C:\xls_date.xlsx';
  XLSReadWriteII51.Sheets[0].AsDateTime[0, 1]:=d1;
  XLSReadWriteII51.Sheets[0].AsDateTime[0, 2]:=d2;
  XLSReadWriteII51.Write;
end;

procedure TForm1.Button_ImportClick(Sender: TObject);
var
  date_1, date_2: String;
begin
  XLSReadWriteII51.FileName:='C:\xls_date.xlsx';
  XLSReadWriteII51.Read;
  date_1:=XLSReadWriteII51.Sheets[0].AsString[0, 1];
  date_2:=XLSReadWriteII51.Sheets[0].AsString[0, 2];
end;
date_1
result is : 42060,6691537268
should be : '25.02.2015 16:03:35'

date_2
result is : 36526
should be : '01.01.2000'
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Date value in the cell not received as string

Post by larsa »

Hello

Use AsFmtString if you want the formatted cell value (there are no date cells in excel, it's just number cells formatted as date).
Lars Arvidsson, Axolot Data
Post Reply