unit main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleServer, ExcelXP, StdCtrls , ExtCtrls; type TForm1 = class(TForm) exclplctn1: TExcelApplication; exclwrkbk1: TExcelWorkbook; exclwrksht1: TExcelWorksheet; exclplctn2: TExcelApplication; exclwrkbk2: TExcelWorkbook; exclwrksht2: TExcelWorksheet; btn1: TButton; procedure btn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btn1Click(Sender: TObject); begin exclplctn1.Connect; exclwrkbk1.ConnectTo(exclplctn1.Workbooks.Add(EmptyParam , 0)); exclplctn1.Workbooks[1].Activate(0); exclplctn1.Visible[0] := True; exclplctn2.Connect; exclplctn2.Workbooks.Open('d:\Information.xlsx' , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , EmptyParam , 0); exclplctn2.Workbooks[1].Activate(0); exclplctn2.Visible[0] := True; exclplctn2.ActiveSheet.Used.Range.Copy; //这句Used , Range , Copy均报错。
end; end.
Used报错为:IDisptch does not contain a member named 'Used';
Range & Copy报错为:Undeclared indentifier。
请问大大们,这个是怎么回事,还有下面动态创建。
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs , ComObj; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var wb1 : Variant; wb2 : Variant; begin wb1 := CreateOleObject('Excel.Application'); wb2 := CreateOleObject('Excel.Application'); wb1.WorkBooks.add; wb2.WorkBooks.Open('D:\Information.xlsx'); wb1.Visible := True; wb2.Visible := True; wb2.Activate.Used.Range.Copy; //这句不能执行; end; end.
拷贝操作还是不行,不能执行,报出异常:rasied exception class EOleError with message 'Method 'Activate' not supported by automaion object';
还请大神交一下小弟,万分感谢。