copying word document to clipboard

Add-in Express™ Support Service
That's what is more important than anything else

copying word document to clipboard
 
Guest


Guest


I am trying to develop word add-in which copies the active document to the clipboard.

DataObject iData = new DataObject(DataFormats.Rtf, doc);
Clipboard.SetDataObject(iData, true);

(where doc is active document) does not work.
Note that i am trying to copy entire document to clipboard, not just the text. I am seriously in need of help on this problem.

thanks in advance,
serhat.
Posted 05 Mar, 2005 22:58:46 Top
Eugene Starostin


Guest


Use IPersistFile.

procedure TAddInModule.adxCommandBar1Controls0Click(Sender: TObject);
var
  PF: IPersistFile;
begin
  WordApp.ActiveDocument.QueryInterface(IPersistFile, PF);
  try
    if Assigned(PF) then begin
      PF.Save(MyFileName, false);
    end;
  finally
    PF := nil;
  end;
end;
Posted 06 Mar, 2005 06:06:22 Top
Eugene Starostin


Guest


Ooops... Sorry, ingnore the previous reply...
Posted 06 Mar, 2005 06:14:48 Top
Guest


Guest


no problem.

i forgot to mention that i am trying to save it as RTF.
Posted 06 Mar, 2005 08:35:04 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Guest,

I hope the code below will be useful:


procedure TAddInModule.adxCommandBar1Controls0Click(Sender: TObject);
var
  IData: IDataObject;
begin
  if WordApp.Documents.Count 
>
 0 then begin
    WordApp.ActiveDocument.QueryInterface(IDataObject, IData);
    if Assigned(IData) then
      try
        OleSetClipboard(IData);
      finally
        IData := nil;
      end;
  end;
end;


Posted 07 Mar, 2005 07:08:50 Top
Guest


Guest


Dmitry,

thanks for the reply. However, i also forgot to mention that i am working on .net c# and I couldnt manage to find the QueryInterface method.
also, does your proposal include conversion to rtf?

thanks,
serhat.
Posted 07 Mar, 2005 15:28:09 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Serhat,

After the code is executed the Clipboard will have the Rich Text format.
BTW, we have NET forum. Could you please all your questions related to C# ask here:
http://www.add-in-express.com/forum/list.php?FID=5
Posted 08 Mar, 2005 06:11:52 Top