Yeah you are right, the order of yy mm dd cannot be changed unless we remove the number format of each cell.
TQ for the code sample but I think it cannot solve my problem because the worksheets are not created by me and
and the user might set the date/number format in different way.
After spending some time to study this issue, I think it would be better for me to modify the readasText function in
a classhelper for my own purpose. As follows:
function TSheetHelper.ReadAsStr(ARow, ACol: Cardinal;
DateFmt:string = 'yyyy-mm-dd'; NumFmt: string= '##0.00'): string;
var
ACell: PCell;
hyperlink: PsHyperlink;
begin
Result := '';
ACell := GetCell(ARow, ACol);
with ACell^ do
case ContentType of
cctUTF8String:
Result := UTF8StringValue;
cctNumber:
Result := FormatFloat(NumFmt, NumberValue);
cctDateTime:
Result := FormatDateTime(DateFmt, DateTimeValue);
cctBool:
Result := StrUtils.IfThen(BoolValue, STR_TRUE, STR_FALSE);
cctError:
Result := GetErrorValueStr(TsErrorValue(ErrorValue));
else // blank --> display hyperlink target if available
Result := '';
if HasHyperlink(ACell) then
begin
hyperlink := FindHyperlink(ACell);
if hyperlink <> nil then Result := hyperlink^.Target;
end;
end;
end;
The above code is largely taken from fpspreadsheet.pas and it works so far. Only thing I wish to ask is about the 'else' case (line 2873 fpspreadsheet.pas):
(i) why do we have to set result to '' again? and (ii) shoud I change this part to
...
else // blank --> display hyperlink target if available
if HasHyperlink(ACell) then
begin
hyperlink := FindHyperlink(ACell);
if hyperlink <> nil then Result := hyperlink^.Target;
end;
...