線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2693
推到 Plurk!
推到 Facebook!

OLE的問題(在Word中插入表格)

尚未結案
gump996
一般會員


發表:10
回覆:8
積分:3
註冊:2002-10-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-19 11:33:16 IP:218.172.xxx.xxx 未訂閱
以下的程式碼是我在討論區中所搜尋到的,為何不能使用? 希望能有哪為前輩能指出錯誤在哪裡,感激不盡! Variant wordApp; if (wordApp.IsEmpty()) { wordApp=Variant::CreateObject("Word.Application"); } else { wordApp=GetActiveOleObject("Word.Application"); } if (wordApp.IsEmpty()) { ShowMessage("Unable to find Word application."); return; } wordApp.OlePropertySet("Visible", (Variant) true); Variant wordDocuments = wordApp.OlePropertyGet("Documents"); // creates a new document wordDocuments.OleProcedure("Add"); Variant wordActiveDocument = wordApp.OlePropertyGet("ActiveDocument"); Variant wordTables = wordActiveDocument.OlePropertyGet("Tables"); Variant wordSelection = wordApp.OlePropertyGet("Selection"); Variant Range = wordSelection.OlePropertyGet("Range"); // inserts the table wordTables.OleProcedure("Add", Range, (Variant) 3, (Variant) 5);
gemi0305
版主


發表:81
回覆:564
積分:629
註冊:2003-05-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-12-20 23:40:10 IP:61.224.xxx.xxx 未訂閱
在前面記得要加上這行 應該就行~ < class="code"> #include 國泰平安
gump996
一般會員


發表:10
回覆:8
積分:3
註冊:2002-10-18

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-12-22 09:19:37 IP:218.172.xxx.xxx 未訂閱
引言: 在前面記得要加上這行 應該就行~ < class="code"> #include 國泰平安
謝謝您的回覆,但是在測試上面的程式碼時,我已經有加入您所說的那一行了。
gemi0305
版主


發表:81
回覆:564
積分:629
註冊:2003-05-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-12-22 13:24:17 IP:210.66.xxx.xxx 未訂閱
請問你出現的錯誤訊息是什麼?? 這裡有我
gump996
一般會員


發表:10
回覆:8
積分:3
註冊:2002-10-18

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-12-22 13:45:38 IP:218.172.xxx.xxx 未訂閱
引言: 請問你出現的錯誤訊息是什麼?? 這裡有我>< face="Verdana, Arial, Helvetica"> 感謝Gemi版主,我試了您所提供的code但是在我的Builder上無法compile通過。 應該是我的設定有問題吧,但我不知問題出在哪裡,還懇請多多指教,出現錯誤訊息如下: [C Error] sysvari.h(2561): E2450 Undefined structure 'TAutoArgs<1>' [C Error] sysvari.h(2561): E2449 Size of 'args' is unknown or zero [C Error] sysvari.h(2561): E2450 Undefined structure 'TAutoArgs<1>' [C Error] sysvari.h(2562): E2094 'operator ' not implemented in type 'TAutoArgs<1>' for arguments of type 'int' [C Error] sysvari.h(2563): E2450 Undefined structure 'TAutoArgs<1>' [C Error] sysvari.h(2563): E2285 Could not find a match for 'Variant::OlePropertySet(const AnsiString,undefined)' [C Error] sysvari.h(1246): E2450 Undefined structure 'TAutoArgs<3>' [C Error] sysvari.h(1246): E2449 Size of 'args' is unknown or zero [C Error] sysvari.h(1246): E2450 Undefined structure 'TAutoArgs<3>' [C Error] sysvari.h(1247): E2094 'operator ' not implemented in type 'TAutoArgs<3>' for arguments of type 'int' [C Error] sysvari.h(1247): E2094 'operator ' not implemented in type 'TAutoArgs<3>' for arguments of type 'int' [C Error] sysvari.h(1247): E2094 'operator ' not implemented in type 'TAutoArgs<3>' for arguments of type 'int' [C Error] sysvari.h(1248): E2450 Undefined structure 'TAutoArgs<3>' [C Error] sysvari.h(1248): E2285 Could not find a match for 'Variant::OleProcedure(const AnsiString,undefined)'
gemi0305
版主


發表:81
回覆:564
積分:629
註冊:2003-05-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-12-22 15:12:29 IP:210.66.xxx.xxx 未訂閱
呵,你可能是用bcb5寫的吧~ 在bcb5之下的確會出現這些錯鋘訊息~ 看看有沒有使用bcb5的版友, 有什麼解決的辨法~ 我是在
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-12-22 18:26:26 IP:61.218.xxx.xxx 未訂閱
gump996您好: 試試下面的方法
//---------------------------------------------------------------------------    #include 
#pragma hdrstop
#include 
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Variant word_app;
  Variant word_docs;
  Variant word_range;
  Variant word_tables;
  Variant word_table;
  Variant active_doc;
  Variant the_cell;
  Variant cell_range;
  int cell_width  ;
  int cell_long   ;      word_app=Variant::CreateObject("Word.application");      word_docs=word_app.OlePropertyGet("documents");       word_docs.OleProcedure("add");       word_app.OlePropertySet("Visible",true);       active_doc=word_app.OlePropertyGet("ActiveDocument");       word_range=active_doc.OleFunction("Range");       word_tables=word_range.OlePropertyGet("Tables");       cell_width=5; 
  cell_long=20;
  word_table=word_tables.OleFunction("Add",word_range,cell_long+1,cell_width); 
  //*****畫表格
  Procedure InsertAfter("InsertAfter");
  for(int i=0;i
結果
/*生活是一種藝術,用心生活才能享受生活*/
gump996
一般會員


發表:10
回覆:8
積分:3
註冊:2002-10-18

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-12-24 09:52:54 IP:218.172.xxx.xxx 未訂閱
感謝Gemi及Axsoft兩位版主的熱心幫忙,謝謝!
系統時間:2024-07-05 3:19:34
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!