by DaviWall » Wed Jul 23, 2008 6:56 pm
I'm very proud to announce that I've found a solution for your problem ( which is mine also ).
Basically OleObject only understand dates in American format (MM/DD/YYYY), it doesn't take in consideration Computer Regional Settings. When you send a text date to a cell it tries to convert the cell to date format. As the date is invalid the cell remains as text format.
This will produce a TEXT fomatted cell:
Ex: Let's say HC.Text := '23/12/2008' (DD/MM/YYYY)
Sheet.Cells[hc.Range[0] + FFixedRowsExt + 1 + 2 * Ord(Title <> ''), k + 1] := HC.Text;
Now, if you convert the date from DD/MM/YYYY to MM/DD/YYYY the OleObject will be able to succesfully convert this cell to date format as it is a valid date for the Object.
This will produce a DATE fomatted cell:
Ex: Let's say HC.Text := '23/12/2008' (DD/MM/YYYY)
Sheet.Cells[hc.Range[0] + FFixedRowsExt + 1 + 2 * Ord(Title <> ''), k + 1] := FormatDateTime('MM/DD/YYYY',StrToDatetime(HC.Text))
Conclusion, when you open this file in Excel, it understands this cell as date and use the regional settings to format it!
So in the end, I believe that no matter what date format / language the computer is using, you have always to pass the date in American format.
This is the change I did for my own need:
if TryStrToDate(hc.Text, Data) then
Sheet.Cells[hc.Range[0] + FFixedRowsExt + 1 + 2 * Ord(Title <> ''), k + 1] := FormatDateTime('MM/DD/YYYY',StrToDatetime(HC.Text))
else
Sheet.Cells[hc.Range[0] + FFixedRowsExt + 1 + 2 * Ord(Title <> ''), k + 1] := HC.Text;
Why am I telling you this? Cuz I'm looking for a job...(no, just kidding)
It's just that I don't wanna have go over this change everytime I get a new update of PivotCube.
I even hope you find a more elegant solution for this problem.
Thank you for your time.
Davi Wall.