diff --git a/components/fpspreadsheet/examples/excel2demo/excel2write.lpr b/components/fpspreadsheet/examples/excel2demo/excel2write.lpr index 92e97b4af..0f9139622 100644 --- a/components/fpspreadsheet/examples/excel2demo/excel2write.lpr +++ b/components/fpspreadsheet/examples/excel2demo/excel2write.lpr @@ -212,36 +212,6 @@ begin MyWorksheet.WriteNumber(r, 2, -number, nfFixedTh, 3); MyWorksheet.WriteFontColor(r, 2, scGray); inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 1 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 1); - MyWorksheet.WriteFontColor(r, 1, scGray); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 1); - MyWorksheet.WriteFontColor(r, 2, scGray); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 1); - MyWorksheet.WriteFontColor(r, 3, scGray); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 1); - MyWorksheet.WriteFontColor(r, 4, scGray); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 2 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 2); - MyWorksheet.WriteFontColor(r, 1, scGray); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 2); - MyWorksheet.WriteFontColor(r, 2, scGray); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 2); - MyWorksheet.WriteFontColor(r, 3, scGray); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 2); - MyWorksheet.WriteFontColor(r, 4, scGray); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 3 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 3); - MyWorksheet.WriteFontColor(r, 1, scGray); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 3); - MyWorksheet.WriteFontColor(r, 2, scGray); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 3); - MyWorksheet.WriteFontColor(r, 3, scGray); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 3); - MyWorksheet.WriteFontColor(r, 4, scGray); - inc(r); MyWorksheet.WriteUTF8Text(r, 0, 'nfExp, 1 dec'); MyWorksheet.WriteNumber(r, 1, number, nfExp, 1); MyWorksheet.WriteFontColor(r, 1, scGray); @@ -278,16 +248,6 @@ begin MyWorksheet.WriteCurrency(r, 2, -number, nfCurrencyRed, 0, 'USD'); MyWorksheet.WriteCurrency(r, 3, 0.0, nfCurrencyRed, 0, 'USD'); inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfAccounting, 0 decs'); - MyWorksheet.WriteCurrency(r, 1, number, nfAccounting, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 2, -number, nfAccounting, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 3, 0.0, nfAccounting, 0, 'USD'); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfAccountingRed, 0 decs'); - MyWorksheet.WriteCurrency(r, 1, number, nfAccountingRed, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 2, -number, nfAccountingRed, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 3, 0.0, nfAccountingRed, 0, 'USD'); - inc(r, 2); MyWorksheet.WriteUTF8Text(r, 0, 'nfCustom, "$"#,##0_);("$"#,##0)'); MyWorksheet.WriteNumber(r, 1, number); MyWorksheet.WriteFontColor(r, 1, scGray); diff --git a/components/fpspreadsheet/examples/excel5demo/excel5write.lpr b/components/fpspreadsheet/examples/excel5demo/excel5write.lpr index d896159de..0f950117c 100644 --- a/components/fpspreadsheet/examples/excel5demo/excel5write.lpr +++ b/components/fpspreadsheet/examples/excel5demo/excel5write.lpr @@ -238,24 +238,6 @@ begin MyWorksheet.WriteNumber(r, 1, number, nfFixedTh, 3); MyWorksheet.WriteNumber(r, 2, -number, nfFixedTh, 3); inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 1 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 1); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 1); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 1); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 1); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 2 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 2); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 2); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 2); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 2); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 3 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 3); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 3); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 3); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 3); - inc(r); MyWorksheet.WriteUTF8Text(r, 0, 'nfExp, 1 dec'); MyWorksheet.WriteNumber(r, 1, number, nfExp, 1); MyWorksheet.WriteNumber(r, 2, -number, nfExp, 1); @@ -284,16 +266,6 @@ begin MyWorksheet.WriteCurrency(r, 1, number, nfCurrencyRed, 0, 'USD'); MyWorksheet.WriteCurrency(r, 2, -number, nfCurrencyRed, 0, 'USD'); MyWorksheet.WriteCurrency(r, 3, 0.0, nfCurrencyRed, 0, 'USD'); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfAccounting, 0 decs'); - MyWorksheet.WriteCurrency(r, 1, number, nfAccounting, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 2, -number, nfAccounting, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 3, 0.0, nfAccounting, 0, 'USD'); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfAccountingRed, 0 decs'); - MyWorksheet.WriteCurrency(r, 1, number, nfAccountingRed, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 2, -number, nfAccountingRed, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 3, 0.0, nfAccountingRed, 0, 'USD'); inc(r, 2); MyWorksheet.WriteUTF8Text(r, 0, 'nfCustom, "$"#,##0_);("$"#,##0)'); diff --git a/components/fpspreadsheet/examples/excel8demo/excel8write.lpr b/components/fpspreadsheet/examples/excel8demo/excel8write.lpr index 49dfbae0f..248df45ec 100644 --- a/components/fpspreadsheet/examples/excel8demo/excel8write.lpr +++ b/components/fpspreadsheet/examples/excel8demo/excel8write.lpr @@ -256,30 +256,7 @@ begin MyWorksheet.WriteNumber(r, 1, number, nfFixedTh, 3); MyWorksheet.WriteNumber(r, 2, -number, nfFixedTh, 3); inc(r,2); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 0 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 0); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 0); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 0); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 0); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 1 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 1); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 1); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 1); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 1); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 2 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 2); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 2); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 2); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 2); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfSci, 3 dec'); - MyWorksheet.WriteNumber(r, 1, number, nfSci, 3); - MyWorksheet.WriteNumber(r, 2, -number, nfSci, 3); - MyWorksheet.WriteNumber(r, 3, 1.0/number, nfSci, 3); - MyWorksheet.WriteNumber(r, 4, -1.0/number, nfSci, 3); - inc(r); + MyWorksheet.WriteUTF8Text(r, 0, 'nfExp, 0 dec'); MyWorksheet.WriteNumber(r, 1, number, nfExp, 0); MyWorksheet.WriteNumber(r, 2, -number, nfExp, 0); @@ -314,18 +291,8 @@ begin MyWorksheet.WriteCurrency(r, 1, number, nfCurrencyRed, 0, 'USD'); MyWorksheet.WriteCurrency(r, 2, -number, nfCurrencyRed, 0, 'USD'); MyWorksheet.WriteCurrency(r, 3, 0.0, nfCurrencyRed, 0, 'USD'); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfAccounting, 0 decs'); - MyWorksheet.WriteCurrency(r, 1, number, nfAccounting, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 2, -number, nfAccounting, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 3, 0.0, nfAccounting, 0, 'USD'); - inc(r); - MyWorksheet.WriteUTF8Text(r, 0, 'nfAccountingRed, 0 decs'); - MyWorksheet.WriteCurrency(r, 1, -number, nfAccountingRed, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 2, number, nfAccountingRed, 0, 'USD'); - MyWorksheet.WriteCurrency(r, 3, 0.0, nfAccountingRed, 0, 'USD'); - { + { inc(r,2); MyWorksheet.WriteUTF8Text(r, 0, 'nfCustom, "EUR "#,##0_);("EUR "#,##0)'); MyWorksheet.WriteNumber(r, 1, number); diff --git a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr index 9769918ce..181db344c 100644 --- a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr +++ b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr @@ -184,16 +184,6 @@ begin MyWorksheet.WriteNumber(row, 7, number7, nfExp, 3); MyWorksheet.WriteNumber(row, 8, number8, nfExp, 3); inc(row); - MyWorksheet.WriteUTF8Text(row, 0, 'nfSci, 2 decimals'); - MyWorksheet.WriteNumber(row, 1, number1, nfSci, 2); - MyWorksheet.WriteNumber(row, 2, number2, nfSci, 2); - MyWorksheet.WriteNumber(row, 3, number3, nfSci, 2); - MyWorksheet.WriteNumber(row, 4, number4, nfSci, 2); - MyWorksheet.WriteNumber(row, 5, number5, nfSci, 2); - MyWorksheet.WriteNumber(row, 6, number6, nfSci, 2); - MyWorksheet.WriteNumber(row, 7, number7, nfSci, 2); - MyWorksheet.WriteNumber(row, 8, number8, nfSci, 2); - inc(row); MyWorksheet.WriteUTF8Text(row, 0, 'nfCurrency, 2 decimals'); MyWorksheet.WriteCurrency(row, 1, number1, nfCurrency, 2, '$'); MyWorksheet.WriteCurrency(row, 2, number2, nfCurrency, 2, '$'); @@ -213,28 +203,8 @@ begin MyWorksheet.WriteCurrency(row, 6, number6, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB); MyWorksheet.WriteCurrency(row, 7, number7, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB); MyWorksheet.WriteCurrency(row, 8, number8, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB); - inc(row); - // Note: nfAccounting's not supported by ods, will be replaced by nfCurrency's - MyWorksheet.WriteUTF8Text(row, 0, 'nfAccounting, 2 decimals'); - MyWorksheet.WriteCurrency(row, 1, number1, nfAccounting, 2, '$'); - MyWorksheet.WriteCurrency(row, 2, number2, nfAccounting, 2, '$'); - MyWorksheet.WriteCurrency(row, 3, number3, nfAccounting, 2, '$'); - MyWorksheet.WriteCurrency(row, 4, number4, nfAccounting, 2, '$'); - MyWorksheet.WriteCurrency(row, 5, number5, nfAccounting, 2, '$'); - MyWorksheet.WriteCurrency(row, 6, number6, nfAccounting, 2, '$'); - MyWorksheet.WriteCurrency(row, 7, number7, nfAccounting, 2, '$'); - MyWorksheet.WriteCurrency(row, 8, number8, nfAccounting, 2, '$'); - inc(row); - MyWorksheet.WriteUTF8Text(row, 0, 'nfAccountingRed, 2 decimals, >0: EUR 1000, <0: -EUR 1000)'); - MyWorksheet.WriteCurrency(row, 1, number1, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV); - MyWorksheet.WriteCurrency(row, 2, number2, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV); - MyWorksheet.WriteCurrency(row, 3, number3, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV); - MyWorksheet.WriteCurrency(row, 4, number4, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV); - MyWorksheet.WriteCurrency(row, 5, number5, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV); - MyWorksheet.WriteCurrency(row, 6, number6, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV); - MyWorksheet.WriteCurrency(row, 7, number7, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV); - MyWorksheet.WriteCurrency(row, 8, number8, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV); inc(row,2); + MyWorksheet.WriteUTF8Text(row, 0, 'Some date/time values in various formats:'); inc(row); MyWorksheet.WriteUTF8Text(row, 0, 'nfShortDateTime'); @@ -264,6 +234,9 @@ begin MyWorksheet.WriteUTF8Text(row, 0, 'nfLongTimeAM'); MyWorksheet.WriteDateTime(row, 1, dt1, nfLongTimeAM); MyWorksheet.WriteDateTime(row, 2, dt2, nfLongTimeAM); + inc(row,2); + + MyWorksheet.WriteUTF8Text(row, 0, 'Some custom formats'); inc(row); // In order to use a semicolon as a date-time separator it must be escaped either by // using the backslash or quotes (because the semicolon is the separator between sections) diff --git a/components/fpspreadsheet/examples/spready/mainform.lfm b/components/fpspreadsheet/examples/spready/mainform.lfm index 380c67b11..12c90740b 100644 --- a/components/fpspreadsheet/examples/spready/mainform.lfm +++ b/components/fpspreadsheet/examples/spready/mainform.lfm @@ -4,7 +4,7 @@ object Form1: TForm1 Top = 248 Width = 884 Caption = 'spready' - ClientHeight = 629 + ClientHeight = 624 ClientWidth = 884 Menu = MainMenu OnActivate = FormActivate @@ -14,7 +14,7 @@ object Form1: TForm1 object Panel1: TPanel Left = 0 Height = 85 - Top = 544 + Top = 539 Width = 884 Align = alBottom BevelOuter = bvNone @@ -23,9 +23,9 @@ object Form1: TForm1 TabOrder = 0 object CbShowHeaders: TCheckBox Left = 8 - Height = 19 + Height = 24 Top = 8 - Width = 93 + Width = 116 Caption = 'Show headers' Checked = True OnClick = CbShowHeadersClick @@ -34,9 +34,9 @@ object Form1: TForm1 end object CbShowGridLines: TCheckBox Left = 8 - Height = 19 + Height = 24 Top = 32 - Width = 100 + Width = 125 Caption = 'Show grid lines' Checked = True OnClick = CbShowGridLinesClick @@ -45,7 +45,7 @@ object Form1: TForm1 end object EdFrozenCols: TSpinEdit Left = 389 - Height = 23 + Height = 28 Top = 8 Width = 52 OnChange = EdFrozenColsChange @@ -53,7 +53,7 @@ object Form1: TForm1 end object EdFrozenRows: TSpinEdit Left = 389 - Height = 23 + Height = 28 Top = 39 Width = 52 OnChange = EdFrozenRowsChange @@ -61,37 +61,37 @@ object Form1: TForm1 end object Label1: TLabel Left = 304 - Height = 15 + Height = 20 Top = 13 - Width = 62 + Width = 77 Caption = 'Frozen cols:' FocusControl = EdFrozenCols ParentColor = False end object Label2: TLabel Left = 304 - Height = 15 + Height = 20 Top = 40 - Width = 66 + Width = 82 Caption = 'Frozen rows:' FocusControl = EdFrozenRows ParentColor = False end object CbReadFormulas: TCheckBox Left = 8 - Height = 19 + Height = 24 Top = 56 - Width = 96 + Width = 120 Caption = 'Read formulas' OnChange = CbReadFormulasChange TabOrder = 4 end object CbHeaderStyle: TComboBox Left = 152 - Height = 23 + Height = 28 Top = 8 Width = 116 - ItemHeight = 15 + ItemHeight = 20 ItemIndex = 2 Items.Strings = ( 'Lazarus' @@ -106,7 +106,7 @@ object Form1: TForm1 end object PageControl1: TPageControl Left = 0 - Height = 465 + Height = 460 Top = 79 Width = 884 ActivePage = TabSheet1 @@ -116,11 +116,11 @@ object Form1: TForm1 OnChange = PageControl1Change object TabSheet1: TTabSheet Caption = 'Sheet1' - ClientHeight = 437 + ClientHeight = 427 ClientWidth = 876 object WorksheetGrid: TsWorksheetGrid Left = 0 - Height = 437 + Height = 427 Top = 0 Width = 876 FrozenCols = 0 @@ -136,7 +136,7 @@ object Form1: TForm1 TitleStyle = tsNative OnSelection = WorksheetGridSelection ColWidths = ( - 42 + 56 64 64 64 @@ -244,19 +244,19 @@ object Form1: TForm1 end object FontComboBox: TComboBox Left = 52 - Height = 23 + Height = 28 Top = 2 Width = 127 - ItemHeight = 15 + ItemHeight = 20 OnSelect = FontComboBoxSelect TabOrder = 0 end object FontSizeComboBox: TComboBox Left = 179 - Height = 23 + Height = 28 Top = 2 Width = 48 - ItemHeight = 15 + ItemHeight = 20 Items.Strings = ( '8' '9' @@ -977,6 +977,9 @@ object Form1: TForm1 Action = AcNFGeneral AutoCheck = True end + object MenuItem38: TMenuItem + Caption = '-' + end object MenuItem34: TMenuItem Action = AcNFFixed AutoCheck = True @@ -993,8 +996,54 @@ object Form1: TForm1 Action = AcNFExp AutoCheck = True end - object MenuItem38: TMenuItem - Action = AcNFSci + object MenuItem47: TMenuItem + Caption = '-' + end + object MenuItem48: TMenuItem + Action = AcNFCurrency + AutoCheck = True + end + object MenuItem49: TMenuItem + Action = AcNFCurrencyRed + AutoCheck = True + end + object MenuItem50: TMenuItem + Caption = '-' + end + object MenuItem51: TMenuItem + Action = AcNFShortDateTime + AutoCheck = True + end + object MenuItem52: TMenuItem + Action = AcNFShortDate + AutoCheck = True + end + object MenuItem53: TMenuItem + Action = AcNFLongDate + AutoCheck = True + end + object MenuItem54: TMenuItem + Action = AcNFCustomDM + AutoCheck = True + end + object MenuItem55: TMenuItem + Action = AcNFCustomMY + AutoCheck = True + end + object MenuItem56: TMenuItem + Action = AcNFShortTime + AutoCheck = True + end + object MenuItem57: TMenuItem + Action = AcNFLongTime + AutoCheck = True + end + object MenuItem58: TMenuItem + Action = AcNFShortTimeAM + AutoCheck = True + end + object MenuItem59: TMenuItem + Action = AcNFLongTimeAM AutoCheck = True end end @@ -2398,127 +2447,106 @@ object Form1: TForm1 Caption = 'Exponential' OnExecute = AcNumFormatExecute end - object AcNFSci: TAction - Tag = 1040 - Category = 'Format' - AutoCheck = True - Caption = 'Scientific' - OnExecute = AcNumFormatExecute - end object AcNFPercentage: TAction - Tag = 1050 + Tag = 1040 Category = 'Format' AutoCheck = True Caption = 'Percentage' OnExecute = AcNumFormatExecute end object AcNFCurrency: TAction - Tag = 1060 + Tag = 1050 Category = 'Format' AutoCheck = True Caption = 'Currency' OnExecute = AcNumFormatExecute end object AcNFCurrencyRed: TAction - Tag = 1070 + Tag = 1060 Category = 'Format' AutoCheck = True Caption = 'Currency (negative values in red)' OnExecute = AcNumFormatExecute end - object AcNFAccounting: TAction - Tag = 1080 - Category = 'Format' - AutoCheck = True - Caption = 'Accounting' - OnExecute = AcNumFormatExecute - end - object AcNFAccountingRed: TAction - Tag = 1090 - Category = 'Format' - AutoCheck = True - Caption = 'Accounting (negative values in red)' - OnExecute = AcNumFormatExecute - end object AcNFShortDateTime: TAction - Tag = 1100 + Tag = 1070 Category = 'Format' AutoCheck = True Caption = 'Date + time' OnExecute = AcNumFormatExecute end object AcNFShortDate: TAction - Tag = 1110 + Tag = 1080 Category = 'Format' AutoCheck = True Caption = 'Short date' OnExecute = AcNumFormatExecute end - object AcNFFmtDateTimeDM: TAction - Tag = 1181 - Category = 'Format' - AutoCheck = True - Caption = 'Day + month' - OnExecute = AcNumFormatExecute - end - object AcNFFmtDateTimeMY: TAction - Tag = 1182 - Category = 'Format' - AutoCheck = True - Caption = 'Month + year' - OnExecute = AcNumFormatExecute - end object AcNFLongDate: TAction - Tag = 1120 + Tag = 1090 Category = 'Format' AutoCheck = True Caption = 'Long date' OnExecute = AcNumFormatExecute end + object AcNFCustomDM: TAction + Tag = 1151 + Category = 'Format' + AutoCheck = True + Caption = 'Day + month' + OnExecute = AcNumFormatExecute + end + object AcNFCustomMY: TAction + Tag = 1152 + Category = 'Format' + AutoCheck = True + Caption = 'Month + year' + OnExecute = AcNumFormatExecute + end object AcNFShortTime: TAction - Tag = 1130 + Tag = 1100 Category = 'Format' AutoCheck = True Caption = 'Short time' OnExecute = AcNumFormatExecute end object AcNFLongTime: TAction - Tag = 1140 + Tag = 1110 Category = 'Format' AutoCheck = True Caption = 'Long time' OnExecute = AcNumFormatExecute end object AcNFShortTimeAM: TAction - Tag = 1150 + Tag = 1120 Category = 'Format' AutoCheck = True Caption = 'Short time AM/PM' OnExecute = AcNumFormatExecute end object AcNFLongTimeAM: TAction - Tag = 1160 + Tag = 1130 Category = 'Format' AutoCheck = True Caption = 'Long time AM/PM' OnExecute = AcNumFormatExecute end - object AcNFFmtDateTimeMS: TAction - Tag = 1183 + object AcNFCusstomMS: TAction + Tag = 1153 Category = 'Format' AutoCheck = True Caption = 'Minutes + seconds' OnExecute = AcNumFormatExecute end - object AcNFFmtDateTimeMSZ: TAction - Tag = 1184 + object AcNFCustomMSZ: TAction + Tag = 1154 Category = 'Format' AutoCheck = True Caption = 'Minutes + seconds + milliseconds' OnExecute = AcNumFormatExecute end object AcNFTimeInterval: TAction - Tag = 1170 + Tag = 1140 Category = 'Format' AutoCheck = True Caption = 'Time interval' @@ -3218,10 +3246,6 @@ object Form1: TForm1 Action = AcNFExp AutoCheck = True end - object MnuNFSci: TMenuItem - Action = AcNFSci - AutoCheck = True - end object MenuItem39: TMenuItem Caption = '-' end @@ -3233,14 +3257,6 @@ object Form1: TForm1 Action = AcNFCurrencyRed AutoCheck = True end - object MnuAccounting: TMenuItem - Action = AcNFAccounting - AutoCheck = True - end - object MnuAccountingRed: TMenuItem - Action = AcNFAccountingRed - AutoCheck = True - end object MenuItem40: TMenuItem Caption = '-' end @@ -3260,11 +3276,11 @@ object Form1: TForm1 AutoCheck = True end object MnuFmtDateTimeDM: TMenuItem - Action = AcNFFmtDateTimeDM + Action = AcNFCustomDM AutoCheck = True end object MnuFmtDateTimeMY: TMenuItem - Action = AcNFFmtDateTimeMY + Action = AcNFCustomMY AutoCheck = True end object MenuItem43: TMenuItem @@ -3287,11 +3303,11 @@ object Form1: TForm1 AutoCheck = True end object MenuItem45: TMenuItem - Action = AcNFFmtDateTimeMS + Action = AcNFCusstomMS AutoCheck = True end object MnuFmtDateTimeMSZ: TMenuItem - Action = AcNFFmtDateTimeMSZ + Action = AcNFCustomMSZ AutoCheck = True end object MenuItem44: TMenuItem diff --git a/components/fpspreadsheet/examples/spready/mainform.pas b/components/fpspreadsheet/examples/spready/mainform.pas index 9bfd2be7c..68810ce75 100644 --- a/components/fpspreadsheet/examples/spready/mainform.pas +++ b/components/fpspreadsheet/examples/spready/mainform.pas @@ -53,12 +53,9 @@ type AcDecDecimals: TAction; AcNFGeneral: TAction; AcNFExp: TAction; - AcNFSci: TAction; AcCopyFormat: TAction; AcNFCurrency: TAction; AcNFCurrencyRed: TAction; - AcNFAccounting: TAction; - AcNFAccountingRed: TAction; AcNFShortDateTime: TAction; AcNFShortDate: TAction; AcNFLongDate: TAction; @@ -67,10 +64,10 @@ type AcNFShortTimeAM: TAction; AcNFLongTimeAM: TAction; AcNFTimeInterval: TAction; - AcNFFmtDateTimeDM: TAction; - AcNFFmtDateTimeMY: TAction; - AcNFFmtDateTimeMS: TAction; - AcNFFmtDateTimeMSZ: TAction; + AcNFCustomDM: TAction; + AcNFCustomMY: TAction; + AcNFCusstomMS: TAction; + AcNFCustomMSZ: TAction; AcNew: TAction; AcWordwrap: TAction; AcVAlignDefault: TAction; @@ -132,6 +129,19 @@ type MenuItem44: TMenuItem; MenuItem45: TMenuItem; MenuItem46: TMenuItem; + MenuItem47: TMenuItem; + MenuItem48: TMenuItem; + MenuItem49: TMenuItem; + MenuItem50: TMenuItem; + MenuItem51: TMenuItem; + MenuItem52: TMenuItem; + MenuItem53: TMenuItem; + MenuItem54: TMenuItem; + MenuItem55: TMenuItem; + MenuItem56: TMenuItem; + MenuItem57: TMenuItem; + MenuItem58: TMenuItem; + MenuItem59: TMenuItem; MnuFmtDateTimeMSZ: TMenuItem; MnuTimeInterval: TMenuItem; MnuShortTimeAM: TMenuItem; @@ -143,8 +153,6 @@ type MnuLongTime: TMenuItem; MnuLongDate: TMenuItem; MnuShortDateTime: TMenuItem; - MnuAccountingRed: TMenuItem; - MnuAccounting: TMenuItem; MnuCurrencyRed: TMenuItem; MnuCurrency: TMenuItem; MnuNumberFormat: TMenuItem; @@ -152,7 +160,6 @@ type MnuNFFixedTh: TMenuItem; MnuNFPercentage: TMenuItem; MnuNFExp: TMenuItem; - MnuNFSci: TMenuItem; MnuNFGeneral: TMenuItem; MnuTextRotation: TMenuItem; MenuItem3: TMenuItem; diff --git a/components/fpspreadsheet/fpsnumformatparser.pas b/components/fpspreadsheet/fpsnumformatparser.pas index 193ef5dac..422e9a2e7 100644 --- a/components/fpspreadsheet/fpsnumformatparser.pas +++ b/components/fpspreadsheet/fpsnumformatparser.pas @@ -133,8 +133,6 @@ type var ANextIndex: Integer): Boolean; function IsNumberAt(ASection,AIndex: Integer; out ANumberFormat: TsNumberFormat; out ADecimals: Byte; out ANextIndex: Integer): Boolean; - function IsSciAt(ASection, AIndex: Integer; out ANumberFormat: TsNumberFormat; - out ADecimals: Byte; out ANextIndex: Integer): Boolean; function IsTextAt(AText: string; ASection, AIndex: Integer): Boolean; function IsTimeAt(ASection,AIndex: Integer; out ANumberFormat: TsNumberFormat; out ANextIndex: Integer): Boolean; @@ -179,7 +177,7 @@ begin inherited Create; FCreateMethod := 0; FWorkbook := AWorkbook; - FHasRedSection := (ANumFormat in [nfCurrencyRed, nfAccountingRed]); + FHasRedSection := (ANumFormat = nfCurrencyRed); Parse(AFormatString); end; @@ -584,10 +582,6 @@ begin end; end; - // Look for scientific format - if IsSciAt(ASection, 0, ANumFormat, ADecimals, next) then - exit; - // Currency? if IsCurrencyAt(ASection, ANumFormat, ADecimals, ACurrencySymbol, AColor) then exit; @@ -677,7 +671,7 @@ begin result := nfGeneral else begin Result := FSections[0].NumFormat; - if (Result in [nfCurrency, nfAccounting]) then begin + if (Result = nfCurrency) then begin if Length(FSections) = 2 then begin Result := FSections[1].NumFormat; if FSections[1].CurrencySymbol <> FSections[0].CurrencySymbol then begin @@ -688,10 +682,6 @@ begin (FSections[1].NumFormat in [nfCurrency, nfCurrencyRed]) then exit; - if FSections[1].NumFormat = nfAccounting then begin - Result := nfAccounting; - exit; - end; end else if Length(FSections) = 3 then begin Result := FSections[1].NumFormat; @@ -706,12 +696,6 @@ begin (FSections[2].NumFormat in [nfCurrency, nfCurrencyRed]) then exit; - if (FSections[1].NumFormat = nfAccounting) and - (FSections[2].NumFormat in [nfCurrency, nfAccounting]) - then begin - Result := nfAccounting; - exit; - end; end; Result := nfCustom; exit; @@ -739,7 +723,6 @@ function TsNumFormatParser.IsCurrencyAt(ASection: Integer; out ANumFormat: TsNumberFormat; out ADecimals: byte; out ACurrencySymbol: String; out AColor: TsColor): Boolean; var - isAccounting : Boolean; hasCurrSymbol: Boolean; hasColor: Boolean; el: Integer; @@ -750,7 +733,6 @@ begin ACurrencySymbol := ''; ADecimals := 0; AColor := scNotDefined; - isAccounting := false; hasColor := false; hasCurrSymbol := false; @@ -783,7 +765,7 @@ begin hasColor := true; end; nftRepeat: - isAccounting := true; + ; nftCurrSymbol: begin ACurrencySymbol := FSections[ASection].Elements[el].TextValue; @@ -812,13 +794,8 @@ begin Result := hasCurrSymbol and ((ANumFormat = nfFixedTh) or (ASection = 2)); if Result then begin - if isAccounting then begin - if AColor = scNotDefined then ANumFormat := nfAccounting else - if AColor = scRed then ANumFormat := nfAccountingRed; - end else begin - if AColor = scNotDefined then ANumFormat := nfCurrency else - if AColor = scRed then ANumFormat := nfCurrencyRed; - end; + if AColor = scNotDefined then ANumFormat := nfCurrency else + if AColor = scRed then ANumFormat := nfCurrencyRed; end else ANumFormat := nfCustom; end; @@ -974,26 +951,6 @@ begin end; end; -function TsNumFormatParser.IsSciAt(ASection, AIndex: Integer; - out ANumberFormat: TsNumberFormat; out ADecimals: Byte; out ANextIndex: Integer): Boolean; -begin - if IsTokenAt(nftOptDigit, ASection, AIndex) and // '#' - IsTokenAt(nftOptDigit, ASection, Aindex+1) and // '#' - IsTokenAt(nftDigit, ASection, AIndex+2) and // '0' - IsTokenAt(nftDecSep, ASection, AIndex+3) and // '.' - IsTokenAt(nftDecs, ASection, AIndex+4) and // count of decimals - IsTokenAt(nftExpChar, ASection, AIndex+5) and // E - IsTokenAt(nftExpSign, ASection, AIndex+6) and // +/- - IsTokenAt(nftExpDigits, ASection, AIndex+7) - then begin - Result := true; - ANumberFormat := nfSci; - ADecimals := FSections[ASection].Elements[AIndex+4].IntValue; - ANextIndex := AIndex + 8; - end else - Result := false; -end; - function TsNumFormatParser.IsTextAt(AText: String; ASection, AIndex: Integer): Boolean; begin Result := IsTokenAt(nftText, ASection, AIndex) and diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index f18c687aa..4cea0f812 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -183,9 +183,9 @@ type // general-purpose for all numbers nfGeneral, // numbers - nfFixed, nfFixedTh, nfExp, nfSci, nfPercentage, + nfFixed, nfFixedTh, nfExp, nfPercentage, // currency - nfCurrency, nfCurrencyRed, nfAccounting, nfAccountingRed, + nfCurrency, nfCurrencyRed, // dates and times nfShortDateTime, {nfFmtDateTime, }nfShortDate, nfLongDate, nfShortTime, nfLongTime, nfShortTimeAM, nfLongTimeAM, nfTimeInterval, @@ -1779,18 +1779,8 @@ function TsWorksheet.ReadAsUTF8Text(ACell: PCell): ansistring; if (ANumberFormat = nfGeneral) or (ANumberFormatStr = '') then Result := FloatToStr(Value, fs) else - if ANumberFormat = nfSci then - Result := SciFloat(Value, CountDecs(ANumberFormatStr, ['0']), fs) - else if (ANumberFormat = nfPercentage) then Result := FormatFloat(ANumberFormatStr, Value*100, fs) - else - if (ANumberFormat in [nfAccounting, nfAccountingRed]) then - case SplitAccountingFormatString(ANumberFormatStr, Sign(Value), left, right) of - 0: Result := FormatFloat(ANumberFormatStr, Value, fs); - 1: Result := FormatFloat(left, abs(Value), fs) + ' ' + Right; - 2: Result := Left + ' ' + FormatFloat(right, abs(Value), fs); - end else Result := FormatFloat(ANumberFormatStr, Value, fs) end; @@ -2203,15 +2193,14 @@ begin if ACell <> nil then begin ACell^.ContentType := cctNumber; ACell^.NumberValue := ANumber; + ACell^.NumberFormat := AFormat; if AFormat <> nfGeneral then begin Include(ACell^.UsedFormattingFields, uffNumberFormat); - ACell^.NumberFormat := AFormat; ACell^.NumberFormatStr := BuildNumberFormatString(ACell^.NumberFormat, Workbook.FormatSettings, ADecimals); end else begin Exclude(ACell^.UsedFormattingFields, uffNumberFormat); - ACell^.NumberFormat := nfGeneral; ACell^.NumberFormatStr := ''; end; @@ -2268,11 +2257,16 @@ begin parser.Free; end; - Include(ACell^.UsedFormattingFields, uffNumberFormat); ACell^.ContentType := cctNumber; ACell^.NumberValue := ANumber; - ACell^.NumberFormat := AFormat; //nfCustom; - ACell^.NumberFormatStr := AFormatString; + ACell^.NumberFormat := AFormat; + if AFormat <> nfGeneral then begin + Include(ACell^.UsedFormattingFields, uffNumberFormat); + ACell^.NumberFormatStr := AFormatString; + end else begin + Exclude(ACell^.UsedFormattingFields, uffNumberFormat); + ACell^.NumberFormatStr := ''; + end; ChangedCell(ACell^.Row, ACell^.Col); end; @@ -2381,8 +2375,7 @@ end; @param ARow Cell row index @param ACol Cell column index @param AValue Number value to be written - @param AFormat Format identifier, must be nfCurrency, nfCurrencyRed, - nfAccounting, or nfAccountingRed + @param AFormat Format identifier, must be nfCurrency, or nfCurrencyRed. @param ADecimals Number of decimal places @param APosCurrFormat Code specifying the order of value, currency symbol and spaces (see pcfXXXX constants) @@ -2408,8 +2401,7 @@ end; @param ACell Pointer to the cell considered @param AValue Number value to be written - @param AFormat Format identifier, must be nfCurrency, nfCurrencyRed, - nfAccounting, or nfAccountingRed + @param AFormat Format identifier, must be nfCurrency or nfCurrencyRed. @param ADecimals Number of decimal places @param APosCurrFormat Code specifying the order of value, currency symbol and spaces (see pcfXXXX constants) @@ -2454,8 +2446,7 @@ end; @param ARow Cell row index @param ACol Cell column index @param AValue Number value to be written - @param AFormat Format identifier, must be nfCurrency, nfCurrencyRed, - nfAccounting, or nfAccountingRed + @param AFormat Format identifier, must be nfCurrency or nfCurrencyRed. @param AFormatString String of formatting codes, including currency symbol. Can contain sections for different formatting of positive and negative number. Example: '"EUR" #,##0.00;("EUR" #,##0.00)' @@ -2472,8 +2463,7 @@ end; @param ACell Pointer to the cell considered @param AValue Number value to be written - @param AFormat Format identifier, must be nfCurrency, nfCurrencyRed, - nfAccounting, or nfAccountingRed + @param AFormat Format identifier, must be nfCurrency or nfCurrencyRed. @param AFormatString String of formatting codes, including currency symbol. Can contain sections for different formatting of positive and negative number. Example: '"EUR" #,##0.00;("EUR" #,##0.00)' diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index 5859ef88e..3b675d6ba 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -695,7 +695,7 @@ begin Canvas.Font.Size := round(fnt.Size); end; end; - if (lCell^.NumberFormat in [nfCurrencyRed, nfAccountingRed]) and + if (lCell^.NumberFormat = nfCurrencyRed) and not IsNaN(lCell^.NumberValue) and (lCell^.NumberValue < 0) then Canvas.Font.Color := FWorkbook.GetPaletteColor(scRed); @@ -941,174 +941,34 @@ begin InflateRect(ARect, -constCellPadding, -constCellPadding); - if (lCell^.NumberFormat in [nfAccounting, nfAccountingRed]) and not IsNaN(lCell^.Numbervalue) - then begin - case SplitAccountingFormatString(lCell^.NumberFormatStr, Sign(lCell^.NumberValue), - txtLeft, txtRight) of - 1: begin - txtLeft := FormatFloat(txtLeft, lCell^.NumberValue); - if txtLeft = '' then exit; - txt := txtLeft + ' ' + txtRight; - end; - 2: begin - txtRight := FormatFloat(txtRight, lCell^.NumberValue); - if txtRight = '' then exit; - txt := txtLeft + ' ' + txtRight; - end; - end; - InternalDrawTextInCell(txtLeft, txt, ARect, 0, horAlign, vertAlign, - txtRot, wrapped, true); - InternalDrawTextInCell(txtRight, txt, ARect, 2, horAlign, vertAlign, - txtRot, wrapped, true); - end else begin - txt := GetCellText(ACol, ARow); - if txt = '' then - exit; - case txtRot of - trHorizontal: - case horAlign of - haLeft : justif := 0; - haCenter : justif := 1; - haRight : justif := 2; - end; - rtStacked, - rt90DegreeClockwiseRotation: - case vertAlign of - vaTop : justif := 0; - vaCenter: justif := 1; - vaBottom: justif := 2; - end; - rt90DegreeCounterClockwiseRotation: - case vertAlign of - vaTop : justif := 2; - vaCenter: justif := 1; - vaBottom: justif := 0; - end; - end; - InternalDrawTextInCell(txt, txt, ARect, justif, horAlign, vertAlign, - txtRot, wrapped, false); - end; -end; + txt := GetCellText(ACol, ARow); + if txt = '' then + exit; -(* - - - - - - procedure InternalDrawTextInCell(AText, AMeasureText: String; ARect: TRect; - AJustification: Byte; ACellHorAlign: TsHorAlignment; - ACellVertAlign: TsVertAlignment; ATextRot: TsTextRotation; - ATextWrap, ReplaceTooLong: Boolean); - - - - - if (lCell^.TextRotation in [trHorizontal, rtStacked]) or - (not (uffTextRotation in lCell^.UsedFormattingFields)) - then begin - // HORIZONAL TEXT DRAWING DIRECTION - ts := Canvas.TextStyle; - if wrapped then begin - ts.Wordbreak := true; - ts.SingleLine := false; - flags := DT_WORDBREAK and not DT_SINGLELINE; - LCLIntf.DrawText(Canvas.Handle, PChar(txt), Length(txt), txtRect, - DT_CALCRECT or flags); - w := txtRect.Right - txtRect.Left; - h := txtRect.Bottom - txtRect.Top; - end else begin - ts.WordBreak := false; - ts.SingleLine := false; - w := Canvas.TextWidth(txt); - h := Canvas.TextHeight('Tg'); - end; - - Canvas.Font.Orientation := 0; - ts.Alignment := HOR_ALIGNMENTS[horAlign]; - ts.Opaque := false; - if h > ARect.Bottom - ARect.Top then - ts.Layout := tlTop - else - ts.Layout := VERT_ALIGNMENTS[vertAlign]; - - Canvas.TextStyle := ts; - Canvas.TextRect(ARect, ARect.Left, ARect.Top, txt); - end - else - begin - // ROTATED TEXT DRAWING DIRECTION - L := TStringList.Create; - try - txtRect := Bounds(ARect.Left, ARect.Top, ARect.Bottom - ARect.Top, ARect.Right - ARect.Left); - hline := Canvas.TextHeight('Tg'); - if wrapped then begin - L.Text := WrapText(Canvas, txt, txtRect.Right - txtRect.Left); - flags := DT_WORDBREAK and not DT_SINGLELINE; - LCLIntf.DrawText(Canvas.Handle, PChar(L.Text), Length(L.Text), txtRect, - DT_CALCRECT or flags); - w := txtRect.Right - txtRect.Left; - h := txtRect.Bottom - txtRect.Top; - h0 := hline; - end - else begin - L.Text := txt; - w := Canvas.TextWidth(txt); - h := hline; - h0 := 0; + case txtRot of + trHorizontal: + case horAlign of + haLeft : justif := 0; + haCenter : justif := 1; + haRight : justif := 2; end; - - ts := Canvas.TextStyle; - ts.SingleLine := true; // Draw text line by line - ts.Clipping := false; - ts.Layout := tlTop; - ts.Alignment := taLeftJustify; - ts.Opaque := false; - - if lCell^.TextRotation = rt90DegreeClockwiseRotation then begin - // Clockwise - Canvas.Font.Orientation := -900; - case horAlign of - haLeft : P.X := Min(ARect.Right-1, ARect.Left + h - h0); - haCenter : P.X := Min(ARect.Right-1, (ARect.Left + ARect.Right + h) div 2); - haRight : P.X := ARect.Right - 1; - end; - for i:= 0 to L.Count-1 do begin - w := Canvas.TextWidth(L[i]); - case vertAlign of - vaTop : P.Y := ARect.Top; - vaCenter : P.Y := Max(ARect.Top, (ARect.Top + ARect.Bottom - w) div 2); - vaBottom : P.Y := Max(ARect.Top, ARect.Bottom - w); - end; - Canvas.TextRect(ARect, P.X, P.Y, L[i], ts); - dec(P.X, hline); - end - end - else begin - // Counter-clockwise - Canvas.Font.Orientation := +900; - case horAlign of - haLeft : P.X := ARect.Left; - haCenter : P.X := Max(ARect.Left, (ARect.Left + ARect.Right - h + h0) div 2); - haRight : P.X := MAx(ARect.Left, ARect.Right - h + h0); - end; - for i:= 0 to L.Count-1 do begin - w := Canvas.TextWidth(L[i]); - case vertAlign of - vaTop : P.Y := Min(ARect.Bottom, ARect.Top + w); - vaCenter : P.Y := Min(ARect.Bottom, (ARect.Top + ARect.Bottom + w) div 2); - vaBottom : P.Y := ARect.Bottom; - end; - Canvas.TextRect(ARect, P.X, P.Y, L[i], ts); - inc(P.X, hline); - end; + rtStacked, + rt90DegreeClockwiseRotation: + case vertAlign of + vaTop : justif := 0; + vaCenter: justif := 1; + vaBottom: justif := 2; + end; + rt90DegreeCounterClockwiseRotation: + case vertAlign of + vaTop : justif := 2; + vaCenter: justif := 1; + vaBottom: justif := 0; end; - finally - L.Free; - end; end; + InternalDrawTextInCell(txt, txt, ARect, justif, horAlign, vertAlign, + txtRot, wrapped, false); end; -*) procedure TsCustomWorksheetGrid.EditingDone; var @@ -1899,7 +1759,8 @@ end; filling the cell. The reason to separate AJustification from ACellHorAlign and ACelVertAlign is the output of nfAccounting formatted numbers where the numbers are always - right-aligned, and the currency symbol is left-aligned. } + right-aligned, and the currency symbol is left-aligned. + NOTE: THIS FEATURE IS NO LONGER SUPPORTED. } procedure TsCustomWorksheetGrid.InternalDrawTextInCell(AText, AMeasureText: String; ARect: TRect; AJustification: Byte; ACellHorAlign: TsHorAlignment; ACellVertAlign: TsVertAlignment; ATextRot: TsTextRotation; diff --git a/components/fpspreadsheet/fpsutils.pas b/components/fpspreadsheet/fpsutils.pas index 29a017906..acf261bb0 100644 --- a/components/fpspreadsheet/fpsutils.pas +++ b/components/fpspreadsheet/fpsutils.pas @@ -93,13 +93,9 @@ function MakeLongDateFormat(AShortDateFormat: String): String; function MakeShortDateFormat(AShortDateFormat: String): String; function SpecialDateTimeFormat(ACode: String; const AFormatSettings: TFormatSettings; ForWriting: Boolean): String; -function SplitAccountingFormatString(const AFormatString: String; ASection: ShortInt; - out ALeft, ARight: String): Byte; procedure SplitFormatString(const AFormatString: String; out APositivePart, ANegativePart, AZeroPart: String); -function SciFloat(AValue: Double; ADecimals: Byte): String; overload; -function SciFloat(AValue: Double; ADecimals: Byte; AFormatSettings: TFormatSettings): String; overload; procedure MakeTimeIntervalMask(Src: String; var Dest: String); // These two functions are copies of fpc trunk until they are available in stable fpc. @@ -565,11 +561,11 @@ begin if ACondition then Result := AValue1 else Result := AValue2; end; -{ Checks whether the given number format code is for currency or accounting +{ Checks whether the given number format code is for currency, i.e. requires currency symbol. } function IsCurrencyFormat(AFormat: TsNumberFormat): Boolean; begin - Result := AFormat in [nfCurrency, nfCurrencyRed, nfAccounting, nfAccountingRed]; + Result := AFormat in [nfCurrency, nfCurrencyRed]; end; { Checks whether the given number format code is for date/times. } @@ -648,69 +644,81 @@ begin end; end; -{ Builds a currency format string. The presentation of negative values (brackets, +{@@ + Builds a currency format string. The presentation of negative values (brackets, or minus signs) is taken from the provided format settings. The format string consists of three sections, separated by semicolons. - Additional code is inserted for the destination file format: - - AAccountingStyle = true adds code to align the currency symbols below each - other. - - ANegativeValuesRed adds code to the second section of the format code (for - negative values) to apply a red font color. - This code has to be removed by StripAccountingSymbols before applying to - FormatFloat. } + + @param ADialect Determines whether the format string is for use by + fpspreadsheet (nfdDefault) or by Excel (nfdExcel) + @param ANumberFormat Identifier of the built-in number format for which the + format string is to be generated. + @param AFormatSettings FormatSettings to be applied (used to extract default + values for the next parameters) + @param ADecimals number of decimal places. If < 0, the CurrencyDecimals + of the FormatSettings is used. + @param APosCurrFormat Identifier for the order of currency symbol, value and + spaces of positive values + - see pcfXXXX constants in fpspreadsheet.pas. + If < 0, the CurrencyFormat of the FormatSettings is used. + @param ANegCurrFormat Identifier for the order of currency symbol, value and + spaces of negative values. Specifies also usage of (). + - see ncfXXXX constants in fpspreadsheet.pas. + If < 0, the NegCurrFormat of the FormatSettings is used. + @param ACurrencySymbol Name of the currency, like $ or USD. + If ? the CurrencyString of the FormatSettings is used. + + @return String of formatting codes, such as '"$"#,##0.00;("$"#,##0.00);"EUR"0.00' +} function BuildCurrencyFormatString(ADialect: TsNumFormatDialect; ANumberFormat: TsNumberFormat; const AFormatSettings: TFormatSettings; ADecimals, APosCurrFormat, ANegCurrFormat: Integer; ACurrencySymbol: String): String; const - POS_FMT: array[0..3, boolean] of string = ( - // Parameter 0 is "value", parameter 1 is "currency symbol" - // AccountingStyle = false --> 1st column, true --> 2nd column - ('"%1:s"%0:s', '"%1:s"* %0:s'), // 0: $1 - ('%0:s"%1:s"', '%0:s "%1:s"'), // 1: 1$ - ('"%1:s" %0:s', '"%1:s"* %0:s'), // 2: $ 1 - ('%0:s "%1:s"', '%0:s "%1:s"') // 3: 1 $ + POS_FMT: array[0..3] of string = ( + // Format parameter 0 is "value", parameter 1 is "currency symbol" + ('"%1:s"%0:s'), // 0: $1 + ('%0:s"%1:s"'), // 1: 1$ + ('"%1:s" %0:s'), // 2: $ 1 + ('%0:s "%1:s"') // 3: 1 $ ); - NEG_FMT: array[0..15, boolean] of string = ( - ('("%1:s"%0:s)', '"%1:s"* (%0:s)'), // 0: ($1) - ('-"%1:s"%0:s', '-* "%1:s" %0:s'), // 1: -$1 - ('"%1:s"-%0:s', '"%1:s"* -%0:s'), // 2: $-1 - ('"%1:s"%0:s-', '"%1:s"%0:s-'), // 3: $1- - ('(%0:s"%1:s")', '(%0:s)%1:s"'), // 4: (1$) - ('-%0:s"%1:s"', '-* %0:s"%1:s"'), // 5: -1$ - ('%0:s-"%1:s"', '%0:s-"%1:s"'), // 6: 1-$ - ('%0:s"%1:s"-', '%0:s-"%1:s"'), // 7: 1$- - ('-%0:s "%1:s"', '-* %0:s"%1:s"'), // 8: -1 $ - ('-"%1:s" %0:s', '-* "%1:s" %0:s'), // 9: -$ 1 - ('%0:s "%1:s"-', '%0:s- "%1:s"'), // 10: 1 $- - ('"%1:s" %0:s-', '"%1:s"* %0:s-'), // 11: $ 1- - ('"%1:s" -%0:s', '"%1:s"* -%0:s'), // 12: $ -1 - ('%0:s- "%1:s"', '%0:s- "%1:s"'), // 13: 1- $ - ('("%1:s" %0:s)', '"%1:s"* (%0:s)'), // 14: ($ 1) - ('(%0:s "%1:s")', '(%0:s "%1:s")') // 15: (1 $) + NEG_FMT: array[0..15] of string = ( + ('("%1:s"%0:s)'), // 0: ($1) + ('-"%1:s"%0:s'), // 1: -$1 + ('"%1:s"-%0:s'), // 2: $-1 + ('"%1:s"%0:s-'), // 3: $1- + ('(%0:s"%1:s")'), // 4: (1$) + ('-%0:s"%1:s"'), // 5: -1$ + ('%0:s-"%1:s"'), // 6: 1-$ + ('%0:s"%1:s"-'), // 7: 1$- + ('-%0:s "%1:s"'), // 8: -1 $ + ('-"%1:s" %0:s'), // 9: -$ 1 + ('%0:s "%1:s"-'), // 10: 1 $- + ('"%1:s" %0:s-'), // 11: $ 1- + ('"%1:s" -%0:s'), // 12: $ -1 + ('%0:s- "%1:s"'), // 13: 1- $ + ('("%1:s" %0:s)'), // 14: ($ 1) + ('(%0:s "%1:s")') // 15: (1 $) ); var decs: String; pcf, ncf: Byte; p, n: String; - accStyle: Boolean; negRed: Boolean; begin pcf := IfThen(APosCurrFormat < 0, AFormatSettings.CurrencyFormat, APosCurrFormat); ncf := IfThen(ANegCurrFormat < 0, AFormatSettings.NegCurrFormat, ANegCurrFormat); - if ADecimals < 0 then + if (ADecimals < 0) then ADecimals := AFormatSettings.CurrencyDecimals; if ACurrencySymbol = '?' then ACurrencySymbol := AnsiToUTF8(AFormatSettings.CurrencyString); decs := DupeString('0', ADecimals); if ADecimals > 0 then decs := '.' + decs; - accStyle := ANumberFormat in [nfAccounting, nfAccountingRed]; - negRed := ANumberFormat in [nfCurrencyRed, nfAccountingRed]; - - p := POS_FMT[pcf, accStyle]; - n := NEG_FMT[ncf, accStyle]; + negRed := (ANumberFormat = nfCurrencyRed); + p := POS_FMT[pcf]; // Format mask for positive values + n := NEG_FMT[ncf]; // Format mask for negative values // add extra space for the sign of the number for perfect alignment in Excel - if accStyle then + if ADialect = nfdExcel then case ncf of 0, 14: p := p + '_)'; 3, 11: p := p + '_-'; @@ -722,7 +730,7 @@ begin Result := Format(p, ['#,##0' + decs, ACurrencySymbol]) + ';' + IfThen(negRed and (ADialect = nfdExcel), '[red]', '') + Format(n, ['#,##0' + decs, ACurrencySymbol]) + ';' - + Format(p, [IfThen(accStyle, '-', '0'+decs), ACurrencySymbol]); + + Format(p, ['0'+decs, ACurrencySymbol]); end else begin Result := '#,##0' + decs; @@ -735,12 +743,22 @@ begin 1, 2, 5, 6, 8, 9, 12: Result := Result + '-#,##0' + decs; else Result := Result + '#,##0' + decs + '-'; end; - Result := Result + ';' + IfThen(accStyle, '-', '0'+decs); + Result := Result + ';0' + decs; end; end; -{ Builds a number format string from the number format code, the count of - decimals, and the currencysymbol (if not empty). } +{@@ + Builds a number format string from the number format code and the count of + decimal places. + + @param ANumberFormat Identifier of the built-in numberformat for which a + format string is to be generated + @param AFormatSettings FormatSettings for default parameters + @param ADecimals Number of decimal places. If < 0 the CurrencyDecimals + value of the FormatSettings is used. + + @return String of formatting codes, such as '#,##0.00' for nfFixedTh and 2 decimals +} function BuildNumberFormatString(ANumberFormat: TsNumberFormat; const AFormatSettings: TFormatSettings; ADecimals: Integer = -1): String; var @@ -758,11 +776,9 @@ begin Result := '#,##0' + decs; nfExp: Result := '0' + decs + 'E+00'; - nfSci: - Result := '##0' + decs + 'E+0'; nfPercentage: Result := '0' + decs + '%'; - nfCurrency, nfCurrencyRed, nfAccounting, nfAccountingRed: + nfCurrency, nfCurrencyRed: raise Exception.Create('BuildNumberFormatString: Use BuildCurrencyFormatString '+ 'to create a format string for currency values.'); nfShortDateTime, nfShortDate, nfLongDate, nfShortTime, nfLongTime, @@ -933,84 +949,6 @@ begin Result := ACode; end; -{ Splits the sections +1 (positive) or -1 (negative values) or 0 (zero values) - of the accounting format string at the position of the '*' into a left - and right part and returns 1 if the format string is in the left, and 2 if - it is in the right part. Additionally removes Excel format codes '_' } -function SplitAccountingFormatString(const AFormatString: String; ASection: ShortInt; - out ALeft, ARight: String): Byte; -var - P: PChar; - PStart, PEnd: PChar; - token: Char; - done: Boolean; - i: Integer; -begin - Result := 0; - PStart := PChar(@AFormatString[1]); - PEnd := PStart + Length(AFormatString); - P := PStart; - - done := false; - case ASection of - -1 : while (P < PEnd) and not done do begin - token := P^; - if token = ';' then done := true; - inc(P); - end; - 0 : for i := 1 to 2 do begin - done := false; - while (P < PEnd) and not done do begin - token := P^; - if token = ';' then done := true; - inc(P); - end; - end; - +1: ; - end; - - ALeft := ''; - done := false; - - while (P < PEnd) and not done do begin - token := P^; - case token of - '_': inc(P); - ';': done := true; - '"': ; - '*': begin - inc(P); - done := true; - end; - '0', - '#': begin - ALeft := ALeft + token; - Result := 1; - end; - else ALeft := ALeft + token; - end; - inc(P); - end; - - ARight := ''; - done := false; - while (P < PEnd) and not done do begin - token := P^; - case token of - '_': inc(P); - ';': done := true; - '"': ; - '0', - '#': begin - ARight := ARight + token; - Result := 2; - end; - else ARight := ARight + token; - end; - inc(P); - end; -end; - procedure SplitFormatString(const AFormatString: String; out APositivePart, ANegativePart, AZeroPart: String); @@ -1068,35 +1006,14 @@ begin end; end; -{ Formats the number AValue in "scientific" format with the given number of - decimals. "Scientific" is the same as "exponential", but with exponents rounded - to multiples of 3 (like for "kilo" - "Mega" - "Giga" etc.). } -function SciFloat(AValue: Double; ADecimals: Byte; - AFormatSettings: TFormatSettings): String; -var - m: Double; - ex: Integer; -begin - if AValue = 0 then - Result := Format('%0.*fE+0', [ADecimals, 0.0], AFormatSettings) - // Excel shows "000.0E+0", but I think the "0.0E+0" shown here is better. - else begin - ex := floor(log10(abs(AValue))); // exponent - // round exponent to multiples of 3 - ex := (ex div 3) * 3; - if ex < 0 then dec(ex, 3); - m := AValue * Power(10, -ex); // mantisse - Result := Format('%.*fE+%d', [ADecimals, m, ex], AFormatSettings); - end; -end; +{@@ + Creates a "time interval" format string having the first time code identifier + in square brackets. -function SciFloat(AValue: Double; ADecimals: Byte): String; -begin - Result := SciFloat(AValue, ADecimals, DefaultFormatSettings); -end; - -{ Creates a "time interval" format string having the first code identifier - in square brackets. } + @param Src Source format string, must be a time format string, like 'hh:nn' + @param Dest Destination format string, will have the first time code element + of the src format string in square brackets, like '[hh]:nn'. +} procedure MakeTimeIntervalMask(Src: String; var Dest: String); var L: TStrings; diff --git a/components/fpspreadsheet/tests/formattests.pas b/components/fpspreadsheet/tests/formattests.pas index b740c149b..6c97eea5d 100644 --- a/components/fpspreadsheet/tests/formattests.pas +++ b/components/fpspreadsheet/tests/formattests.pas @@ -18,10 +18,10 @@ uses var // Norm to test against - list of strings that should occur in spreadsheet - SollNumberStrings: array[0..6, 0..8] of string; + SollNumberStrings: array[0..6, 0..7] of string; SollNumbers: array[0..6] of Double; - SollNumberFormats: array[0..8] of TsNumberFormat; - SollNumberDecimals: array[0..8] of word; + SollNumberFormats: array[0..7] of TsNumberFormat; + SollNumberDecimals: array[0..7] of word; SollDateTimeStrings: array[0..4, 0..9] of string; SollDateTimes: array[0..4] of TDateTime; @@ -164,7 +164,6 @@ begin SollNumberFormats[5] := nfExp; SollNumberDecimals[5] := 2; SollNumberFormats[6] := nfPercentage; SollNumberDecimals[6] := 0; SollNumberFormats[7] := nfPercentage; SollNumberDecimals[7] := 2; - SollNumberFormats[8] := nfSci; SollNumberDecimals[8] := 1; for i:=Low(SollNumbers) to High(SollNumbers) do begin SollNumberStrings[i, 0] := FloatToStr(SollNumbers[i], fs); @@ -175,7 +174,6 @@ begin SollNumberStrings[i, 5] := FormatFloat('0.00E+00', SollNumbers[i], fs); SollNumberStrings[i, 6] := FormatFloat('0', SollNumbers[i]*100, fs) + '%'; SollNumberStrings[i, 7] := FormatFloat('0.00', SollNumbers[i]*100, fs) + '%'; - SollNumberStrings[i, 8] := SciFloat(SollNumbers[i], 1, fs); end; // Date/time values @@ -288,8 +286,6 @@ begin for Col := ord(Low(SollNumberFormats)) to ord(High(SollNumberFormats)) do begin MyWorksheet.WriteNumber(Row, Col, SollNumbers[Row], SollNumberFormats[Col], SollNumberDecimals[Col]); ActualString := MyWorksheet.ReadAsUTF8Text(Row, Col); - if (AFormat=sfExcel2) and (SollNumberFormats[Col] = nfSci) then - Continue; // BIFF2 does not support nfSci -> ignore CheckEquals(SollNumberStrings[Row, Col], ActualString, 'Test unsaved string mismatch cell ' + CellNotation(MyWorksheet,Row,Col)); end; MyWorkBook.WriteToFile(TempFile, AFormat, true); @@ -306,8 +302,6 @@ begin fail('Error in test code. Failed to get named worksheet'); for Row := Low(SollNumbers) to High(SollNumbers) do for Col := Low(SollNumberFormats) to High(SollNumberFormats) do begin - if (AFormat=sfExcel2) and (SollNumberFormats[Col] = nfSci) then - Continue; // BIFF2 does not support nfSci --> ignore ActualString := MyWorkSheet.ReadAsUTF8Text(Row,Col); CheckEquals(SollNumberStrings[Row,Col],ActualString,'Test saved string mismatch cell '+CellNotation(MyWorkSheet,Row,Col)); end; diff --git a/components/fpspreadsheet/tests/numberstests.pas b/components/fpspreadsheet/tests/numberstests.pas index ea7192c8b..479cc9684 100644 --- a/components/fpspreadsheet/tests/numberstests.pas +++ b/components/fpspreadsheet/tests/numberstests.pas @@ -22,7 +22,7 @@ uses var // Norm to test against - list of numbers/times that should occur in spreadsheet - SollNumbers: array[0..23] of double; //"Soll" is a German word in Dutch accountancy jargon meaning "normative value to check against". There ;) + SollNumbers: array[0..22] of double; //"Soll" is a German word in Dutch accountancy jargon meaning "normative value to check against". There ;) // Initializes Soll*/normative variables. // Useful in test setup procedures to make sure the norm is correct. procedure InitSollNumbers; @@ -64,7 +64,6 @@ type procedure TestReadNumber20; procedure TestReadNumber21; procedure TestReadNumber22; - procedure TestReadNumber23; procedure TestReadODFNumber0; //number tests using ODF/LibreOffice file format procedure TestReadODFNumber1; //number and time procedure TestReadODFNumber2; @@ -88,7 +87,6 @@ type procedure TestReadODFNumber20; procedure TestReadODFNumber21; procedure TestReadODFNumber22; - procedure TestReadODFNumber23; end; { TSpreadWriteReadNumberTests } @@ -142,13 +140,12 @@ begin SollNumbers[14]:=0.3536; // 0.3536 formatted as percentage, 2 decimals SollNumbers[15]:=59000000.1234; // 59 million + 0.1234 formatted with thousand separator, no decimals SollNumbers[16]:=59000000.1234; // 59 million + 0.1234 formatted with thousand separator, 2 decimals - SollNumbers[17]:=-59000000.1234; // minus 59 million + 0.1234, formatted as "scientific" with 1 decimal - SollNumbers[18]:=-59000000.1234; // minus 59 million + 0.1234, formatted as "exp" with 2 decimals - SollNumbers[19]:=59000000.1234; // 59 million + 0.1234 formatted as currrency (EUROs, at end), 2 decimals - SollNumbers[20]:=59000000.1234; // 59 million + 0.1234 formatted as currrency (Dollars, at end), 2 decimals - SollNumbers[21]:=-59000000.1234; // minus 59 million + 0.1234 formatted as currrency (EUROs, at end), 2 decimals - SollNumbers[22]:=-59000000.1234; // minus 59 million + 0.1234 formatted as currrency (Dollars, at end), 2 decimals - SollNumbers[23]:=-59000000.1234; // minus 59 million + 0.1234 formatted as currrency (Dollars, at end, neg red), 2 decimals + SollNumbers[17]:=-59000000.1234; // minus 59 million + 0.1234, formatted as "exp" with 2 decimals + SollNumbers[18]:=59000000.1234; // 59 million + 0.1234 formatted as currrency (EUROs, at end), 2 decimals + SollNumbers[19]:=59000000.1234; // 59 million + 0.1234 formatted as currrency (Dollars, at end), 2 decimals + SollNumbers[20]:=-59000000.1234; // minus 59 million + 0.1234 formatted as currrency (EUROs, at end), 2 decimals + SollNumbers[21]:=-59000000.1234; // minus 59 million + 0.1234 formatted as currrency (Dollars, at end), 2 decimals + SollNumbers[22]:=-59000000.1234; // minus 59 million + 0.1234 formatted as currrency (Dollars, at end, neg red), 2 decimals end; { TSpreadWriteReadNumberTests } @@ -395,11 +392,6 @@ begin TestReadNumber(ExtractFilePath(ParamStr(0)) + TestFileBIFF8,22); end; -procedure TSpreadReadNumberTests.TestReadNumber23; -begin - TestReadNumber(ExtractFilePath(ParamStr(0)) + TestFileBIFF8,23); -end; - procedure TSpreadReadNumberTests.TestReadODFNumber0; begin TestReadNumber(ExtractFilePath(ParamStr(0)) + TestFileODF,0); @@ -515,11 +507,6 @@ begin TestReadNumber(ExtractFilePath(ParamStr(0)) + TestFileODF,22); end; -procedure TSpreadReadNumberTests.TestReadODFNumber23; -begin - TestReadNumber(ExtractFilePath(ParamStr(0)) + TestFileODF,23); -end; - initialization // Register so these tests are included in a full run diff --git a/components/fpspreadsheet/tests/spreadtestgui.lpi b/components/fpspreadsheet/tests/spreadtestgui.lpi index 597f7735e..a519b4425 100644 --- a/components/fpspreadsheet/tests/spreadtestgui.lpi +++ b/components/fpspreadsheet/tests/spreadtestgui.lpi @@ -103,6 +103,7 @@ + diff --git a/components/fpspreadsheet/tests/stringtests.pas b/components/fpspreadsheet/tests/stringtests.pas index 56efbf37e..9a6660e4d 100644 --- a/components/fpspreadsheet/tests/stringtests.pas +++ b/components/fpspreadsheet/tests/stringtests.pas @@ -30,7 +30,7 @@ uses var // Norm to test against - list of strings that should occur in spreadsheet - SollStrings: array[0..14] of string; //"Soll" is a German word in Dutch accountancy jargon meaning "normative value to check against". There ;) + SollStrings: array[0..13] of string; //"Soll" is a German word in Dutch accountancy jargon meaning "normative value to check against". There ;) // Initializes Soll*/normative variables. // Useful in test setup procedures to make sure the norm is correct. procedure InitSollStrings; @@ -63,7 +63,6 @@ type procedure TestReadString11; procedure TestReadString12; procedure TestReadString13; - procedure TestReadString14; procedure TestReadODFString0; //OpenDocument/LibreOffice format empty string procedure TestReadODFString1; procedure TestReadODFString2; @@ -78,7 +77,6 @@ type procedure TestReadODFString11; procedure TestReadODFString12; procedure TestReadODFString13; - procedure TestReadODFString14; end; { TSpreadWriteReadStringTests } @@ -124,10 +122,9 @@ begin SollStrings[8]:=FormatFloat('0.00', 35.36)+'%'; // 0.3536 formatted as percentage, 2 decimals SollStrings[9]:=FormatFloat('#,##0', 59000000.1234); // 59 million + 0.1234 formatted with thousand separator, no decimals SollStrings[10]:=FormatFloat('#,##0.00', 59000000.1234); // 59 million + 0.1234 formatted with thousand separator, 2 decimals - SollStrings[11]:=SciFloat(-59000000.1234, 1); // minus 59 million + 0.1234, formatted as "scientific" with 1 decimal - SollStrings[12]:=FormatFloat('0.00E+00', -59000000.1234); // minus 59 million + 0.1234, formatted as "exp" with 2 decimals - SollStrings[13]:=FormatFloat('#,##0.00 "EUR";(#,##0.00 "EUR")', 59000000.1234); // 59 million + 0.1234, formatted as "currencyRed" with 2 decimals, brackets and EUR - SollStrings[14]:=FormatFloat('#,##0.00 "EUR";(#,##0.00 "EUR")', -59000000.1234); // minus 59 million + 0.1234, formatted as "currencyRed" with 2 decimals, brackets and EUR + SollStrings[11]:=FormatFloat('0.00E+00', -59000000.1234); // minus 59 million + 0.1234, formatted as "exp" with 2 decimals + SollStrings[12]:=FormatFloat('#,##0.00 "EUR";(#,##0.00 "EUR")', 59000000.1234); // 59 million + 0.1234, formatted as "currencyRed" with 2 decimals, brackets and EUR + SollStrings[13]:=FormatFloat('#,##0.00 "EUR";(#,##0.00 "EUR")', -59000000.1234); // minus 59 million + 0.1234, formatted as "currencyRed" with 2 decimals, brackets and EUR end; { TSpreadWriteReadStringTests } @@ -415,11 +412,6 @@ begin TestReadString(ExtractFilePath(ParamStr(0)) + TestFileBIFF8,13); end; -procedure TSpreadReadStringTests.TestReadString14; -begin - TestReadString(ExtractFilePath(ParamStr(0)) + TestFileBIFF8,14); -end; - procedure TSpreadReadStringTests.TestReadODFString0; begin TestReadString(ExtractFilePath(ParamStr(0)) + TestFileODF,0); @@ -490,10 +482,6 @@ begin TestReadString(ExtractFilePath(ParamStr(0)) + TestFileODF,13); end; -procedure TSpreadReadStringTests.TestReadODFString14; -begin - TestReadString(ExtractFilePath(ParamStr(0)) + TestFileODF,14); -end; initialization // Register so these tests are included in a full run diff --git a/components/fpspreadsheet/tests/testbiff8_1899.xls b/components/fpspreadsheet/tests/testbiff8_1899.xls index 361c4d243..c73994677 100644 Binary files a/components/fpspreadsheet/tests/testbiff8_1899.xls and b/components/fpspreadsheet/tests/testbiff8_1899.xls differ diff --git a/components/fpspreadsheet/tests/testbiff8_1904.xls b/components/fpspreadsheet/tests/testbiff8_1904.xls index 6850c0637..3e01305a8 100644 Binary files a/components/fpspreadsheet/tests/testbiff8_1904.xls and b/components/fpspreadsheet/tests/testbiff8_1904.xls differ diff --git a/components/fpspreadsheet/tests/testodf_1899.ods b/components/fpspreadsheet/tests/testodf_1899.ods index adbbb8a41..15f28cf6b 100644 Binary files a/components/fpspreadsheet/tests/testodf_1899.ods and b/components/fpspreadsheet/tests/testodf_1899.ods differ diff --git a/components/fpspreadsheet/tests/testodf_1904.ods b/components/fpspreadsheet/tests/testodf_1904.ods index 7aad1ee4b..8d1c9adda 100644 Binary files a/components/fpspreadsheet/tests/testodf_1904.ods and b/components/fpspreadsheet/tests/testodf_1904.ods differ diff --git a/components/fpspreadsheet/xlsbiff2.pas b/components/fpspreadsheet/xlsbiff2.pas index fd28aaf57..1990e5c26 100755 --- a/components/fpspreadsheet/xlsbiff2.pas +++ b/components/fpspreadsheet/xlsbiff2.pas @@ -235,6 +235,8 @@ var decs: Integer; dt: string; begin + Result := 0; + parser := TsNumFormatParser.Create(Workbook, AFormatCell^.NumberFormatStr); try decs := parser.Decimals; @@ -243,25 +245,23 @@ begin parser.Free; end; - Result := 0; case AFormatCell^.NumberFormat of - nfFixed : Result := IfThen(decs = 0, 1, 2); - nfFixedTh : Result := IfThen(decs = 0, 3, 4); - nfCurrency, - nfAccounting : Result := IfThen(decs = 0, 5, 7); - nfCurrencyRed, - nfAccountingRed : Result := IfThen(decs = 0, 6, 8); - nfPercentage : Result := IfThen(decs = 0, 9, 10); - nfExp, nfSci : Result := 11; - nfShortDate : Result := 12; - nfLongDate : Result := 13; - nfShortTimeAM : Result := 16; - nfLongTimeAM : Result := 17; - nfShortTime : Result := 18; - nfLongTime : Result := 19; - nfShortDateTime : Result := 20; - nfCustom : if dt = 'dm' then Result := 14 else - if dt = 'my' then Result := 15; + nfGeneral : exit; + nfFixed : Result := IfThen(decs = 0, 1, 2); + nfFixedTh : Result := IfThen(decs = 0, 3, 4); + nfCurrency : Result := IfThen(decs = 0, 5, 7); + nfCurrencyRed : Result := IfThen(decs = 0, 6, 8); + nfPercentage : Result := IfThen(decs = 0, 9, 10); + nfExp : Result := 11; + nfShortDate : Result := 12; + nfLongDate : Result := 13; + nfShortTimeAM : Result := 16; + nfLongTimeAM : Result := 17; + nfShortTime : Result := 18; + nfLongTime : Result := 19; + nfShortDateTime: Result := 20; + nfCustom : if dt = 'dm' then Result := 14 else + if dt = 'my' then Result := 15; end; end; diff --git a/components/fpspreadsheet/xlscommon.pas b/components/fpspreadsheet/xlscommon.pas index d66ebd1d0..46b3a9efb 100644 --- a/components/fpspreadsheet/xlscommon.pas +++ b/components/fpspreadsheet/xlscommon.pas @@ -742,14 +742,14 @@ begin AddFormat(38, '_(#,##0_);[Red](#,##0)', nfCurrencyRed); AddFormat(39, '_(#,##0.00_);(#,##0.00)', nfCurrency); AddFormat(40, '_(#,##0.00_);[Red](#,##0.00)', nfCurrencyRed); - AddFormat(41, '_("'+cs+'"* #,##0_);_("'+cs+'"* (#,##0);_("'+cs+'"* "-"_);_(@_)', nfAccounting); - AddFormat(42, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)', nfAccounting); - AddFormat(43, '_("'+cs+'"* #,##0.00_);_("'+cs+'"* (#,##0.00);_("'+cs+'"* "-"??_);_(@_)', nfAccounting); - AddFormat(44, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)', nfAccounting); + AddFormat(41, '_("'+cs+'"* #,##0_);_("'+cs+'"* (#,##0);_("'+cs+'"* "-"_);_(@_)', nfCustom); + AddFormat(42, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)', nfCustom); + AddFormat(43, '_("'+cs+'"* #,##0.00_);_("'+cs+'"* (#,##0.00);_("'+cs+'"* "-"??_);_(@_)', nfCustom); + AddFormat(44, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)', nfCustom); AddFormat(45, 'nn:ss', nfCustom); AddFormat(46, '[h]:nn:ss', nfTimeInterval); AddFormat(47, 'nn:ss.z', nfCustom); - AddFormat(48, '##0.0E+00', nfSci); + AddFormat(48, '##0.0E+00', nfCustom); // 49 ("Text") not supported // All indexes from 0 to 163 are reserved for built-in formats.