求高手相助:在Delphi中怎么按照Excel某个单元格的别名访问值,我在Excel中录的宏怎么在Delphi中不能用

hcj2002 2007-04-04 10:03:39
VBA代码:
activeworkbook.Names("tt").RefersToRange.Value = 100

怎么转换为Delphi代码,谢谢!
...全文
333 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yi10000 2007-04-05
  • 打赏
  • 举报
回复
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;
xiaocai800322 2007-04-05
  • 打赏
  • 举报
回复
关注
IDWB 2007-04-04
  • 打赏
  • 举报
回复
我的代码不知道对你有没有用
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;

16,747

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