Copy-paste office documents via clipboard
Hello!
I need to copy paste office documents via clipboard. I wrote next code:
public void InsertDocument(object mDocument, string documentFileName)
{
if(mDocument!=null)
{
FileStream fileStream = new FileStream(documentFileName,FileMode.Open);
byte[] file = new byte[(int)fileStream.Length];
fileStream.Read(file,0,(int)fileStream.Length);
fileStream.Close();
Clipboard.SetDataObject(new
DataObject(System.Windows.Forms.DataFormats.FileDrop,file), false);
object selection = mDocument.GetType().InvokeMember("Selection",
BindingFlags.GetProperty, null, mMSWord, null);
selection.GetType().InvokeMember("Paste",BindingFlags.InvokeMethod, null,
selection, null);
}
}
The last command couses inner exception "command error". Is there wrong
DataFormat ? What should I put to the clipboard, file in binary or file path
as a string ? What should I correct to get it working ?
Thanks
JensB - 30 Mar 2007 16:47 GMT
Hi
I am not a C# programmer, but if you want to bring the content from a
word.doc file to another,
you could use this wordbasic command:
selection.InsertFile(documentFilename)
Might be at some help.
JensB
> Copy-paste office documents via clipboard
>
[quoted text clipped - 37 lines]
>
> Thanks