F flysand Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-02 #1 在delphi中通过OLE控制excel,选择一行 在VBA中为:sheet1.Rows("12:12").Select 在delphi中应如何写该语句?
B bbs_delphi Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-02 #2 app1.sheet1.Rows("12:12").Select; app1.selection.你的进一步操作 app1为你创建的对象
荷 荷塘新月 Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-02 #3 不,不能用这种方法,应该是: app1.rows['12:12'].select; //app1为你创建的ole对象
Y yzhshi Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-02 #4 荷塘新月 写的对,下面是具体的实现代码 uses comobj; procedure TForm1.Button1Click(Sender: TObject); var Excel_handle, Book_Handle: OleVariant; begin try Excel_handle := GetActiveOleObject('Excel.Application'); except try Excel_Handle := CreateOleObject('Excel.Application'); except Exit; end; end; Excel_Handle.Visible := True; Book_Handle := Excel_Handle.Workbooks.Open(FileName := 'C:/1.xls'); Book_Handle.Sheets[1].Rows['12:12'].Select; end;
荷塘新月 写的对,下面是具体的实现代码 uses comobj; procedure TForm1.Button1Click(Sender: TObject); var Excel_handle, Book_Handle: OleVariant; begin try Excel_handle := GetActiveOleObject('Excel.Application'); except try Excel_Handle := CreateOleObject('Excel.Application'); except Exit; end; end; Excel_Handle.Visible := True; Book_Handle := Excel_Handle.Workbooks.Open(FileName := 'C:/1.xls'); Book_Handle.Sheets[1].Rows['12:12'].Select; end;
F flysand Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-02 #5 Book_Handle.Sheets[1].Rows['12:12'].Select; 编译出错 "class does not have a default properly"
Y yzhshi Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-02 #6 Book_Handle.Sheets[1].Rows['12:12'].Select; 编译出错?不会吧,你新建一个工程将我上面的代码拷贝出去,看执行是否出错? OleVariant不会蹦叉的,我测试通过了的,我再测一次,给你答复。
Book_Handle.Sheets[1].Rows['12:12'].Select; 编译出错?不会吧,你新建一个工程将我上面的代码拷贝出去,看执行是否出错? OleVariant不会蹦叉的,我测试通过了的,我再测一次,给你答复。
Y yzhshi Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-02 #8 我知道你的问题原因了,你不是使用这种方式建立的Excel,是使用Server控件建立的。 这个偶也不知道怎么玩,我基本没用过这组控件,我对这个有点反感,呵呵。
F flysand Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-02 #9 ExcelApp: TExcelApplication; Excelbook: TExcelWorkbook; Excelsheet: TExcelWorksheet; //使用Server控件建立 begin ExcelApp.Connect; Excelbook.ConnectTo(ExcelApp.Workbooks.Add('c:/e.xlt',0)); Excelsheet.ConnectTo(Excelbook.WorkSheets[1] as _WorkSheet); excelsheet.range[items[1,1],items[2,22]].select;//没问题 excelsheet.rows['1:1'].select; //error end;
ExcelApp: TExcelApplication; Excelbook: TExcelWorkbook; Excelsheet: TExcelWorksheet; //使用Server控件建立 begin ExcelApp.Connect; Excelbook.ConnectTo(ExcelApp.Workbooks.Add('c:/e.xlt',0)); Excelsheet.ConnectTo(Excelbook.WorkSheets[1] as _WorkSheet); excelsheet.range[items[1,1],items[2,22]].select;//没问题 excelsheet.rows['1:1'].select; //error end;