我想把word文档的内容以图片形式复制到剪切板,然后再保存成位图格式。可是剪切板上总是找不到对象。但是在“画图”中可以粘贴上内容。这是怎么会事啊?应当怎么改进?
object OFileName = (object)filename;
object OMissing = System.Reflection.Missing.Value;
///////////////////////打开word////////////////////////////
Word.ApplicationClass wordApp = new Word.ApplicationClass();
Document wordDoc = wordApp.Documents.Open(ref OFileName,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing);
wordApp.Selection.WholeStory(); //全选
wordApp.Selection.CopyAsPicture(); //以图片形式复制
wordDoc.Close(ref OMissing ,ref OMissing,ref OMissing);
wordApp.Quit(ref OMissing,ref OMissing,ref OMissing);
Bitmap bt = null;
IDataObject ido = Clipboard.GetDataObject(); //问题出在这里,ido总是NULL,为什么?
if(ido != null)
{
if(ido.GetDataPresent(DataFormats.Bitmap))
{
bt = (Bitmap)ido.GetData(DataFormats.Bitmap);
}
}return bt;
object OFileName = (object)filename;
object OMissing = System.Reflection.Missing.Value;
///////////////////////打开word////////////////////////////
Word.ApplicationClass wordApp = new Word.ApplicationClass();
Document wordDoc = wordApp.Documents.Open(ref OFileName,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing,ref OMissing);
wordApp.Selection.WholeStory(); //全选
wordApp.Selection.CopyAsPicture(); //以图片形式复制
wordDoc.Close(ref OMissing ,ref OMissing,ref OMissing);
wordApp.Quit(ref OMissing,ref OMissing,ref OMissing);
Bitmap bt = null;
IDataObject ido = Clipboard.GetDataObject(); //问题出在这里,ido总是NULL,为什么?
if(ido != null)
{
if(ido.GetDataPresent(DataFormats.Bitmap))
{
bt = (Bitmap)ido.GetData(DataFormats.Bitmap);
}
}return bt;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货