diff --git a/components/rx/trunk/Demos/RxDBGrid_ExportSpreadsheet/project1.lps b/components/rx/trunk/Demos/RxDBGrid_ExportSpreadsheet/project1.lps index b06d9b9b5..e9aee9242 100644 --- a/components/rx/trunk/Demos/RxDBGrid_ExportSpreadsheet/project1.lps +++ b/components/rx/trunk/Demos/RxDBGrid_ExportSpreadsheet/project1.lps @@ -9,7 +9,7 @@ - + @@ -18,10 +18,9 @@ - - - + + @@ -43,19 +42,17 @@ - - - + + + - - - + - - - + + + @@ -76,17 +73,21 @@ - - - + + + + + - - - + + + + + @@ -104,54 +105,127 @@ - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - diff --git a/components/rx/trunk/languages/rxdconst.es.po b/components/rx/trunk/languages/rxdconst.es.po index 2622a9e5f..0ba16e01d 100644 --- a/components/rx/trunk/languages/rxdconst.es.po +++ b/components/rx/trunk/languages/rxdconst.es.po @@ -117,6 +117,10 @@ msgstr "" msgid "Export params" msgstr "" +#: rxdconst.sexportselectedrows +msgid "Export only selected rows" +msgstr "" + #: rxdconst.sexprbadcompare #, fuzzy #| msgid "Compare opertion need fielad and const" diff --git a/components/rx/trunk/languages/rxdconst.po b/components/rx/trunk/languages/rxdconst.po index 55f6e5481..3dbdfa99a 100644 --- a/components/rx/trunk/languages/rxdconst.po +++ b/components/rx/trunk/languages/rxdconst.po @@ -113,6 +113,10 @@ msgstr "" msgid "Export params" msgstr "" +#: rxdconst.sexportselectedrows +msgid "Export only selected rows" +msgstr "" + #: rxdconst.sexprbadcompare msgid "Compare opertion needs field and const" msgstr "" diff --git a/components/rx/trunk/languages/rxdconst.ru.po b/components/rx/trunk/languages/rxdconst.ru.po index 4527178ed..75c7883a2 100644 --- a/components/rx/trunk/languages/rxdconst.ru.po +++ b/components/rx/trunk/languages/rxdconst.ru.po @@ -123,6 +123,10 @@ msgstr "Экспорт изображений" msgid "Export params" msgstr "Параметры экспорта" +#: rxdconst.sexportselectedrows +msgid "Export only selected rows" +msgstr "Экспорт только помеченных строк" + #: rxdconst.sexprbadcompare msgid "Compare opertion needs field and const" msgstr "Операции сравнения требуют наличия поля и константы" diff --git a/components/rx/trunk/languages/rxdconst.uk.po b/components/rx/trunk/languages/rxdconst.uk.po index df24e6fb7..d9437f622 100644 --- a/components/rx/trunk/languages/rxdconst.uk.po +++ b/components/rx/trunk/languages/rxdconst.uk.po @@ -122,6 +122,10 @@ msgstr "Експортувати зображення" msgid "Export params" msgstr "Експортувати параметри" +#: rxdconst.sexportselectedrows +msgid "Export only selected rows" +msgstr "" + # msgid "Compare opertion need fielad and const" #: rxdconst.sexprbadcompare msgid "Compare opertion needs field and const" diff --git a/components/rx/trunk/rxdbgridexportspreadsheet.pas b/components/rx/trunk/rxdbgridexportspreadsheet.pas index 4c0601fff..421e2f23f 100644 --- a/components/rx/trunk/rxdbgridexportspreadsheet.pas +++ b/components/rx/trunk/rxdbgridexportspreadsheet.pas @@ -43,7 +43,8 @@ type ressExportColors, ressExportFooter, ressExportFormula, - ressOverwriteExisting + ressOverwriteExisting, + ressExportSelectedRows ); TRxDBGridExportSpreadSheetOptions = set of TRxDBGridExportSpreadSheetOption; @@ -59,6 +60,9 @@ type FOptions: TRxDBGridExportSpreadSheetOptions; FPageName: string; function ColIndex(ACol:TRxColumn):integer; + procedure ExpCurRow(AFont: TFont); + procedure ExpAllRow; + procedure ExpSelectedRow; protected FDataSet:TDataSet; FWorkbook: TsWorkbook; @@ -88,7 +92,7 @@ procedure Register; implementation uses fpsallformats, LCLType, Forms, math, LazUTF8, rxdconst, Controls, LCLIntf, - RxDBGridExportSpreadSheet_ParamsUnit, rxdbutils, fpsutils; + RxDBGridExportSpreadSheet_ParamsUnit, rxdbutils, fpsutils, DBGrids; {$R rxdbgridexportspreadsheet.res} @@ -119,6 +123,106 @@ begin end; end; +procedure TRxDBGridExportSpreadSheet.ExpCurRow(AFont:TFont); +var + i, J: Integer; + C: TRxColumn; + CT: TRxColumnTitle; + S: String; + CC: TColor; +begin + FCurCol:=0; + for i:=0 to FRxDBGrid.Columns.Count - 1 do + begin + C:=FRxDBGrid.Columns[i] as TRxColumn; + CT:=C.Title as TRxColumnTitle; + if C.Visible then + begin + if Assigned(C.Field) then + begin + S:=C.Field.DisplayText; + if (C.KeyList.Count > 0) and (C.PickList.Count > 0) then + begin + J := C.KeyList.IndexOf(S); + if (J >= 0) and (J < C.PickList.Count) then + S := C.PickList[j]; + FWorksheet.WriteUTF8Text(FCurRow, FCurCol, S); + end + else + if Assigned(C.Field.OnGetText) then + FWorksheet.WriteUTF8Text(FCurRow, FCurCol, S) + else + if C.Field.DataType in [ftCurrency] then + FWorksheet.WriteCurrency(FCurRow, FCurCol, C.Field.AsCurrency, nfCurrency, '') + else + if C.Field.DataType in IntegerDataTypes then + FWorksheet.WriteNumber(FCurRow, FCurCol, C.Field.AsInteger, nfFixed, 0) + else + if C.Field.DataType in NumericDataTypes then + FWorksheet.WriteNumber(FCurRow, FCurCol, C.Field.AsFloat, nfFixed, 2) + else + FWorksheet.WriteUTF8Text(FCurRow, FCurCol, S); + end; + + if ressExportColors in FOptions then + begin + CC:=C.Color; + if Assigned(RxDBGrid.OnGetCellProps) then + RxDBGrid.OnGetCellProps(RxDBGrid, C.Field, AFont, CC); + if (CC and SYS_COLOR_BASE) = 0 then + begin + {$IFDEF OLD_fpSPREADSHEET} + scColor:=FWorkbook.AddColorToPalette(CC); + FWorksheet.WriteBackgroundColor(FCurRow,FCurCol, scColor); + {$ELSE} + FWorksheet.WriteBackgroundColor(FCurRow,FCurCol, CC); + {$ENDIF} + end; + end; + + FWorksheet.WriteBorders(FCurRow,FCurCol, [cbNorth, cbWest, cbEast, cbSouth]); + FWorksheet.WriteBorderColor(FCurRow,FCurCol, cbNorth, scColorBlack); + FWorksheet.WriteBorderColor(FCurRow,FCurCol, cbWest, scColorBlack); + FWorksheet.WriteBorderColor(FCurRow,FCurCol, cbEast, scColorBlack); + FWorksheet.WriteBorderColor(FCurRow,FCurCol, cbSouth, scColorBlack); + + FWorksheet.WriteHorAlignment(FCurRow, FCurCol, ssAligns[C.Alignment]); + inc(FCurCol); + end; + end; +end; + +procedure TRxDBGridExportSpreadSheet.ExpAllRow; +var + F: TFont; +begin + F:=TFont.Create; + FDataSet.First; + while not FDataSet.EOF do + begin + ExpCurRow(F); + inc(FCurRow); + FDataSet.Next; + end; + F.Free; +end; + +procedure TRxDBGridExportSpreadSheet.ExpSelectedRow; +var + F: TFont; + k: Integer; +begin + F:=TFont.Create; + FDataSet.First; + for k:=0 to FRxDBGrid.SelectedRows.Count-1 do + begin + FDataSet.Bookmark:=FRxDBGrid.SelectedRows[k]; + ExpCurRow(F); + inc(FCurRow); + end; + F.Free; +end; + procedure TRxDBGridExportSpreadSheet.DoExportTitle; var i, k : Integer; @@ -242,83 +346,12 @@ begin end; procedure TRxDBGridExportSpreadSheet.DoExportBody; -var - i : Integer; - C : TRxColumn; - CT : TRxColumnTitle; - CC : TColor; - scColor : TsColor; - F:TFont; - S: String; - J: Integer; begin - F:=TFont.Create; - FDataSet.First; - while not FDataSet.EOF do - begin - FCurCol:=0; - for i:=0 to FRxDBGrid.Columns.Count - 1 do - begin - C:=FRxDBGrid.Columns[i] as TRxColumn; - CT:=C.Title as TRxColumnTitle; - if C.Visible then - begin - if Assigned(C.Field) then - begin - S:=C.Field.DisplayText; - if (C.KeyList.Count > 0) and (C.PickList.Count > 0) then - begin - J := C.KeyList.IndexOf(S); - if (J >= 0) and (J < C.PickList.Count) then - S := C.PickList[j]; - FWorksheet.WriteUTF8Text(FCurRow, FCurCol, S); - end - else - if Assigned(C.Field.OnGetText) then - FWorksheet.WriteUTF8Text(FCurRow, FCurCol, S) - else - if C.Field.DataType in [ftCurrency] then - FWorksheet.WriteCurrency(FCurRow, FCurCol, C.Field.AsCurrency, nfCurrency, '') - else - if C.Field.DataType in IntegerDataTypes then - FWorksheet.WriteNumber(FCurRow, FCurCol, C.Field.AsInteger, nfFixed, 0) - else - if C.Field.DataType in NumericDataTypes then - FWorksheet.WriteNumber(FCurRow, FCurCol, C.Field.AsFloat, nfFixed, 2) - else - FWorksheet.WriteUTF8Text(FCurRow, FCurCol, S); - end; + if (dgMultiselect in RxDBGrid.Options) and (RxDBGrid.SelectedRows.Count > 0) and (ressExportSelectedRows in FOptions) then + ExpSelectedRow + else + ExpAllRow; - if ressExportColors in FOptions then - begin - CC:=C.Color; - if Assigned(RxDBGrid.OnGetCellProps) then - RxDBGrid.OnGetCellProps(RxDBGrid, C.Field, F, CC); - if (CC and SYS_COLOR_BASE) = 0 then - begin - {$IFDEF OLD_fpSPREADSHEET} - scColor:=FWorkbook.AddColorToPalette(CC); - FWorksheet.WriteBackgroundColor(FCurRow,FCurCol, scColor); - {$ELSE} - FWorksheet.WriteBackgroundColor(FCurRow,FCurCol, CC); - {$ENDIF} - end; - end; - - FWorksheet.WriteBorders(FCurRow,FCurCol, [cbNorth, cbWest, cbEast, cbSouth]); - FWorksheet.WriteBorderColor(FCurRow,FCurCol, cbNorth, scColorBlack); - FWorksheet.WriteBorderColor(FCurRow,FCurCol, cbWest, scColorBlack); - FWorksheet.WriteBorderColor(FCurRow,FCurCol, cbEast, scColorBlack); - FWorksheet.WriteBorderColor(FCurRow,FCurCol, cbSouth, scColorBlack); - - FWorksheet.WriteHorAlignment(FCurRow, FCurCol, ssAligns[C.Alignment]); - inc(FCurCol); - end; - end; - inc(FCurRow); - FDataSet.Next; - end; - F.Free; FLastDataRow:=FCurRow-1; end; @@ -497,6 +530,8 @@ begin F.cbExportCellColors.Checked:=ressExportColors in FOptions; F.cbOverwriteExisting.Checked:=ressOverwriteExisting in FOptions; F.cbExportFormula.Checked:=ressExportFormula in FOptions; + F.cbExportSelectedRows.Checked:=ressExportSelectedRows in FOptions; + F.cbExportSelectedRows.Enabled:=(dgMultiselect in RxDBGrid.Options) and (RxDBGrid.SelectedRows.Count > 0); F.edtPageName.Text:=FPageName; @@ -518,7 +553,8 @@ begin FOptions :=FOptions + [ressOverwriteExisting]; if F.cbExportFormula.Checked then FOptions :=FOptions + [ressExportFormula]; - + if F.cbExportSelectedRows.Enabled and F.cbExportSelectedRows.Checked then + FOptions :=FOptions + [ressExportSelectedRows]; end; F.Free; end; diff --git a/components/rx/trunk/rxdbgridexportspreadsheet_paramsunit.lfm b/components/rx/trunk/rxdbgridexportspreadsheet_paramsunit.lfm index 01bde6a9e..31fc3273a 100644 --- a/components/rx/trunk/rxdbgridexportspreadsheet_paramsunit.lfm +++ b/components/rx/trunk/rxdbgridexportspreadsheet_paramsunit.lfm @@ -1,10 +1,10 @@ object RxDBGridExportSpreadSheet_ParamsForm: TRxDBGridExportSpreadSheet_ParamsForm Left = 732 - Height = 246 + Height = 294 Top = 338 Width = 548 Caption = 'Export params' - ClientHeight = 246 + ClientHeight = 294 ClientWidth = 548 OnCreate = FormCreate Position = poScreenCenter @@ -96,7 +96,7 @@ object RxDBGridExportSpreadSheet_ParamsForm: TRxDBGridExportSpreadSheet_ParamsFo object ButtonPanel1: TButtonPanel Left = 6 Height = 46 - Top = 194 + Top = 242 Width = 536 OKButton.Name = 'OKButton' OKButton.DefaultCaption = True @@ -167,4 +167,16 @@ object RxDBGridExportSpreadSheet_ParamsForm: TRxDBGridExportSpreadSheet_ParamsFo Caption = 'Export formula' TabOrder = 5 end + object cbExportSelectedRows: TCheckBox + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = cbExportCellColors + AnchorSideTop.Side = asrBottom + Left = 6 + Height = 24 + Top = 195 + Width = 163 + BorderSpacing.Around = 6 + Caption = 'Export selected rows' + TabOrder = 9 + end end diff --git a/components/rx/trunk/rxdbgridexportspreadsheet_paramsunit.pas b/components/rx/trunk/rxdbgridexportspreadsheet_paramsunit.pas index 3fe6450e4..d816b0cc7 100644 --- a/components/rx/trunk/rxdbgridexportspreadsheet_paramsunit.pas +++ b/components/rx/trunk/rxdbgridexportspreadsheet_paramsunit.pas @@ -45,6 +45,7 @@ type TRxDBGridExportSpreadSheet_ParamsForm = class(TForm) ButtonPanel1: TButtonPanel; + cbExportSelectedRows: TCheckBox; cbExportFormula: TCheckBox; cbExportColumnFooter: TCheckBox; cbOpenAfterExport: TCheckBox; @@ -81,6 +82,7 @@ begin cbExportCellColors.Caption:=sExportCellColors; cbOverwriteExisting.Caption:=sOverwriteExisting; cbExportFormula.Caption:=sExportFormula; + cbExportSelectedRows.Caption:=sExportSelectedRows; end; end. diff --git a/components/rx/trunk/rxdconst.pas b/components/rx/trunk/rxdconst.pas index 4c67e0687..2fbcb6f5a 100644 --- a/components/rx/trunk/rxdconst.pas +++ b/components/rx/trunk/rxdconst.pas @@ -185,6 +185,7 @@ resourcestring sExportCellColors = 'Export cell colors'; sExportFormula = 'Export footer formula'; sExportImages = 'Export images'; + sExportSelectedRows = 'Export only selected rows'; sOverwriteExisting = 'Overwrite existing'; sShowColumnHeaderOnAllPage = 'Show column header on all pages'; sPageMargins = 'Page margins';