在Excel中移動Sheet位置的寫法? |
尚未結案
|
m8815010
版主 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
大家好: 題目如 href="http://delphi.ktop.com.tw/topic.php?topic_id=50320">http://delphi.ktop.com.tw/topic.php?topic_id=50320 那不曉得這樣的寫法要怎樣寫:
~~ Variant ExcelApp,WorkBook,WorkSheets,Old_Sheet; ExcelApp=CreateOleObject("Excel.Application"); WorkBook=ExcelApp.OlePropertyGet("WorkBooks").OleFunction("Open",filenmae); WorkSheets=WorkBook.OlePropertyGet("WorkSheets"); Old_Sheet=WorkSheets.OlePropertyGet("Item",1); Varinat New_Sheet; New_Sheet=WorkSheets.OleFunction("Add"); 然後要如何移動這個Sheet的位置呢(例如把這個Sheet移到Old_Sheet之後)? New_Sheet.OleFunction("Move" .... or someway else?找半天找不到相關文章,又try不出來,請大家幫幫了,謝謝! |
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
|
Clarinet
高階會員 發表:9 回覆:97 積分:126 註冊:2002-05-08 發送簡訊給我 |
|
sanhang
一般會員 發表:12 回覆:25 積分:17 註冊:2002-08-31 發送簡訊給我 |
引言: 語法為Move(Before, After :OleVariant) 若有兩個Sheet為1和2,要把1移至2之後,即如下: Sheet :=Sheets.Item[1];//取得Sheet1 Sheet.Move(, Sheets.Item[2]);//把Sheet1移至Sheet2之後Delphi如果是引用CreateOleObject 遇到選擇性參數也要填滿,最少也要填入EmptyParam 所以補充一下Clarinet大大的寫法 MySheet := ExcelApp.WorkSheets[1];//取得Sheet1 MySheet.Move(EmptyParam, ExcelApp.WorkSheets[2]); //把Sheet1移至Sheet2之後 |
Clarinet
高階會員 發表:9 回覆:97 積分:126 註冊:2002-05-08 發送簡訊給我 |
引言: Delphi如果是引用CreateOleObject 遇到選擇性參數也要填滿,最少也要填入EmptyParam 所以補充一下Clarinet大大的寫法 MySheet := ExcelApp.WorkSheets[1];//取得Sheet1 MySheet.Move(EmptyParam, ExcelApp.WorkSheets[2]); //把Sheet1移至Sheet2之後我測試過是可以不用的! 所以,EmptyParam 可以不用。 不過加入對程式來說是比較好看!
------
GPS(全球衛星定位系統) http://www.allgps.com |
m8815010
版主 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
歹勢,歹勢,俗事纏身,拖了這麼久才回! 首先感謝 >!
<>< face="Verdana, Arial, Helvetica">引言:
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=21190
另外感謝Clarinet及sanhang兄的相關回覆,但我要的是這樣的寫法:
WorkSheet.OleFunction(〝這裏面要如何下參數〞)當然也可能是用OlePropertySet這個method等等等啦! 我不是要問WorkSheet.Move("...")這樣要怎麼寫,因為我那樣的寫法WorkSheet物件根本沒有Move method的< >! 也就是我要跟我問題描述的一樣東東,請大家再幫幫忙,感謝,< >! |
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
引言: 大家好: 題目如 href="http://delphi.ktop.com.tw/topic.php?topic_id=50320">http://delphi.ktop.com.tw/topic.php?topic_id=50320 那不曉得這樣的寫法要怎樣寫:OleFunction 是BCB寫法 以下範例僅供參考:~~ Variant ExcelApp,WorkBook,WorkSheets,Old_Sheet; ExcelApp=CreateOleObject("Excel.Application"); WorkBook=ExcelApp.OlePropertyGet("WorkBooks").OleFunction("Open",filenmae); WorkSheets=WorkBook.OlePropertyGet("WorkSheets"); Old_Sheet=WorkSheets.OlePropertyGet("Item",1); Varinat New_Sheet; New_Sheet=WorkSheets.OleFunction("Add"); 然後要如何移動這個Sheet的位置呢(例如把這個Sheet移到Old_Sheet之後)? New_Sheet.OleFunction("Move" .... or someway else? unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, 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; XLSApp,XLSWK:Variant; implementation uses Comobj; {$R *.dfm} //開三個工作表玩玩 procedure TForm1.Button1Click(Sender: TObject); begin XLSApp:=CreateOleObject('Excel.Application'); XLSWK:=XLSApp.WorkBooks.Add; XLSApp.Sheets['Sheet1'].Name:='Qoo-1'; XLSApp.Worksheets.Add; XLSApp.Sheets['Sheet2'].Name:='Qoo-2'; XLSApp.Worksheets.Add; XLSApp.Sheets['Sheet3'].Name:='Qoo-3'; XLSApp.Visible:=True; end; //調整位置 procedure TForm1.Button2Click(Sender: TObject); begin XLSWK.Sheets[1].Move(After:=XLSWK.Sheets[2]); XLSWK.Sheets[2].Move(After:=XLSWK.Sheets[3]); XLSWK.Sheets[1].Move(After:=XLSWK.Sheets[2]); end; end. |
m8815010
版主 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
|
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |