全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1661
推到 Plurk!
推到 Facebook!

Test Program - 有2個 Excel Books run on 2 個 EXCEL.EXE processes, 如何同時讀資料?

尚未結案
joewang12
一般會員


發表:7
回覆:4
積分:2
註冊:2005-02-22

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-02-06 02:51:51 IP:218.170.xxx.xxx 訂閱
有2個 Excel Books run on 2 個 EXCEL.EXE processes, 如何同時讀資料?

問題如同Test program.
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-02-09 18:45:30 IP:61.229.xxx.xxx 訂閱
Excel 同一檔案不允許被重複開啟二次,希望我有猜對。
[code delphi]
procedure TForm1.btRunClick(Sender: TObject);
begin
ExcelApp1:=CreateOleObject('Excel.Application');
ExcelWorkBooks1:=ExcelApp1.WorkBooks.Add;
ExcelWorkSheets1:=ExcelWorkBooks1.WorkSheets[1];
ExcelApp1.Visible := True;
ExcelWorkSheets1.Activate;
ExcelWorkSheets1.Cells[1,1]:='ExcelApp1';
ExcelWorkSheets1.Cells[2,1]:='ExcelWorkBooks1';
ExcelWorkSheets1.Cells[3,1]:='ExcelWorkSheets1';

// ExcelApp1:=CreateOleObject('Excel.Application'); <---Excel 同一檔案不允許被重複開啟二次
ExcelWorkBooks2:=ExcelApp1.WorkBooks.Add;
ExcelWorkSheets2:=ExcelWorkBooks2.WorkSheets[2];
ExcelApp1.Visible := True;
ExcelWorkSheets2.Activate;
ExcelWorkSheets2.Cells[1,1]:='ExcelApp1';
ExcelWorkSheets2.Cells[2,1]:='ExcelWorkBooks2';
ExcelWorkSheets2.Cells[3,1]:='ExcelWorkSheets2';

btRun.Enabled:=False;
btExit.Enabled:=True;
btGetExcel1.Enabled:=True;
btGetExcel2.Enabled:=True;
tmRun.Enabled:=true;
end;
[/code]
------
努力會更接近成功
joewang12
一般會員


發表:7
回覆:4
積分:2
註冊:2005-02-22

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-02-10 16:52:43 IP:218.174.xxx.xxx 訂閱
謝謝pceyes大大,
我的問題是已有2 EXCEL.EXE process 存在,我如何同時抓他們的資料.
http://delphi.ktop.com.tw/board.php?cid=30&fid=1498&tid=92477

我只會用GetActiveOleObject('Excel.Application');
這只會抓到一個EXCEL.EXE的Book1資料,另一Book2則抓不到.
我要如何才能抓到Book2?

問題來源是群益錢博士real time stock program的DDE to EXCEL function,我須要它同時export2個EXCEL Data
計算所需的值.

敬請各位高手大大指教
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-02-11 08:33:39 IP:61.229.xxx.xxx 訂閱
目前並沒有找到切換Excelapp的方法, 你可能仍要自已測一下

procedure TForm1.btGetExcel2Click(Sender: TObject);
var
exSheet: Variant;
begin
{-----------以下是我加的, 目的是切換至另一個Excelapp }
if GetExcelSheet('Book2', 'Sheet1', exSheet) then begin <---它好像沒有指定哪個excelapp(未切換至另一個Excelapp)
Memo2.Clear;
Memo2.Lines.Add(exSheet.Cells[1,1]);
Memo2.Lines.Add(exSheet.Cells[2,1]);
Memo2.Lines.Add(exSheet.Cells[3,1]);
Memo2.Lines.Add(exSheet.Cells[4,1]);
tmGetExcelApp2.Enabled:=True;
btGetExcel2.Enabled:=False;
end else begin
Showmessage('Error here! This is read from BOOK1.Sheet1, not BOOK2...How Can I read BOOK2');
end;
end;
------
努力會更接近成功
joewang12
一般會員


發表:7
回覆:4
積分:2
註冊:2005-02-22

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-02-11 15:54:03 IP:218.170.xxx.xxx 訂閱
pceyes大大,

Thanks very much for your information.
我試了它,亦不行.我想原因為
1.真實問題是我沒有ExcelApp2,ExcelWorkBooks2 variables.
2.GetExcelSheet is same as GetActiveOleObject to use current active EXCEL.EXE process.
3.All others EXCEL functions have same issue which works on active EXCEL.EXE process too.

因此,我猜測需要使用Window find process API to find it first 然後change EXCEL OLE server to it.
但是我不知道怎樣 how to configure OLE server if I know every information about it。

無論如何,感謝你的好心幫助我。
joewang12
一般會員


發表:7
回覆:4
積分:2
註冊:2005-02-22

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-02-15 13:49:00 IP:218.170.xxx.xxx 訂閱
I do not know who will concern this issue since none to answer.

I got the answer for this issue and I post it below.
It is not in all delphi code But I write some VB macro in
non-active EAXCEL.EXE to write out all data to file periodical.
Deliph code will get data from file but directly access from EXCEL.EXE.

So, I will close this issue.
Thanks for anyone whom read this acticle.
系統時間:2024-04-18 17:22:53
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!