wtorek, 2 listopada 2021

Saving text to Word (C++ Builder)


 void __fastcall TForm1::Button1Click(TObject *Sender)

{

 Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)

{

 ListBox1->Items->Clear();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)

{

 ListBox1->Items->Clear();

 if(FileExists(Edit1->Text))

  ListBox1->Items->LoadFromFile(Edit1->Text);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)

{

 ListBox1->Items->SaveToFile(Edit2->Text);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button5Click(TObject *Sender)

{

 ListBox1->Items->Add(Edit3->Text);

 Edit3->Text="";

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button6Click(TObject *Sender)

{

 Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button7Click(TObject *Sender)

{

 int i;

 Variant mWord, mValue;

 for (i=0;i<ListBox1->Items->Count;i++)

 {

if(ListBox1->Selected[i])

  Edit4->Text=ListBox1->Items->Strings[i];

 }


 UnicodeString a1,a2;

 a1="Selection";

 a2="Select";

 mWord=Variant::GetActiveObject("Word.Application");

 mValue=mWord.OlePropertyGet(a1);

 mValue.OlePropertySet("Text",Edit4->Text.w_str());

 mValue.OleProcedure(a2);

 mWord=mValue=Unassigned;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)

{

 Edit4->Text="Select text from the ListBox";

}

Brak komentarzy:

Prześlij komentarz