C#Microsoft.Office.Interop.Excel.Range.CopyPicture在某些计算机上工作,但在其他计算机上不工作
我正在尝试将所选Excel区域的图片复制到剪贴板,并在GUI上显示该位图。我使用以下方法获取位图:C#Microsoft.Office.Interop.Excel.Range.CopyPicture在某些计算机上工作,但在其他计算机上不工作,c#,excel,office-interop,comexception,C#,Excel,Office Interop,Comexception,我正在尝试将所选Excel区域的图片复制到剪贴板,并在GUI上显示该位图。我使用以下方法获取位图: using Excel = Microsoft.Office.Interop.Excel; public static Bitmap CopyPicture(ref Excel.Range range) { System.Threading.Thread.Sleep(1000); //Google told me... range.Select();
using Excel = Microsoft.Office.Interop.Excel;
public static Bitmap CopyPicture(ref Excel.Range range)
{
System.Threading.Thread.Sleep(1000); //Google told me...
range.Select(); //...that these lines are possible fixes.
range.Copy(); //They aren't.
try
{
range.CopyPicture(Excel.XlPictureAppearance.xlScreen, Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlBitmap);
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
IDataObject data = Clipboard.GetDataObject();
if (data != null)
{
if (data.GetDataPresent(DataFormats.Bitmap))
{
Bitmap map = (Bitmap)data.GetData(DataFormats.Bitmap, true);
MessageBox.Show("Return map");
return map;
}
}
MessageBox.Show("Return null");
return null;
}
问题是,在我的计算机(我用来开发)和另一台计算机上,这个解决方案工作得很好,我得到了我想要的图片。在其他一些计算机上,它不工作,range.CopyPicture(…)
抛出此错误
所有这些计算机都有最新的Excel更新,并运行Windows 7。使用不同的用户(管理员或非管理员)时没有区别
非常感谢大家的帮助,这几天我一直在忙