从EXCEL导入cxGrid旧版本部分测试代码存档

以前旧版本测试数据的代码

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, XLSSheetData5, XLSReadWriteII5, Xc12Utils5,
  Vcl.Grids, Vcl.StdCtrls, cxGraphics, cxControls, cxLookAndFeels, cxGridExportLink,
  cxLookAndFeelPainters, cxStyles, cxCustomData, cxFilter, cxData, MyMsgBox,
  cxDataStorage, cxEdit, cxNavigator, Data.DB, cxDBData, cxGridLevel, cxClasses,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, MemDS, DBAccess, Uni;

type
  TForm1 = class(TForm)
    XLSReadWrite: TXLSReadWriteII5;
    btnImport: TButton;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    dlgSave1: TSaveDialog;
    btnExport: TButton;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGridDBColumnGrid1DBTableView1Column1: TcxGridDBColumn;
    cxGridDBColumnGrid1DBTableView1Column2: TcxGridDBColumn;
    cxGridDBColumnGrid1DBTableView1Column3: TcxGridDBColumn;
    unids1: TUniDataSource;
    uniqry1: TUniQuery;
    btn1: TButton;
    uniqry2: TUniQuery;
    btn2: TButton;
    btn3: TButton;
    btn4: TButton;
    procedure btnImportClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnExportClick(Sender: TObject);
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure btn3Click(Sender: TObject);
    procedure btn4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses UnitDevExpressVCLCustom, UnitUniDAC;

procedure TForm1.btnImportClick(Sender: TObject);
var
  iColIndex, iRowIndex: integer;
begin
  XLSReadWrite.Filename := 'F:\Import.xlsx';
  XLSReadWrite.Read; //此行不能省,否则读取不到数据
  cxGrid1DBTableView1.BeginUpdate;
  try
    with cxGrid1DBTableView1.DataController, XLSReadWrite.Sheets[0] do
      begin
        RecordCount := LastRow - FirstRow;//必须先定义cxGrid1DBTableView1的行数,否则看不到数据
        for iColIndex := FirstCol to LastCol do
          begin
            for iRowIndex := FirstRow to LastRow do
              if iRowIndex <> LastRow then
                begin
                  cxGrid1DBTableView1.Columns[iColIndex].DataBinding.ValueTypeClass := TcxStringValueType;//定义数据类型放在赋值前面,否则看不到数据
                  Values[iRowIndex, iColIndex] := AsFmtString[iColIndex, iRowIndex + 1];  
                end;
//            ShowMessage('获得Excel表的数据:' + IntToStr(iColIndex));
          end;
        for iColIndex := FirstCol to LastCol do //解决CXGRID导入EXCEL首行不显示的BUG
          begin
	    cxGrid1DBTableView1.Columns[iColIndex].DataBinding.ValueTypeClass := TcxStringValueType;//定义数据类型放在赋值前面,否则看不到数据	
            Values[0, iColIndex] := AsFmtString[iColIndex, 1];
            cxGrid1DBTableView1.Columns[iColIndex].Caption := '名称';
          end;
      end;
  finally
    cxGrid1DBTableView1.EndUpdate;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  MyCxGrid: TMyCxGrid;
begin
  MyCxGrid := TMyCxGrid.Create(nil);
  MyCxGrid.IniMyCxGrid(cxGrid1DBTableView1);
end;

end.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值