在C++ Builde 中呼出 Words 並建立上下兩個表格 |
尚未結案
|
MartinPan
一般會員 發表:3 回覆:4 積分:1 註冊:2005-04-30 發送簡訊給我 |
|
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
|
MartinPan
一般會員 發表:3 回覆:4 積分:1 註冊:2005-04-30 發送簡訊給我 |
謝謝您 以下是我的程式碼。
執行到wordApp.OleFunction("SaveAs",StringToOleStr(fname)); 會有錯誤訊息。麻煩各位大大指點一下。
/*********************************************************************
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant FileFormat=wdFormatText;
AnsiString fname;
if(SaveDialog1->Execute())
{
fname= SaveDialog1->FileName;
wordApp.OleFunction("SaveAs",StringToOleStr(fname));
}
}
********************************************************************/
//---------------------------------------------------------------------------
bool __fastcall TForm1::connectWinWord(void)
{
if (wordApp.IsEmpty())
{
wordApp=Variant::CreateObject("Word.Application");
}
else
{
wordApp=GetActiveOleObject("Word.Application");
}
if (wordApp.IsEmpty())
{
ShowMessage("Unable to find Word application.");
return false;
} wordApp.OlePropertySet("Visible", true);
//wordApp.Visible=true; return (!wordApp.IsEmpty());
}
//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TForm1::btnOpenClick(TObject *Sender)
{
wordDocuments = wordApp.OlePropertyGet("Documents");
String ffName="c:\\test.doc";
wordDocuments.OleProcedure("Open", ffName); // (Variant).c_str() }
//--------------------------------------------------------------------------- void __fastcall TForm1::btnConnectClick(TObject *Sender)
{
connectWinWord();
}
//--------------------------------------------------------------------------- void __fastcall TForm1::btnPrintClick(TObject *Sender)
{
wordApp.OleProcedure("PrintOut");
}
//--------------------------------------------------------------------------- void __fastcall TForm1::btnSaveClick(TObject *Sender)
{
wordDocuments.OleProcedure("Save");
}
//--------------------------------------------------------------------------- void __fastcall TForm1::btnCloseWordClick(TObject *Sender)
{
wordDocuments.OleProcedure("Close"); //
}
//--------------------------------------------------------------------------- void __fastcall TForm1::btnCloseAppClick(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------- void __fastcall TForm1::btnAddClick(TObject *Sender)
{
//wordApp.OlePropertySet("Visible", true);
wordDocuments = wordApp.OlePropertyGet("Documents");
wordDocuments.OleProcedure("Add");
}
//--------------------------------------------------------------------------- void __fastcall TForm1::btnTableClick(TObject *Sender)
{
Variant wordActiveDocument = wordApp.OlePropertyGet("ActiveDocument");
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);
}
//--------------------------------------------------------------------------- void __fastcall TForm1::btnInsertTextClick(TObject *Sender)
{
Variant wordTable1 = wordTables.OleFunction("Item", (Variant)1); //
Variant wordCell = wordTable1.OleFunction("Cell", (Variant)2, (Variant)3 );
Variant wordRange = wordCell.OlePropertyGet("Range");
wordRange.OlePropertySet("Text", WideString("We are at 2/3")); //wordCell ,wordRange (Variant)
}
//--------------------------------------------------------------------------- void __fastcall TForm1::btnDisconWordClick(TObject *Sender)
{
wordApp.OleProcedure("Quit");
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant FileFormat=wdFormatText;
AnsiString fname;
if(SaveDialog1->Execute())
{
fname= SaveDialog1->FileName;
wordApp.OleFunction("SaveAs",StringToOleStr(fname)); //()
}
}
//---------------------------------------------------------------------------
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |