RxFPC:TRxDBGridExportSpreadSheet allow export selected rows. tnx rellai2

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5359 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2016-11-17 07:04:27 +00:00
parent 44f0250efa
commit 1b7a79aa78
9 changed files with 270 additions and 129 deletions

View File

@ -9,7 +9,7 @@
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos Y="20"/>
<UsageCount Value="32"/>
<UsageCount Value="33"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
@ -18,10 +18,9 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
<IsVisibleTab Value="True"/>
<TopLine Value="3"/>
<CursorPos X="6" Y="84"/>
<UsageCount Value="32"/>
<CursorPos X="105" Y="24"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
@ -43,19 +42,17 @@
<Unit4>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<UnitName Value="RxDBGridExportSpreadSheet"/>
<EditorIndex Value="-1"/>
<TopLine Value="345"/>
<CursorPos X="40" Y="358"/>
<EditorIndex Value="1"/>
<TopLine Value="197"/>
<CursorPos X="7" Y="217"/>
<UsageCount Value="15"/>
<Bookmarks Count="1">
<Item0 Y="404" ID="1"/>
</Bookmarks>
<Loaded Value="True"/>
</Unit4>
<Unit5>
<Filename Value="../../rxdbgrid.pas"/>
<EditorIndex Value="1"/>
<TopLine Value="5397"/>
<CursorPos X="54" Y="5421"/>
<EditorIndex Value="4"/>
<TopLine Value="4700"/>
<CursorPos Y="4718"/>
<UsageCount Value="15"/>
<Bookmarks Count="2">
<Item0 X="14" Y="822" ID="1"/>
@ -76,17 +73,21 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="RxDBGridExportSpreadSheet_ParamsUnit"/>
<EditorIndex Value="-1"/>
<TopLine Value="53"/>
<CursorPos X="43" Y="82"/>
<EditorIndex Value="2"/>
<TopLine Value="51"/>
<CursorPos X="33" Y="85"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit7>
<Unit8>
<Filename Value="../../rxdconst.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="163"/>
<CursorPos X="17" Y="182"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="3"/>
<TopLine Value="173"/>
<CursorPos X="21" Y="185"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
<Filename Value="../../../../lcl/include/control.inc"/>
@ -104,54 +105,127 @@
<UsageCount Value="10"/>
</Unit10>
</Units>
<JumpHistory Count="9" HistoryIndex="8">
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="73" TopLine="57"/>
<Caret Line="22" Column="5" TopLine="3"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="78" TopLine="57"/>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="443" Column="3" TopLine="439"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="78" TopLine="57"/>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="63" Column="30" TopLine="54"/>
</Position3>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="84" Column="6" TopLine="3"/>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="504" Column="3" TopLine="500"/>
</Position4>
<Position5>
<Filename Value="../../rxdbgrid.pas"/>
<Caret Line="117" Column="37" TopLine="100"/>
<Filename Value="../../rxdbgridexportspreadsheet_paramsunit.pas"/>
<Caret Line="46" Column="3" TopLine="27"/>
</Position5>
<Position6>
<Filename Value="../../rxdbgrid.pas"/>
<Caret Line="990" Column="61" TopLine="959"/>
<Filename Value="../../rxdbgridexportspreadsheet_paramsunit.pas"/>
<Caret Line="85" Column="33" TopLine="51"/>
</Position6>
<Position7>
<Filename Value="../../rxdbgrid.pas"/>
<Caret Line="4542" Column="24" TopLine="4512"/>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="504" Column="3" TopLine="500"/>
</Position7>
<Position8>
<Filename Value="../../rxdbgrid.pas"/>
<Caret Line="5445" Column="9" TopLine="5409"/>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="47" Column="7" TopLine="23"/>
</Position8>
<Position9>
<Filename Value="../../rxdbgrid.pas"/>
<Caret Line="5425" Column="15" TopLine="5407"/>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="273" TopLine="250"/>
</Position9>
<Position10>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="329" TopLine="323"/>
</Position10>
<Position11>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="204" Column="3" TopLine="173"/>
</Position11>
<Position12>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="129" Column="3" TopLine="108"/>
</Position12>
<Position13>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="135" Column="9" TopLine="115"/>
</Position13>
<Position14>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="138" Column="7" TopLine="118"/>
</Position14>
<Position15>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="140" Column="7" TopLine="120"/>
</Position15>
<Position16>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="146" Column="11" TopLine="127"/>
</Position16>
<Position17>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="149" Column="13" TopLine="131"/>
</Position17>
<Position18>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="173" Column="11" TopLine="154"/>
</Position18>
<Position19>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="224" Column="11" TopLine="194"/>
</Position19>
<Position20>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="227" Column="13" TopLine="209"/>
</Position20>
<Position21>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="63" Column="24" TopLine="45"/>
</Position21>
<Position22>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="134" TopLine="116"/>
</Position22>
<Position23>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="168" Column="9" TopLine="147"/>
</Position23>
<Position24>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="174" TopLine="164"/>
</Position24>
<Position25>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="126" Column="38" TopLine="107"/>
</Position25>
<Position26>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="63" Column="15" TopLine="44"/>
</Position26>
<Position27>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="171" Column="59" TopLine="152"/>
</Position27>
<Position28>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="134" TopLine="126"/>
</Position28>
<Position29>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="203" Column="16" TopLine="184"/>
</Position29>
<Position30>
<Filename Value="../../rxdbgridexportspreadsheet.pas"/>
<Caret Line="193" TopLine="193"/>
</Position30>
</JumpHistory>
</ProjectSession>
<Debugging>
<BreakPoints Count="1">
<Item1>
<Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/>
<Source Value="../../rxdbgrid.pas"/>
<Line Value="4718"/>
</Item1>
</BreakPoints>
</Debugging>
</CONFIG>

View File

@ -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"

View File

@ -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 ""

View File

@ -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 "Операции сравнения требуют наличия поля и константы"

View File

@ -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"

View File

@ -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;

View File

@ -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

View File

@ -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.

View File

@ -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';