diff --git a/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr b/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr index 10648f22d..32f76ab01 100644 --- a/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr +++ b/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr @@ -92,6 +92,16 @@ begin MyWorksheet.WriteDateTime(1, 5, now, nfShortTime); MyWorksheet.WriteDateTime(2, 5, now, 'nn:ss.zzz'); + // Write some numbers in various formats + MyWorksheet.WriteNumber(0, 6, 12345.6789, nfFixed, 0); + MyWorksheet.WriteNumber(1, 6, 12345.6789, nfFixed, 3); + MyWorksheet.WriteNumber(2, 6, 12345.6789, nfFixedTh, 0); + MyWorksheet.Writenumber(3, 6, 12345.6789, nfFixedTh, 3); + MyWorksheet.WriteNumber(4, 6, 12345.6789, nfExp, 2); + Myworksheet.Writenumber(5, 6, 12345.6789, nfExp, 4); + MyWorksheet.WriteCurrency(6, 6,-12345.6789, nfCurrency, 2); + MyWorksheet.WriteCurrency(7, 6,-12345.6789, nfCurrencyRed, 2); + // Save the spreadsheet to a file MyWorkbook.WriteToFile(MyDir + 'test.xlsx', sfOOXML); MyWorkbook.Free; diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas index 40b988730..285d51f7c 100755 --- a/components/fpspreadsheet/xlsxooxml.pas +++ b/components/fpspreadsheet/xlsxooxml.pas @@ -401,7 +401,8 @@ begin // get style index s := GetAttrValue(ANode, 's'); - ApplyCellFormatting(cell, StrToInt(s)); + if s <> '' then + ApplyCellFormatting(cell, StrToInt(s)); // get data datanode := ANode.FirstChild; @@ -1828,17 +1829,11 @@ var CellPosText: String; CellValueText: String; lStyleIndex: Integer; - lDateTime: TDateTime; begin Unused(AStream, ACell); CellPosText := TsWorksheet.CellPosToText(ARow, ACol); lStyleIndex := GetStyleIndex(ACell); - lDateTime := ConvertDateTimeToExcelDateTime(AValue, FDateMode); - // !!!!!!!!!!!!!!!!!!!!! NEED "IF" TO CHECK FOR DATE/TIME !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -// CellValueText := Format('%g', [lDateTime], FPointSeparatorSettings); - CellValueText := FloatToStr(lDateTime, FPointSeparatorSettings); - + CellValueText := FloatToStr(AValue, FPointSeparatorSettings); AppendToStream(AStream, Format( '%s', [CellPosText, lStyleIndex, CellValueText])); end; @@ -1846,21 +1841,16 @@ end; {******************************************************************* * 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 -* +* DESCRIPTION: Writes a date/time value as a number +* Respects DateMode of the file *******************************************************************} procedure TsSpreadOOXMLWriter.WriteDateTime(AStream: TStream; const ARow, ACol: Cardinal; const AValue: TDateTime; ACell: PCell); var ExcelDateSerial: double; begin - ExcelDateSerial := ConvertDateTimeToExcelDateTime(AValue, dm1900); //FDateMode); + ExcelDateSerial := ConvertDateTimeToExcelDateTime(AValue, FDateMode); WriteNumber(AStream, ARow, ACol, ExcelDateSerial, ACell); -// WriteLabel(AStream, ARow, ACol, FormatDateTime(ISO8601Format, AValue), ACell); end; {