DELPHI 界面及操作小技巧

1、SHOW出来的窗口按ALT后会切换到主窗口,原因应该是按ALT时调用了主窗口的WINDOWS功能的菜单
解决方案一:主窗口的borderstyle 修改为 bsnone。
解决方案二:将SHOW出来的窗口的父窗口设置为一个PANLE等控件
2、listview记录多时的记录定位
 

for i := 0 to ListView3.Items.Count - 1 do
  begin
    if ListView3.Items.Item[i].SubItems[0] = edit1.Text then
    begin
      ListView3.Items.Item[i].Focused:=true;
      ListView3.Items.Item[i].Selected := true;
      ListView3.Items.Item[i].MakeVisible(false);
    end;
  end;

3、导入EXCEL到LISTVIEW
 

function exceltolist(ttname: string; var tt: TListView;start_num:Integer;end_num:integer{读取前几行}):string;
var
  i, j: Integer;
  exlApp: oleVariant;
  iRowCount: integer;
  iColCount: integer;
begin
  exlApp := CreateOleObject('Excel.Application');
  exlApp.Visible := False;
  exlApp.WorkBooks.Open(ttname);
  iRowCount := exlApp.ActiveSheet.UsedRange.Rows.Count;
  iColCount := exlApp.ActiveSheet.UsedRange.Columns.Count;
  for i := 1 to iRowCount do
  begin
    with tt.Items.Add do
    begin
      if start_num>0 then
      begin
        //不写caption,所以先默认一个
        Caption:='';
      end;
      for j := 1 to end_num do
      begin
        if start_num=0 then
        begin
          //重头写
          if j=1 then
          begin
            Caption := exlApp.workbooks[1].sheets[1].cells[i+1, j];
          end
          else
          begin
            SubItems.Add(exlApp.workbooks[1].sheets[1].cells[i+1, j]);
          end;
        end
        else
        begin
          //继续写
          SubItems.Add(exlApp.workbooks[1].sheets[1].cells[i+1, j]);
        end;
        //ShowMessage(exlApp.workbooks[1].sheets[1].cells[i, j]);
      end;
      //临时写的。真没有时间和心情作了。
      SubItems.Add('未确认');
      SubItems.Add('本次增加');
      SubItems.Add('生效');
    end;

  end;
  exlApp := fgUnassigned;

end;

4、导出EXCEL到LISTVEIW
 

function listtoexcel(ttname: string; tt: TListView): string;
var
  h, k, i: integer;
  Excelid: oleVariant;
  Y, X: integer;
  Temsheet: oleVariant; // 工作薄
  FWorkBook: oleVariant; // 工作表
  strFormat: oleVariant;
begin
  try
    Excelid := CreateOleObject('Excel.Application');
  except
    Application.MessageBox('Excel没有安装!', '提示信息', mb_OK + MB_ICONASTERISK +
      MB_DEFBUTTON1 + MB_APPLMODAL);
    Exit;
  end;
  try
    k := tt.Items.Count;
    h := tt.Columns.Count;
    Excelid.Visible := False; // 是否显示
    strFormat := '@';
    FWorkBook := Excelid.WorkBooks.Add(-4167); // 新的工作表
    FWorkBook.sheets[1].name := '提取会员信息';
    FWorkBook.sheets[1].Columns[5].ColumnWidth := 15; // 设置列宽度
    FWorkBook.sheets[1].Columns[6].ColumnWidth := 15; // 设置列宽度
    // 写表头,以LISTVIEWS列名为准
    for i := 0 to h - 1 do
    begin
      Excelid.WorkSheets[1].Cells[1, i + 1].Value :=
        tt.Columns.Items[i].Caption;

    end;
    for X := 2 to k + 1 do
    begin
      Excelid.Cells.item[X, 1].numberformatlocal := strFormat;
      Excelid.WorkSheets[1].Cells[X, 1].Value := tt.Items.item[X - 2].Caption;
      for Y := 2 to h do
      begin
        Excelid.WorkSheets[1].Cells[X, Y].Value := tt.Items.item[X - 2]
          .SubItems[Y - 2];
      end;
    end;
  except

  end;
  Excelid.Visible := True; // 是否显示
  Excelid := fgUnassigned;
end;

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值