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

📄 stocksmain.cpp

📁 DevExpress公司出品的Borland Delphi和C++ Builder的控件(包含完整源代码)。 ExpressSpreadSheet:交叉数据表格控件。 一款Delphi
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    cxSpreadBook->ActivePage = 0;                           // ensure we are looking at the first page
    // Firstly by setting the column widths
    CHeader = cxSpreadBook->ActiveSheet->Cols;
    CHeader->Size[0] = 140;
    for(int i = 1; i <= 8; i++)
      CHeader->Size[i] =  80;
    // and then the Row heights for the title and column descriptors
    RHeader = cxSpreadBook->ActiveSheet->Rows;
    RHeader->Size[0] =  30;
    RHeader->Size[2] =  30;
    // and how about some cell formatting
    // setting the title and column header fonts

    SetCellFont(0, 0, 0, 0, TFontStyles() << fsBold << fsUnderline, 12);
    // and now adding some cell shading
    // for the sheet title
    SetCellPattern(0, 0, 8, 1, 16, 1, fsSolid);
   // for the column headers
    SetCellPattern(0, 2, 8, 2, 23, 1, fsSolid);
    // and the company names
    SetCellPattern(0, 2, 0, FCurRow - 2, 23, 1, fsSolid);
    // and now some number formatting
    SetCellFormat(1,3,1,FCurRow-1, 3);                      // Holding Column #,##0
    SetCellFormat(2,3,2,FCurRow-1,15);                      //  Date Purchased d-mmm-yy
    SetCellFormat(3,3,6,FCurRow-1, 4);                      //  Price/Cost/Value & Worth Column #,##0.00
    SetCellFormat(7,3,7,FCurRow-1, 8);                      //  Gain/(Loss) value (#,##0.00_);[Red](#,##0.00)
    SetCellFormat(8,3,8,FCurRow-1,10);                      //  Gain/(Loss) percentage 0.00%
    // and now for the totals
    SetCellFormat(4,FCurRow,4,FCurRow, 8);                  //  Total Purchase Cost ($#,##0.00_);[Red]($#,##0.00)
    SetCellFormat(6,FCurRow,7,FCurRow, 8);                  //  Total Current Valuation ($#,##0.00_);[Red]($#,##0.00)
    SetCellFormat(8,FCurRow,8,FCurRow,10);                  //  Total Gain/(Loss) percentage 0.00%
    // now lets align all the data
    SetCellAlignment(1,3,8,FCurRow, haRIGHT, vaCENTER);     // Right Align all the numeric fields
    // and how about some borders for the totals
    SetCellBorders(4, FCurRow, 4, FCurRow, 1, lsThin);      // thin single line at the top of the cell
    SetCellBorders(6, FCurRow, 6, FCurRow, 1, lsThin);
    SetCellBorders(7, FCurRow, 7, FCurRow, 1, lsThin);
    SetCellBorders(4, FCurRow, 4, FCurRow, 3, lsDouble);    // double line at the bottom of the cell
    SetCellBorders(6, FCurRow, 6, FCurRow, 3, lsDouble);    // double line at the bottom of the cell
    SetCellBorders(7, FCurRow, 7, FCurRow, 3, lsDouble);    // double line at the bottom of the cell

    // and now a similar process for the Hi/Lo valuations page
    cxSpreadBook->ActivePage = 1;                           // ensure we are looking at the second page
    // Firstly by setting the column widths
    CHeader = cxSpreadBook->ActiveSheet->Cols;
    CHeader->Size[0] = 140;
    for(int i = 1; i<=4; i++) CHeader->Size[i] =  80;
    // and then the Row heights for the title and column descriptors
    RHeader = cxSpreadBook->ActiveSheet->Rows;
    RHeader->Size[0] =  30;
    RHeader->Size[2] =  30;
    // and how about some cell formatting
    // setting the title and column header fonts
    SetCellFont(0, 0, 0, 0, TFontStyles() << fsBold << fsUnderline, 12);
    // and now adding some cell shading
    // for the sheet title
    SetCellPattern(0, 0, 4, 1, 16, 1, fsSolid);
    // for the column headers
    SetCellPattern(0, 2, 4, 2, 23, 1, fsSolid);
    // and the company names
    SetCellPattern(0, 2, 0, FCurRow - 2, 23, 1, fsSolid);
    // and now some number formatting
    SetCellFormat(1, 3, 4, FCurRow - 1, 4);                 //  Current, Hi, Lo and Average #,##0.00
      // now lets align all the data
    SetCellAlignment(1, 3, 4, FCurRow, haRIGHT, vaCENTER);  // Right Align all the numeric fields

    FIsSaveSpreadSheet = true;                              // enable the save spreadsheet button
  }
  __finally {
    cxSpreadBook->ActivePage = 0;                           // and back to the first page
    cxSpreadBook->EndUpdate();
    Screen->Cursor = CurCursor;                             // and reset cursor
  }
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actApplyFormattingUpdate(TObject *Sender)
{
  ((TCustomAction*)Sender)->Enabled = FIsApplyFormatting;
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::cxSpreadBookSheetPopupMenu(
      TObject *Sender, int X, int Y)
{
  pmSheetPopup->Popup(X, Y);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::edtCellEditChange(TObject *Sender)
{
  if (FIsUpdate) return;
  TcxSSCellObject *CellObject = cxSpreadBook->ActiveSheet->GetCellObject(cxSpreadBook->ActiveSheet->SelectionRect.Left,
    cxSpreadBook->ActiveSheet->SelectionRect.Top);
  try {
    CellObject->SetCellText(((TEdit*)Sender)->Text, false);
  }
  __finally {
    delete CellObject;
  }
  cxSpreadBook->UpdateControl();
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::edtCellEditExit(TObject *Sender)
{
  TcxSSCellObject *CellObject = cxSpreadBook->ActiveSheet->GetCellObject(cxSpreadBook->ActiveSheet->SelectionRect.Left,
    cxSpreadBook->ActiveSheet->SelectionRect.Top);
  try {
    CellObject->Text = CellObject->Text;
  }
  __finally {
    delete CellObject;
  }
  cxSpreadBook->UpdateControl();
  cxSpreadBook->SetFocus();
  cxSpreadBookSetSelection(this, cxSpreadBook->ActiveSheet);
}
//---------------------------------------------------------------------------

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

void __fastcall TStocksMainForm::actCutExecute(TObject *Sender)
{
  TRect rec;
  rec = cxSpreadBook->SelectionRect;
  cxSpreadBook->ActiveSheet->Copy(rec, true);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actCopyExecute(TObject *Sender)
{
  TRect rec;
  rec = cxSpreadBook->ActiveSheet->SelectionRect;
  cxSpreadBook->ActiveSheet->Copy(rec, false);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actPasteExecute(TObject *Sender)
{
  TRect rec;
  rec = cxSpreadBook->SelectionRect;
  cxSpreadBook->ActiveSheet->Paste(Point(rec.left, rec.top));
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::FormCreate(TObject *Sender)
{
  FIsApplyFormatting = false;
  FIsSaveSpreadSheet = false;
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actSaveSpeadSheetUpdate(TObject *Sender)
{
  ((TCustomAction*)Sender)->Enabled = FIsSaveSpreadSheet;
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actCellsExecute(TObject *Sender)
{
  TStocksModifyForm *Modify;
  Modify = new TStocksModifyForm(this);
     try {
      div_t sHeight, mHeight, sWidth, mWidth;

      sHeight = div(cxSpreadBook->Height, 2);
      mHeight = div(cxSpreadBook->Height, 2);
      Modify->Top = (cxSpreadBook->Top + sHeight.quot) + mHeight.quot;

      sWidth = div(cxSpreadBook->Width, 2);
      mWidth = div(Modify->Width, 2);
      Modify->Left = (cxSpreadBook->Left + sWidth.quot) + mWidth.quot;
      TcxSSModifyType ModifyType = mtDelete;
      if (((TComponent*)Sender)->Tag)
        ModifyType = mtInsert;
       if (Modify->Execute(ModifyType))
         if (ModifyType == mtInsert)
           cxSpreadBook->ActiveSheet->InsertCells(cxSpreadBook->ActiveSheet->SelectionRect, Modify->Modify);
          else
            cxSpreadBook->ActiveSheet->DeleteCells(cxSpreadBook->ActiveSheet->SelectionRect, Modify->Modify);
     }
     __finally {
       Modify->Free();
     }
}
//---------------------------------------------------------------------------


void __fastcall TStocksMainForm::actFormatCellsExecute(TObject *Sender)
{
  if (FIsUpdate) return;
  cxSpreadBook->ActiveSheet->FormatCells(cxSpreadBook->ActiveSheet->SelectionRect);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actHideCellsExecute(TObject *Sender)
{
  if (FIsUpdate) return;
  cxSpreadBook->ActiveSheet->SetVisibleState(cxSpreadBook->ActiveSheet->SelectionRect, true, true, false);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actShowCellsExecute(TObject *Sender)
{
  if (FIsUpdate) return;
  cxSpreadBook->ActiveSheet->SetVisibleState(cxSpreadBook->ActiveSheet->SelectionRect, true, true, true);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actHideColExecute(TObject *Sender)
{
  if (FIsUpdate) return;
  cxSpreadBook->ActiveSheet->SetVisibleState(cxSpreadBook->ActiveSheet->SelectionRect, true, false, false);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actShowColExecute(TObject *Sender)
{
  if (FIsUpdate) return;
  cxSpreadBook->ActiveSheet->SetVisibleState(cxSpreadBook->ActiveSheet->SelectionRect, true, false, false);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actHideRowExecute(TObject *Sender)
{
  if (FIsUpdate) return;
  cxSpreadBook->ActiveSheet->SetVisibleState(cxSpreadBook->ActiveSheet->SelectionRect, false, true, false);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actShowRowExecute(TObject *Sender)
{
  if (FIsUpdate) return;
  cxSpreadBook->ActiveSheet->SetVisibleState(cxSpreadBook->ActiveSheet->SelectionRect, false, true, true);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actExitExecute(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actSaveSpeadSheetExecute(TObject *Sender)
{
  String AFileName;
  if (SaveDialog->Execute())
  {
    AFileName = ChangeFileExt(SaveDialog->FileName, ".xls");
    cxSpreadBook->SaveToFile(AFileName);
    ActiveMDIChild->Caption = ExtractFileName(AFileName);
  }
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actMergeCellsExecute(TObject *Sender)
{
  cxSpreadBook->ActiveSheet->SetMergedState(cxSpreadBook->ActiveSheet->SelectionRect, true);
}
//---------------------------------------------------------------------------

void __fastcall TStocksMainForm::actSplitCellsExecute(TObject *Sender)
{
  cxSpreadBook->ActiveSheet->SetMergedState(cxSpreadBook->ActiveSheet->SelectionRect, false);
}
//---------------------------------------------------------------------------
 

⌨️ 快捷键说明

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