我试图在vs2010 for Excel 2010中添加一个用于将图像复制到剪贴板然后保存的内容。 add in有一个按钮,它运行以下代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
Dim app As Excel.Application = Globals.ThisAddIn.Application
Dim desktopFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim fileName As String = "D:\testaddin\test.jpg"
Dim activeWorksheet As Excel.Worksheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet
'Dim currentCell As Excel.Range = Globals.ThisAddIn.Application.Selection
Dim pic As Excel.Shape = activeWorksheet.Shapes.Item("Picture 1")
pic.CopyPicture()
If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then
Dim oImgObj As System.Drawing.Image = oDataObj.GetData(DataFormats.Bitmap, True)
oImgObj.Save("d:\Test.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
End If
End If
End Sub
代码编译得很好但是当我按下按钮时没有任何反应 我确定知道的一件事是代码将照片复制到剪贴板,因为我在mspaint中检查过。
如何将剪贴板保存到jpeg?