VBA代码:
activeworkbook.Names("tt").RefersToRange.Value = 100怎么转换为Delphi代码,谢谢!

解决方案 »

  1.   

    我的代码不知道对你有没有用
    procedure Ttcjl.dcClick(Sender: TObject);
    var ExcelApp: Variant;
    begin
    if DBGrid1.DataSource.DataSet.IsEmpty then
    begin
     showmessage('没有数据可以导出!');
     exit;
    end;
    ExcelApp := CreateOleObject( 'Excel.Application' );
    ExcelApp.Visible := True;
    ExcelApp.WorkBooks.Add(1);
    ExcelApp.Workbooks[1].WorkSheets[1].Name := 'sheet页的名称';
    exlDC(ExcelApp);
    end;procedure Ttcjl.exlDC(XLApp: Variant);
    var
      x,i: Integer;
      ExcelSheet: Variant;
    begin
      ExcelSheet := XLApp.Workbooks[1].WorkSheets[1];
      for i:=1 to DBGrid1.Columns.Count do
       with DBGrid1.Columns[i-1] do
       begin
        ExcelSheet.Columns[i].ColumnWidth:=DBGrid1.DataSource.DataSet.FindField(FieldName).DisplayWidth;
        ExcelSheet.Cells(3, i):=Title.Caption;
       end;
        ExcelSheet.Cells(1, 2):='第1行第2格的内容';
        ExcelSheet.Cells(2, 2):= '第2行第2格的内容';
      x:= 4;
      with DBgrid1.DataSource.DataSet do
      begin
       first;
       While Not EOF do
        begin
         for i:=1 to DBGrid1.Columns.Count do
          with DBGrid1.Columns[i-1] do
           begin
            ExcelSheet.Cells(x, i):=''''+FindField(FieldName).AsString;
           end;
          Next;
          x:= x + 1 ;
        end;
      end;
      ExcelSheet.Cells(x, 1):= '合计';
      ExcelSheet.Cells(x, 2):= '共'+'条记录';
      ExcelSheet.Cells(x, 3):= '用户数量:';
      ExcelSheet.Cells(x, 5):= '设备数量:';
      x:=x+1;
      ExcelSheet.Cells(x, 4):= '统计人:'+ CZYxm;
      ExcelSheet.Cells(x, 6):= '统计时间'+DateToStr(now);end;
      

  2.   

    Var
    Aname : Excel2000.Name; 
    begin
    ……
    Aname := wkBook.Names.Add('通讯录','=Sheet1!$A$3:$D$7',EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam); 
    Aname.RefersToRange.Value=100;