⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 featuresdemomain.cpp

📁 DevExpress公司出品的Borland Delphi和C++ Builder的控件(包含完整源代码)。 ExpressSpreadSheet:交叉数据表格控件。 一款Delphi
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        for (j = tp; j <= bt; j++) {
          CellObject = ActiveSpreadSheet->GetCellObject(i, j);
          try {
              AStyle = CellObject->Style->Font->Style;
              if (AValuesSet.Contains(svFontName))
                CellObject->Style->Font->Name = AFontName;
              if (AValuesSet.Contains(svSize))
                CellObject->Style->Font->Size = AFontSize;
              if (AValuesSet.Contains(svAlign))
                CellObject->Style->HorzTextAlign = AAlign;
              SetValue(AValuesSet, AStyles, svBold, fsBold, &AStyle);
              SetValue(AValuesSet, AStyles, svItalic, fsItalic, &AStyle);
              SetValue(AValuesSet, AStyles, svUnderline, fsUnderline, &AStyle);
              SetValue(AValuesSet, AStyles, svStrikeOut, fsStrikeOut, &AStyle);
              CellObject->Style->Font->Style = AStyle;
            }
          __finally {
          delete CellObject;
          }
        }
  }
  __finally
  {
    SheetBook->EndUpdate();
    SheetBook->UpdateControl();
  }
}

