diff --git a/components/fpspreadsheet/examples/db_import_export/db_export_import.lpi b/components/fpspreadsheet/examples/db_import_export/db_export_import.lpi index e0482d46d..f8f0dc238 100644 --- a/components/fpspreadsheet/examples/db_import_export/db_export_import.lpi +++ b/components/fpspreadsheet/examples/db_import_export/db_export_import.lpi @@ -1,11 +1,13 @@ - + + + + - <ResourceType Value="res"/> <UseXPManifest Value="True"/> diff --git a/components/fpspreadsheet/examples/db_import_export/main.lfm b/components/fpspreadsheet/examples/db_import_export/main.lfm index d1bd429b9..5a3d72a8f 100644 --- a/components/fpspreadsheet/examples/db_import_export/main.lfm +++ b/components/fpspreadsheet/examples/db_import_export/main.lfm @@ -8,7 +8,7 @@ object Form1: TForm1 ClientWidth = 521 OnCreate = FormCreate OnDestroy = FormDestroy - LCLVersion = '1.9.0.0' + LCLVersion = '2.1.0.0' object PageControl: TPageControl Left = 4 Height = 302 @@ -95,7 +95,7 @@ object Form1: TForm1 Left = 8 Height = 15 Top = 40 - Width = 324 + Width = 325 Caption = 'Please note: the binary xls files can handle only 65536 records.' ParentColor = False end diff --git a/components/fpspreadsheet/examples/db_import_export/main.pas b/components/fpspreadsheet/examples/db_import_export/main.pas index b67890a6f..e5d869905 100644 --- a/components/fpspreadsheet/examples/db_import_export/main.pas +++ b/components/fpspreadsheet/examples/db_import_export/main.pas @@ -55,6 +55,7 @@ type FHeaderTemplateCell: PCell; FDateTemplateCell: PCell; FCurrencyTemplatecell: PCell; + FSocialSecurityTemplateCell: PCell; FImportedFieldNames: TStringList; FImportedRowCells: Array of TCell; // Actual export code when using FPSpreadsheet's fpsexport: @@ -130,6 +131,15 @@ const { TForm1 } +function RandomNumberStr(ALength: Integer): String; +var + i: Integer; +begin + SetLength(Result, ALength); + for i := 1 to ALength do + Result[i] := char(ord('0') + Random(10)); +end; + { This procedure creates a test dbf table with random data for us to play with } procedure TForm1.BtnCreateDatabaseClick(Sender: TObject); var @@ -163,6 +173,7 @@ begin FExportDataset.FieldDefs.Add('Last name', ftString); FExportDataset.FieldDefs.Add('First name', ftString); FExportDataset.FieldDefs.Add('City', ftString); + FExportDataset.FieldDefs.Add('Social sec', ftString); FExportDataset.FieldDefs.Add('Birthday', ftDate); FExportDataset.FieldDefs.Add('Salary', ftCurrency); FExportDataset.FieldDefs.Add('Work begin', ftDateTime); @@ -196,6 +207,7 @@ begin FExportDataset.FieldByName('Size').AsFloat := (160 + Random(50)) / 100; FExportDataSet.FieldByName('Work begin').AsDateTime := 40000+EncodeTime(6+Random(4), Random(60), Random(60), 0); FExportDataSet.FieldByName('Work end').AsDateTime := EncodeTime(15+Random(4), Random(60), Random(60), 0); + FExportDataSet.FieldByName('Social sec').AsString := RandomNumberStr(16); FExportDataset.Post; end; @@ -408,11 +420,12 @@ begin Exporter.ExportFields.AddField('City'); Exporter.Execute; - // On the second sheet we want "Last name", "First name" and "Birthday" + // On the second sheet we want "Last name", "First name", "Birthday" and "Social security number" Exporter.ExportFields.Clear; Exporter.ExportFields.AddField('Last name'); Exporter.ExportFields.AddField('First name'); Exporter.ExportFields.AddField('Birthday'); + Exporter.ExportFields.AddField('Social sec'); Exporter.Execute; // On the third sheet we want "Last name", "First name" and "Income" @@ -538,6 +551,10 @@ begin FCurrencyTemplateCell := worksheet.GetCell(0, 2); worksheet.WriteNumberFormat(FCurrencyTemplateCell, nfCurrency); + // Use cell D1 as format template for social security number column + FSocialSecurityTemplatecell := worksheet.GetCell(0, 3); + worksheet.WriteNumberFormat(FSocialSecurityTemplateCell, nfText); + // Make rows a bit wider worksheet.WriteColWidth(0, 20); worksheet.WriteColWidth(1, 20); @@ -684,8 +701,9 @@ begin if FExportDataset.Fields[ACol].DataType = ftDate then AStyleCell := FDateTemplateCell else if FExportDataset.Fields[ACol].DataType = ftCurrency then - AStyleCell := FCurrencyTemplateCell; - + AStyleCell := FCurrencyTemplateCell + else if SameText(FExportDataset.Fields[ACol].FieldName, 'Social sec') then + AStyleCell := FSocialSecurityTemplateCell; if ACol = Sender.VirtualColCount-1 then begin // Move to next record after last field has been written