procedure TForm1.Button1Click(Sender: TObject); var Filename:String; begin opendialog1.filter:='所有文件(*.*)|*.*'; Opendialog1.InitialDir:=extractfilepath(application.exename); if Opendialog1.Execute then begin FileName:=OpenDialog1.FileName; OleContainer1.CreateObjectFromFile(FileName,False); OleContainer1.Run; end; end;你试试这个。可以单独再打开窗体啊.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Comobj,Excel2000, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
ExcelApp:Variant; implementation{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
chexingshu:integer;
Excelx1:string;
Excelx2:string;
xl,Cell1: olevariant;
Sum:integer;
begin
ExcelApp := CreateOleObject( 'Excel.Application' );
ExcelApp.Caption := '昆明理工大学学生素质综合测评表打印';
ExcelApp.WorkBooks.Add;
ExcelApp.WorkSheets[1].Activate;
ExcelApp.Visible := True;
ExcelApp.ActiveWindow.Zoom := 75;
chexingshu:=24;
excelx2:='a1';
ExcelApp.Cells[1,1].Value :='昆明理工大学学生素质综合测评表';
ExcelApp.cells.Item[1, 1].font.size := 26;
ExcelApp.cells.Item[1, 1].RowHeight := 50;
ExcelApp.cells.Item[1 , 1].Font.Bold := True;
ExcelApp.cells.Item[1, 1].HorizontalAlignment := xlCenter;
ExcelApp.cells.Item[1, 1].font.Name := '黑体';
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ExcelApp.ActiveWorkbook.SaveAs('c:\1k1.xls');
end;end.
OleContainer1.DoVerb(ovSHOW);
xlapp:=OleContainer1.OleObject.Application;
sheet := xlApp.WorkBooks[1].WorkSheets[1];
Sheet.Cells[1, 1] := '型号';
Sheet.Cells[1, 2] := '厂家';
Sheet.Cells[1, 3] := '批号';
Sheet.Cells[1, 4] := '描述';
Sheet.Cells[1, 5] := '封装';
Sheet.Cells[1, 6] := '数量';
Sheet.Cells[1, 7] := '进价';
Sheet.Cells[1, 8] := '询价人';
Sheet.Cells[1, 9] := '询价日期';
Sheet.Cells[1, 10] := '备注';这些标题就写到我原来打开的Excel文件中去了。不知为何?还请各位大侠告知!
晕.......................................
你说的这个我也能打开啊........
var
Filename:String;
begin
opendialog1.filter:='所有文件(*.*)|*.*';
Opendialog1.InitialDir:=extractfilepath(application.exename);
if Opendialog1.Execute then
begin
FileName:=OpenDialog1.FileName;
OleContainer1.CreateObjectFromFile(FileName,False);
OleContainer1.Run;
end;
end;你试试这个。可以单独再打开窗体啊.
我在程序里里面已经打开了EXCEL,然后我到程序外面也是可以直接就打开EXCEL的。
Sheet.Cells[1, 2] := '厂家';
Sheet.Cells[1, 3] := '批号';
Sheet.Cells[1, 4] := '描述';
Sheet.Cells[1, 5] := '封装';
Sheet.Cells[1, 6] := '数量';
Sheet.Cells[1, 7] := '进价';
Sheet.Cells[1, 8] := '询价人';
Sheet.Cells[1, 9] := '询价日期';
Sheet.Cells[1, 10] := '备注';
,然后我可以在程序外面也就是可以用Excel另外打开任意多的Excel文件,因为我要把那些另外打开的文件复制到我的窗体上进行编辑等操作,然后存入数据库中。
First chance exception at $7C812AFB. Exception class EOleSysError with message '找不到 %1。'.
怎么回事