📄 ufrm_ysbzjpx_pxjh.~pas
字号:
tbItalic.Down := fsItalic in AStyle;
tbUnderline.Down := fsUnderline in AStyle;
tbStrikeOut.Down := fsStrikeOut in AStyle;
edtCellEdit.Text := Text;
cbxFont.Text := Style.Font.Name;
cbxSize.Text := IntToStr(Style.Font.Size);
finally
Free;
end;
actBeveledLookandFeel.Checked := PainterType = ptOfficeXPStyle;
actBufferedpaint.Checked := BufferedPaint;
actShowcaptions.Checked := ShowCaptionBar;
actShowgrid.Checked := ShowGrid;
actShowheaders.Checked := ShowHeaders;
actShowformulas.Checked := ShowFormulas;
actR1C1Referencestyle.Checked := R1C1ReferenceStyle;
actAutomaticcalc.Checked := AutoRecalc;
end;
end;
function TFrm_ysbZjpx_pxjh.GetCellText(SelectionRect: TRect; R1C1: Boolean): String;
begin
Result := cxSpreadBook.CellsNameByRef(cxSpreadBook.ActivePage, SelectionRect);
end;
procedure TFrm_ysbZjpx_pxjh.edtCellEditExit(Sender: TObject);
begin
with cxSpreadBook do
begin
with ActiveSheet.GetCellObject(ActiveSheet.SelectionRect.Left, ActiveSheet.SelectionRect.Top) do
begin
Text := Text;
Free;
end;
UpdateControl;
SetFocus;
end;
cxSpreadBookSetSelection(Self, cxSpreadBook.ActiveSheet);
end;
procedure TFrm_ysbZjpx_pxjh.edtCellEditKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
Windows.SetFocus(cxSpreadBook.Handle);
edtCellEditExit(Sender);
end;
end;
procedure TFrm_ysbZjpx_pxjh.SaveAsSpreadSheet;
var
AFileName: string;
begin
if SaveDialog.Execute then
begin
AFileName := ChangeFileExt(SaveDialog.FileName, '.xls');
cxSpreadBook.SaveToFile(AFileName );
end;
end;
procedure TFrm_ysbZjpx_pxjh.miSaveSpreadSheetClick(Sender: TObject);
begin
SaveAsSpreadSheet;
end;
procedure TFrm_ysbZjpx_pxjh.Action1Execute(Sender: TObject);
begin
SaveAsSpreadSheet;
end;
procedure TFrm_ysbZjpx_pxjh.actSaveSpeadSheetExecute(Sender: TObject);
begin
SaveSpreadSheet;
end;
procedure TFrm_ysbZjpx_pxjh.actSaveAsSpeadSheetExecute(Sender: TObject);
begin
SaveAsSpreadSheet;
end;
procedure TFrm_ysbZjpx_pxjh.RzBitBtn1Click(Sender: TObject);
var
yyyymm:string;
aaa:TMemoryStream;
begin
yyyymm:=formatdatetime('yyyyMM',DateTimePicker1.date);
dm_ysbzjpx_pxjh.cx(yyyymm);
if dm_ysbzjpx_pxjh.dst_pxjh.IsEmpty then
begin
cxSpreadBook.clearall;
cxSpreadBook.PageCount:=cxSpreadBook.PageCount+1;
MessageBox(Handle, PChar('无数据!'), PChar('提示'), 64);
exit;
end;
aaa:=TMemoryStream.Create;
try
dm_ysbzjpx_pxjh.dst_pxjhpxnr.SaveToStream(aaa);
cxSpreadBook.LoadFromStream(aaa);
finally
aaa.Free;
end;
end;
procedure TFrm_ysbZjpx_pxjh.actNewExecute(Sender: TObject);
var
yyyymm:string;
// aaa:TMemoryStream;
begin
yyyymm:=formatdatetime('yyyyMM',DateTimePicker1.date);
// cxSpreadBook.ClearAll;
// cxSpreadBook.DeleteSheet(0);
if dm_ysbzjpx_pxjh.new(yyyymm) then
begin
//aaa:=TMemoryStream.Create;
FIsEditorMode:=true;
cxSpreadBook.clearall;
cxSpreadBook.PageCount:=cxSpreadBook.PageCount+1;
end
end;
procedure TFrm_ysbZjpx_pxjh.actMergeCellsExecute(Sender: TObject);
begin
with cxSpreadBook.ActiveSheet do
SetMergedState(SelectionRect, True); with cxSpreadBook.ActiveSheet do
SetMergedState(SelectionRect, True);
end;
procedure TFrm_ysbZjpx_pxjh.actSplitCellsExecute(Sender: TObject);
begin
with cxSpreadBook.ActiveSheet do
SetMergedState(SelectionRect, False);
end;
procedure TFrm_ysbZjpx_pxjh.actCellLeftAlignExecute(Sender: TObject);
begin
SetCellsStyle([svAlign], haLeft, 0, cbxFont.Text, []);
end;
procedure TFrm_ysbZjpx_pxjh.SetCellsStyle(AValuesSet: TStyleValueSet; AAlign: TcxHorzTextAlign;
AFontSize: Integer; const AFontName: string; AStyles: TFontStyles);
procedure SetValue(AFlag: TStyleValue; ANeedStyle: TFontStyle;
var ASetStyles: TFontStyles);
begin
if AFlag in AValuesSet then
begin
if ANeedStyle in AStyles then
Include(ASetStyles, ANeedStyle)
else
Exclude(ASetStyles, ANeedStyle);
end;
end;
var
I, J: Integer;
AStyle: TFontStyles;
begin
with cxSpreadBook do
try
BeginUpdate;
with ActiveSheet do
begin
for I := SelectionRect.Left to SelectionRect.Right do
for J := SelectionRect.Top to SelectionRect.Bottom do
with GetCellObject(I, J) do
try
with Style do
begin
AStyle := Font.Style;
if svFontName in AValuesSet then
Font.Name := AFontName;
if svSize in AValuesSet then
Font.Size := AFontSize;
if svAlign in AValuesSet then
HorzTextAlign := AAlign;
SetValue(svBold, fsBold, AStyle);
SetValue(svItalic, fsItalic, AStyle);
SetValue(svUnderline, fsUnderline, AStyle);
SetValue(svStrikeOut, fsStrikeOut, AStyle);
Font.Style := AStyle;
end;
finally
Free;
end;
end;
finally
EndUpdate;
UpdateControl;
end;
end;
procedure TFrm_ysbZjpx_pxjh.actCellRightAlignExecute(Sender: TObject);
begin
SetCellsStyle([svAlign], haRight, 0, cbxFont.Text, []);
end;
procedure TFrm_ysbZjpx_pxjh.actCellCenterAlignExecute(Sender: TObject);
begin
SetCellsStyle([svAlign], haCenter, 0, cbxFont.Text, []);
end;
procedure TFrm_ysbZjpx_pxjh.actDeleteCellsExecute(Sender: TObject);
var
AForm :TFeatureModifyForm;
const
AFormType: array[Boolean] of TcxSSModifyType = (mtDelete, mtInsert);
begin
if IsUpdate then Exit;
AForm := TFeatureModifyForm.Create(Self);
AForm.Top := (Top + Height) shr 1;
AForm.Left := (Left + Width) shr 1;
try
if AForm.Execute(AFormType[TCustomAction(Sender).Tag = 1]) then
with cxSpreadBook.ActiveSheet do
case TCustomAction(Sender).Tag of
0:
DeleteCells(SelectionRect, AForm.Modify);
1:
InsertCells(SelectionRect, AForm.Modify);
end;
finally
AForm.Free;
end;
end;
procedure TFrm_ysbZjpx_pxjh.actInsertCellsExecute(Sender: TObject);
var
AForm :TFeatureModifyForm;
const
AFormType: array[Boolean] of TcxSSModifyType = (mtDelete, mtInsert);
begin
if IsUpdate then Exit;
AForm := TFeatureModifyForm.Create(Self);
AForm.Top := (Top + Height) shr 1;
AForm.Left := (Left + Width) shr 1;
try
if AForm.Execute(AFormType[TCustomAction(Sender).Tag = 1]) then
with cxSpreadBook.ActiveSheet do
case TCustomAction(Sender).Tag of
0:
DeleteCells(SelectionRect, AForm.Modify);
1:
InsertCells(SelectionRect, AForm.Modify);
end;
finally
AForm.Free;
end;
end;
procedure TFrm_ysbZjpx_pxjh.actFormatCellsExecute(Sender: TObject);
begin
with cxSpreadBook.ActiveSheet do
FormatCells(SelectionRect);
end;
procedure TFrm_ysbZjpx_pxjh.actHideCellsExecute(Sender: TObject);
begin
if IsUpdate then Exit;
with cxSpreadBook.ActiveSheet do
SetVisibleState(SelectionRect, True, True, False);
end;
procedure TFrm_ysbZjpx_pxjh.actShowCellsExecute(Sender: TObject);
begin
if IsUpdate then Exit;
with cxSpreadBook.ActiveSheet do
SetVisibleState(SelectionRect, True, True, True);
end;
procedure TFrm_ysbZjpx_pxjh.actHideColExecute(Sender: TObject);
begin
if IsUpdate then Exit;
with cxSpreadBook.ActiveSheet do
SetVisibleState(SelectionRect, True, False, False);
end;
procedure TFrm_ysbZjpx_pxjh.actShowColExecute(Sender: TObject);
begin
if IsUpdate then Exit;
with cxSpreadBook.ActiveSheet do
SetVisibleState(SelectionRect, True, False, True);
end;
procedure TFrm_ysbZjpx_pxjh.actBeveledLookandFeelExecute(Sender: TObject);
begin
if (IsUpdate) then Exit;
TCustomAction(Sender).Checked := not TCustomAction(Sender).Checked;
cxSpreadBook.PainterType := TcxSSPainterType(TCustomAction(Sender).Checked);
end;
procedure TFrm_ysbZjpx_pxjh.actBufferedpaintExecute(Sender: TObject);
begin
if IsUpdate then Exit;
TCustomAction(Sender).Checked := not TCustomAction(Sender).Checked;
cxSpreadBook.BufferedPaint := TCustomAction(Sender).Checked;
end;
procedure TFrm_ysbZjpx_pxjh.actShowcaptionsExecute(Sender: TObject);
begin
if IsUpdate then Exit;
TCustomAction(Sender).Checked := not TCustomAction(Sender).Checked;
cxSpreadBook.ShowCaptionBar := TCustomAction(Sender).Checked;
end;
procedure TFrm_ysbZjpx_pxjh.actShowgridExecute(Sender: TObject);
begin
if IsUpdate then Exit;
TCustomAction(Sender).Checked := not TCustomAction(Sender).Checked;
cxSpreadBook.ShowGrid := TCustomAction(Sender).Checked;
end;
procedure TFrm_ysbZjpx_pxjh.actShowheadersExecute(Sender: TObject);
begin
if IsUpdate then Exit;
TCustomAction(Sender).Checked := not TCustomAction(Sender).Checked;
cxSpreadBook.ShowHeaders := TCustomAction(Sender).Checked;
end;
procedure TFrm_ysbZjpx_pxjh.actShowformulasExecute(Sender: TObject);
begin
if IsUpdate then Exit;
TCustomAction(Sender).Checked := not TCustomAction(Sender).Checked;
cxSpreadBook.ShowFormulas := TCustomAction(Sender).Checked;
end;
procedure TFrm_ysbZjpx_pxjh.actR1C1ReferencestyleExecute(Sender: TObject);
begin
if IsUpdate then Exit;
TCustomAction(Sender).Checked := not TCustomAction(Sender).Checked;
cxSpreadBook.R1C1ReferenceStyle := TCustomAction(Sender).Checked;
pnCellRect.Caption := GetCellText(cxSpreadBook.ActiveSheet.SelectionRect, cxSpreadBook.R1C1ReferenceStyle);
end;
procedure TFrm_ysbZjpx_pxjh.actAutomaticCalcExecute(Sender: TObject);
begin
TCustomAction(Sender).Checked := not TCustomAction(Sender).Checked;
cxSpreadBook.AutoRecalc := TCustomAction(Sender).Checked;
if cxSpreadBook.AutoRecalc then
begin
cxSpreadBook.Recalc;
cxSpreadBook.UpdateControl;
end;
end;
procedure TFrm_ysbZjpx_pxjh.actRecalcFormulasExecute(Sender: TObject);
begin
cxSpreadBook.Recalc();
cxSpreadBook.UpdateControl;
end;
procedure TFrm_ysbZjpx_pxjh.actCutExecute(Sender: TObject);
begin
with cxSpreadBook.ActiveSheet do
Copy(SelectionRect, True);
end;
procedure TFrm_ysbZjpx_pxjh.actCopyExecute(Sender: TObject);
begin
with cxSpreadBook.ActiveSheet do
Copy(SelectionRect, False);
end;
procedure TFrm_ysbZjpx_pxjh.actPasteExecute(Sender: TObject);
begin
with cxSpreadBook.ActiveSheet do
Paste(SelectionRect.TopLeft);
end;
procedure TFrm_ysbZjpx_pxjh.actUndoExecute(Sender: TObject);
begin
cxSpreadBook.History.Undo(1);
end;
procedure TFrm_ysbZjpx_pxjh.actRedoExecute(Sender: TObject);
begin
cxSpreadBook.History.Redo(1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -