如何设置excel标题栏,50分(50分)

  • 主题发起人 wydelphi
  • 开始时间
W

wydelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
程序中用excelapplication生成一个excel文件,尚未保存,想在excel窗口的标题栏显示
一个自定义的默认文件名,如何实现?
 
更改 Excel 标题栏:
excelapplication.Caption := '应用程序调用 Microsoft Excel';
 
不行,同时要生成三个excel文件,标题栏分别显示不同的内容
 
你是说要生成三个表格,还是说上面的方法会生成三个表格?
 
我要生成三个新的excel文件,为了区别它们,每个要显示不同的标题栏
 
等着,我下午去公司看,现在机器上没有装DELPHI!
 
procedure TForm2.Button1Click(Sender: TObject);
var v,sheet,range :eek:levariant ;
j:integer ;
begin
with mydata.qyblack do
begin
close ;
sql.Clear ;
sql.Add('select * from blacktb where w_ddate>='+#39+edit1.text+#39+' and w_ddate<='+#39+edit2.text+#39);
open ;
end;
if mydata.qyblack.RecordCount=0 then
begin
showmessage('is not data!');
exit ;
end;
v :=createoleobject('excel.application');
v.workbooks.add ;
v.workbooks[1].worksheets[1].name :='aaa';
sheet:=v.workbooks[1].worksheets[1];
v.visible :=true;
range:=sheet.range['A1:H1'];
range.merge ;
range.formular1c1:=' ('+datetostr(datetimepicker1.Date)+'至'+datetostr(datetimepicker2.Date)+')開除工人名單';
sheet.cells[3,1]:='身份証編號';
sheet.cells[3,2]:='名 稱';
sheet.cells[3,3]:='省 份';
sheet.cells[3,4]:='地 址';
sheet.cells[3,5]:='入廠日期';
sheet.cells[3,6]:='離廠日期';
sheet.cells[3,7]:='原因';
sheet.cells[3,8]:='原所在廠';
mydata.qyblack.First ;
j:=3 ;
while not mydata.qyblack.Eof do
begin
j:=j+1 ;
sheet.cells[j,1].numberformatlocal :='@';
sheet.cells[j,1]:=mydata.qyblack.FieldByName('w_id').AsString ;
sheet.cells[j,2]:=mydata.qyblack.FieldByName('w_cname').AsString ;
sheet.cells[j,3]:=mydata.qyblack.FieldByName('w_nation').AsString ;
sheet.cells[j,4]:=mydata.qyblack.FieldByName('w_addr').AsString ;
sheet.cells[j,5]:=mydata.qyblack.FieldByName('w_cdate').AsString ;
sheet.cells[j,6]:=mydata.qyblack.FieldByName('w_ddate').AsString ;
sheet.cells[j,7]:=mydata.qyblack.FieldByName('w_reason').AsString ;
sheet.cells[j,8]:=mydata.qyblack.fieldbyname('w_factory').AsString ;
mydata.qyblack.Next ;
if mydata.qyblack.Eof then break ;
end;
sheet.cells.entirecolumn.autofit ;
// v.selection.entirecolumn.atutofit ;
// v.displayalerts :=false ;
sheet.printpreview ;
end;
我才寫的,給你個參考吧,希望可以幫你
 
谢了,但是没用
 
procedure Tcountsql.Button2Click(Sender: TObject);
var

xlapp,MyworkBook:variant;
Tempstr:string;
begin
try
xlapp:=createoleobject('excel.application');
MyworkBook:=CreateOleobject('Excel.Sheet');
xlapp.visible:=true;

xlapp.application.caption:=datetostr(date)+'传报统计表';//这里是给EXCEL的标题
//xlapp.workbooks.add(xlwbatworksheet);
MyworkBook:=xlapp.workBooks.Add; //增加一个新表,如果需要多个表再加几次,然后下面的改为2,3……就行了!
MyworkBook.worksheets[1].name:='传报统计表';//这里就是给一个报表取标题


except
messagedlg('请检查Excel是否正确安装!',mterror,[mbok],0);




 
是要给多个workbook不同的标题
 
我现在机器上没有装DELPHI,没法测试,我想三个表格都生成了,其实至于是BOOKI还是SHEET
应该没什么大的区别,我不知道你测试了没有,是否三个表格有了不同的标题?
 
顶部