void __fastcall TFeaturesMainForm::actCellLeftAlignExecute(TObject *Sender)
{
  SetCellsStyle(TStyleValues() << svAlign, haLEFT, 0, cbxFont->Text, TFontStyles());
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actCellRightAlignExecute(TObject *Sender)
{
  SetCellsStyle(TStyleValues() << svAlign, haRIGHT, 0, cbxFont->Text, TFontStyles());
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actBoldExecute(TObject *Sender)
{
  if (tbBold->Down){
    SetCellsStyle(TStyleValues() << svBold, haGENERAL, 0, "", TFontStyles() << fsBold);
  }
  else
    SetCellsStyle(TStyleValues() << svBold, haGENERAL, 0, "", TFontStyles());
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actFontSizeExecute(TObject *Sender)
{
  int ASize;
  if (Cxssutils::cxTryStrToInt(cbxSize->Text, ASize)) 
    SetCellsStyle(TStyleValues() << svSize, haGENERAL, ASize, cbxFont->Text, TFontStyles());
}

void __fastcall TFeaturesMainForm::actCellCenterAlignExecute(TObject *Sender)
{
  SetCellsStyle(TStyleValues() << svAlign, haCENTER, 0, cbxFont->Text, TFontStyles());
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actMergeCellsExecute(TObject *Sender)
{
  ActiveSpreadSheet->SetMergedState(ActiveSpreadSheet->SelectionRect, true);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actSplitCellsExecute(TObject *Sender)
{
  ActiveSpreadSheet->SetMergedState(ActiveSpreadSheet->SelectionRect, false);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::CalculateSummary(int AType)
{
  String S;
  TRect ARect;
  String AFunc[5] = {"Sum", "Average", "Count", "Max", "Min"};
  try {
    ARect = SheetBook->SelectionRect;
    S = SheetBook->CellsNameByRef(SheetBook->ActivePage, ARect, false);
    TcxSSCellObject *CellObject = ActiveSpreadSheet->GetCellObject(ARect.Right, ARect.Bottom + 1);
    try {
      CellObject->Text = "=" + AFunc[AType] + "(" + S + ")";
    }
    __finally {
      delete CellObject;
     }
  }
  __finally {
    SheetBook->UpdateControl();
    }
}

void __fastcall TFeaturesMainForm::actSummaryExecute(TObject *Sender)
{
  CalculateSummary(((TComponent*)Sender)->Tag);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actRowExecute(TObject *Sender)
{
   ActiveSpreadSheet->InsertCells(ActiveSpreadSheet->SelectionRect, msAllRow);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actColumnExecute(TObject *Sender)
{
   ActiveSpreadSheet->InsertCells(ActiveSpreadSheet->SelectionRect, msAllCol);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actSheetExecute(TObject *Sender)
{
  SheetBook->PageCount++;
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actFontExecute(TObject *Sender)
{
  SetCellsStyle(TStyleValues() << svFontName, haGENERAL, 0, cbxFont->Text, TFontStyles());
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actSortAscendingExecute(TObject *Sender)
{
  TcxSortType *SortType;
  SortType = new TcxSortType;
  *SortType = Cxsstypes::stAscending;
  if (((TComponent*)Sender)->Tag)
    *SortType = Cxsstypes::stDescending;
  try{
    ActiveSpreadSheet->Sort(ActiveSpreadSheet->SelectionRect, SortType, 0);
  }
  __finally {
    delete SortType;
  }
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actStrikeOutExecute(TObject *Sender)
{
  if (tbStrikeOut->Down){
    SetCellsStyle(TStyleValues() << svStrikeOut, haGENERAL, 0, "", TFontStyles() << fsStrikeOut);
  }
  else
    SetCellsStyle(TStyleValues() << svStrikeOut, haGENERAL, 0, "", TFontStyles());
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actUnderlineExecute(TObject *Sender)
{
  if (tbUnderline->Down){
    SetCellsStyle(TStyleValues() << svUnderline, haGENERAL, 0, "", TFontStyles() << fsUnderline);
  }
  else
    SetCellsStyle(TStyleValues() << svUnderline, haGENERAL, 0, "", TFontStyles());
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actItalicExecute(TObject *Sender)
{
  if (tbItalic->Down){
    SetCellsStyle(TStyleValues() << svItalic, haGENERAL, 0, "", TFontStyles() << fsItalic);
  }
  else
    SetCellsStyle(TStyleValues() << svItalic, haGENERAL, 0, "", TFontStyles());
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actShowRowExecute(TObject *Sender)
{
  if (IsUpdate) return;
  ActiveSpreadSheet->SetVisibleState(ActiveSpreadSheet->SelectionRect, false, true, true);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actHideRowExecute(TObject *Sender)
{
  if (IsUpdate) return;
  ActiveSpreadSheet->SetVisibleState(ActiveSpreadSheet->SelectionRect, false, true, false);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actHideColExecute(TObject *Sender)
{
  if (IsUpdate) return;
  ActiveSpreadSheet->SetVisibleState(ActiveSpreadSheet->SelectionRect, true, false, false);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actShowColExecute(TObject *Sender)
{
  if (IsUpdate) return;
  ActiveSpreadSheet->SetVisibleState(ActiveSpreadSheet->SelectionRect, true, false, true);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actFormatCellsExecute(TObject *Sender)
{
  if (IsUpdate) return;
  ActiveSpreadSheet->FormatCells(ActiveSpreadSheet->SelectionRect);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actHideCellsExecute(TObject *Sender)
{
  if (IsUpdate) return;
  ActiveSpreadSheet->SetVisibleState(ActiveSpreadSheet->SelectionRect, true, true, false);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actShowCellsExecute(TObject *Sender)
{
  if (IsUpdate) return;
  ActiveSpreadSheet->SetVisibleState(ActiveSpreadSheet->SelectionRect, true, true, true);
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::actCellsExecute(TObject *Sender)
{
  TFeatureModifyForm *Modify;
  Modify = new TFeatureModifyForm(this);
     try {
      div_t sHeight, mHeight, sWidth, mWidth;
      sHeight = div(SheetBook->Height, 2);
      mHeight = div(Modify->Height, 2);
      Modify->Top = (SheetBook->Top + sHeight.quot) + mHeight.quot;

      sWidth = div(SheetBook->Width, 2);
      mWidth = div(Modify->Width, 2);
      Modify->Left = (SheetBook->Left + sWidth.quot) + mWidth.quot;
      TcxSSModifyType ModifyType = mtDelete;
      if (((TComponent*)Sender)->Tag)
        ModifyType = mtInsert;
       if (Modify->Execute(ModifyType))
         if (ModifyType == mtInsert)
           ActiveSpreadSheet->InsertCells(ActiveSpreadSheet->SelectionRect, Modify->Modify);
          else
            ActiveSpreadSheet->DeleteCells(ActiveSpreadSheet->SelectionRect, Modify->Modify);
     }
     __finally {
       Modify->Free();
     }
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::actOpenSpreadSheetExecute(TObject *Sender)
{
  if (OpenDialog->Execute())
  {
    NewSheet(OpenDialog->FileName);
    try {
      try {
        SheetBook->LoadFromFile(OpenDialog->FileName);
      }
      catch (Exception &err) {
        Application->ShowException(&err);
        ActiveMDIChild->Close();
      }
    }
    __finally {
      actShowgrid->Checked = SheetBook->ShowGrid;
    }
  }
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::actSaveSpeadSheetExecute(TObject *Sender)
{
  String AFileName;
  if (SaveDialog->Execute())
  {
    AFileName = ChangeFileExt(SaveDialog->FileName, ".xls");
    SheetBook->SaveToFile(AFileName);
    ActiveMDIChild->Caption = ExtractFileName(AFileName);
  }
}

void __fastcall TFeaturesMainForm::edtCellEditKeyPress(TObject *Sender, char &Key)
{
  if (Key == 13)
  {
    _WINUSER_::SetFocus(SheetBook->Handle);
    edtCellEditExit(Sender);
  }
}
//---------------------------------------------------------------------------

void __fastcall TFeaturesMainForm::SetHorzStyle(TRect ARect, int ARow, TcxSSEdgeLineStyle AStyle)
{
  if (AStyle != lsNone)
  {
    for(int i = ARect.Left; i <= ARect.Right; i++)
    {
      TcxSSCellObject *CellObject = ActiveSpreadSheet->GetCellObject(i, ARow);
      try {
        CellObject->Style->Borders->Edges[eTop]->Style = AStyle;
      }
    __finally {
        delete CellObject;
      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -