unit1.cpp

来自「Advanced Data Import Component Suite for」· C++ 代码 · 共 67 行

CPP
67
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "QImport3"
#pragma link "QImport3XLS"
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString arCountry[5][18];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  QImportXLS1->FileName = ExtractFilePath(Application->ExeName) + "..\\..\\..\\data\\country.xls";
  StringGrid1->Cells[0][0] = "Name";
  StringGrid1->Cells[1][0] = "Capital";
  StringGrid1->Cells[2][0] = "Continent";
  StringGrid1->Cells[3][0] = "Area";
  StringGrid1->Cells[4][0] = "Population";

  StringGrid1->ColWidths[0] = 125;
  StringGrid1->ColWidths[1] = 70;
  StringGrid1->ColWidths[2] = 80;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::QImportXLS1BeforeImport(TObject *Sender)
{
  for (int i = 0; i <= 4; i++)
    for (int j = 0; j <= 17; j++)
      arCountry[i][j] = EmptyStr;
  FCounter = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::QImportXLS1UserDefinedImport(TObject *Sender,
  TQImportRow *Row)
{
  for (int i = 0; i <= Row->Count - 1; i++)
    arCountry[i][FCounter] = Row->Items[i]->Value;
  FCounter++;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  QImportXLS1->Execute();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
  for (int i = 0; i <= 4; i++)
    for (int j = 1; j <= 18; j++)
      StringGrid1->Cells[i][j] = EmptyStr;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::QImportXLS1AfterImport(TObject *Sender)
{
  for (int i = 0; i <= 4; i++)
    for (int j = 0; j <= 17; j++)
      StringGrid1->Cells[i][j + 1] = arCountry[i][j];
}

⌨️ 快捷键说明

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