* Correction to r2863: use ISO 8601 format for WriteDateTime text output (currently every format except BIFF8 xls).

Ensures resulting files are interoperable regardless of OS locale settings, conforming to date/time cell support in BIFF8.



git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2865 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
bigchimp
2013-12-23 12:11:20 +00:00
parent f7dfeba208
commit 6a4ff4c1c2
7 changed files with 44 additions and 21 deletions

View File

@ -85,7 +85,6 @@ type
const AOverwriteExisting: Boolean = False); override;
procedure WriteToStream(AStream: TStream; AData: TsWorkbook); override;
{ Record writing methods }
//todo: add WriteDate
procedure WriteFormula(AStream: TStream; const ARow, ACol: Cardinal; const AFormula: TsFormula; ACell: PCell); override;
procedure WriteLabel(AStream: TStream; const ARow, ACol: Cardinal; const AValue: string; ACell: PCell); override;
procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); override;
@ -710,14 +709,20 @@ begin
' </table:table-cell>' + LineEnding;
end;
{
Writes the date/time as a text to the sheet.
Currently, no formatting code is written.
}
{*******************************************************************
* TsSpreadOpenDocWriter.WriteDateTime ()
*
* DESCRIPTION: Writes a date/time value as a text
* ISO 8601 format is used to preserve interoperability
* between locales.
*
* Note: this should be replaced by writing actual date/time values
*
*******************************************************************}
procedure TsSpreadOpenDocWriter.WriteDateTime(AStream: TStream;
const ARow, ACol: Cardinal; const AValue: TDateTime; ACell: PCell);
begin
WriteLabel(AStream, ARow, ACol, FormatDateTime('c', AValue), ACell);
WriteLabel(AStream, ARow, ACol, FormatDateTime(ISO8601Format, AValue), ACell);
end;
{

View File

@ -1,5 +1,5 @@
{
Utility functions from FPSpreadsheet
Utility functions and constants from FPSpreadsheet
}
unit fpsutils;
@ -14,6 +14,11 @@ uses
type
TsSelectionDirection = (fpsVerticalSelection, fpsHorizontalSelection);
const
// Date formatting string for unambiguous date/time display as strings
// Can be used for text output when date/time cell support is not available
ISO8601Format='yyyymmdd"T"hhmmss';
// Endianess helper functions
function WordToLE(AValue: Word): Word;
function DWordToLE(AValue: Cardinal): Cardinal;

View File

@ -29,10 +29,10 @@ var
type
{ TSpreadReadDateTests }
// Read from xls/xml file with known values
// Read from xls/xml file with known values to test interoperability with Excel/LibreOffice/OpenOffice
TSpreadReadDateTests= class(TTestCase)
private
// Tries to read date in column A, specified (0-based) row
// Tries to read date from the external file in column A, specified (0-based) row
procedure TestReadDate(FileName: string; Row: integer);
protected
// Set up expected values:

View File

@ -3,6 +3,9 @@ unit formattests;
{$mode objfpc}{$H+}
interface
//todo: look at getting read tests from existing xls cells
//todo: date/time sheet name is confusing=>already existing date sheet 'Dates'
//todo: add incorrect/out of range values for testing
uses
// Not using lazarus package as the user may be working with multiple versions

View File

@ -412,14 +412,16 @@ end;
* TsSpreadBIFF2Writer.WriteDateTime ()
*
* DESCRIPTION: Writes a date/time value as a text
* ISO 8601 format is used to preserve interoperability
* between locales.
*
* No further formatting applied.
* Note: this should be replaced by writing actual date/time values
*
*******************************************************************}
procedure TsSpreadBIFF2Writer.WriteDateTime(AStream: TStream;
const ARow, ACol: Cardinal; const AValue: TDateTime; ACell: PCell);
begin
WriteLabel(AStream, ARow, ACol, FormatDateTime('c', AValue), ACell);
WriteLabel(AStream, ARow, ACol, FormatDateTime(ISO8601Format, AValue), ACell);
end;

View File

@ -877,17 +877,19 @@ begin
end;
{*******************************************************************
* TsSpreadBIFF5Writer.WriteDateTime ()
* TsSpreadBIFF2Writer.WriteDateTime ()
*
* DESCRIPTION: Writes a date/time value as a string
* DESCRIPTION: Writes a date/time value as a text
* ISO 8601 format is used to preserve interoperability
* between locales.
*
* No further formatting of the date
* Note: this should be replaced by writing actual date/time values
*
*******************************************************************}
procedure TsSpreadBIFF5Writer.WriteDateTime(AStream: TStream;
const ARow, ACol: Cardinal; const AValue: TDateTime; ACell: PCell);
begin
WriteLabel(AStream, ARow, ACol, FormatDateTime('c', AValue), ACell);
WriteLabel(AStream, ARow, ACol, FormatDateTime(ISO8601Format, AValue), ACell);
end;
{*******************************************************************

View File

@ -37,7 +37,7 @@ uses
fpszipper,
{$ENDIF}
{xmlread, DOM,} AVL_Tree,
fpspreadsheet;
fpspreadsheet, fpsutils;
type
@ -518,14 +518,20 @@ begin
Format(' <c r="%s" s="0" t="n"><v>%s</v></c>', [CellPosText, CellValueText]) + LineEnding;
end;
{
Writes the date/time as a text to the sheet.
No further formatting applied.
}
{*******************************************************************
* TsSpreadOOXMLWriter.WriteDateTime ()
*
* DESCRIPTION: Writes a date/time value as a text
* ISO 8601 format is used to preserve interoperability
* between locales.
*
* Note: this should be replaced by writing actual date/time values
*
*******************************************************************}
procedure TsSpreadOOXMLWriter.WriteDateTime(AStream: TStream;
const ARow, ACol: Cardinal; const AValue: TDateTime; ACell: PCell);
begin
WriteLabel(AStream, ARow, ACol, FormatDateTime('c', AValue), ACell);
WriteLabel(AStream, ARow, ACol, FormatDateTime(ISO8601Format, AValue), ACell);
end;
{