C# Wpf.net core 3.1 Excel互操作选择复制图片
我使用VS2012连接到Excel.Interop应用程序中的Excel文件并将Excel工作表中的数字保存为图像的代码如下所示。VS2012适用于Windows桌面应用程序。但为什么不能在.NETCore3.1WPF应用程序中工作呢。(VS2019) 错误消息如下所示。 Microsoft.csharp.runtimebinder.runtimebinderexception CopyPicture Sysyem.\u comObject不包含“CopyPicture”的定义。 但这些代码在windows桌面应用程序中工作。如果在mvvmcross或wpf中丢失,我可以做什么C# Wpf.net core 3.1 Excel互操作选择复制图片,c#,excel,wpf,excel-interop,C#,Excel,Wpf,Excel Interop,我使用VS2012连接到Excel.Interop应用程序中的Excel文件并将Excel工作表中的数字保存为图像的代码如下所示。VS2012适用于Windows桌面应用程序。但为什么不能在.NETCore3.1WPF应用程序中工作呢。(VS2019) 错误消息如下所示。 Microsoft.csharp.runtimebinder.runtimebinderexception CopyPicture Sysyem.\u comObject不包含“CopyPicture”的定义。 但这些代码在w
object Missing = System.Reflection.Missing.Value;
string path="ExcelFilePath"
Excel.Application ExcelApplication=new Excel.Application();
Excel.Workbook ExcelWorkbook = ExcelApplication.Workbooks.Open(path,
Excel.XlUpdateLinks.xlUpdateLinksUserSetting, true, Missing, Missing, Missing,
Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing);
Excel.Worksheet ExcelWorksheet = ExcelWorkbook.Worksheets["WorksheetName"];
ExcelWorksheet.Activate();
ExcelWorksheet.Shapes.Range["Group 189"].Select(Replace: true);
ExcelWorksheet.Shapes.Range["Group 197"].Select(Replace: false);
ExcelApplication.Selection.CopyPicture(Excel.XlPictureAppearance.xlScreen,
Excel.XlCopyPictureFormat.xlBitmap);
if (Clipboard.ContainsImage() == true)
{
Image image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
image.Save(@"ImagePath"+ ".png", System.Drawing.Imaging.ImageFormat.Png);
}