From 6d4175c72aa4e9dc43787826d6f74199197ec79b Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 15 Jul 2014 15:16:46 +0000 Subject: [PATCH] fpspreadsheet: Writing of date/time values to xlsx files. Date/time formats working. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3322 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr | 4 +++- components/fpspreadsheet/xlsxooxml.pas | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr b/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr index 0354d2c16..85ad10d7d 100644 --- a/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr +++ b/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr @@ -87,7 +87,9 @@ begin MyWorksheet.WriteUTF8Text(0, 3, 'Fourth'); // Write current date/time - MyWorksheet.WriteDateTime(0, 5, now); + MyWorksheet.WriteDateTime(0, 5, now, nfShortDate); + MyWorksheet.WriteDateTime(1, 5, now, nfShortTime); + MyWorksheet.WriteDateTime(2, 5, now, 'nn:ss.zzz'); // Save the spreadsheet to a file MyWorkbook.WriteToFile(MyDir + 'test.xlsx', sfOOXML); diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas index 1358971a9..c6b63a934 100755 --- a/components/fpspreadsheet/xlsxooxml.pas +++ b/components/fpspreadsheet/xlsxooxml.pas @@ -115,7 +115,7 @@ type implementation uses - variants, fpsNumFormatParser; + variants, fpsNumFormatParser, xlscommon; const { OOXML general XML constants } @@ -1261,8 +1261,12 @@ end; *******************************************************************} procedure TsSpreadOOXMLWriter.WriteDateTime(AStream: TStream; const ARow, ACol: Cardinal; const AValue: TDateTime; ACell: PCell); +var + ExcelDateSerial: double; begin - WriteLabel(AStream, ARow, ACol, FormatDateTime(ISO8601Format, AValue), ACell); + ExcelDateSerial := ConvertDateTimeToExcelDateTime(AValue, dm1900); //FDateMode); + WriteNumber(AStream, ARow, ACol, ExcelDateSerial, ACell); +// WriteLabel(AStream, ARow, ACol, FormatDateTime(ISO8601Format, AValue), ACell); end; {