简体   繁体   中英

How to copy image from PictureBox1 to excel?

Following code copies excel chart as picture and paste it into PictureBox1.

Dim ExcelWbk1 As Excel.Workbook
ExcelWbk1.ActiveChart.CopyPicture(Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen, Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlBitmap)
PictureBox1.Image = CType(Clipboard.GetData(System.Windows.Forms.DataFormats.Bitmap), Bitmap)

Now, lets do the opposite.

How to copy image from PictureBox1 and paste to the excel?

Following link may help... https://msdn.microsoft.com/en-us/library/ms172505(v=vs.90).aspx

Give this a try...

Dim xlApp As New Excel.Application
Dim wbkMyBook As Excel.Workbook
Dim shtMySheet As Worksheet

wbkMyBook = xlApp.Workbooks.Open(path to xls file)

xlApp.Visible = True

shtMySheet = wbkMyBook.Worksheets(1)

Clipboard.Clear()

Clipboard.SetData(Image, Me.PictureBox1.Image)

shtMySheet.Paste

wbkMyBook = Nothing
shtMySheet = Nothing
xlApp.Quit
xlApp = Nothing

You can use something like this

Clipboard.SetImage(pictureBox1.Image)
ActiveSheet.Paste(ActiveSheet.Range("A1"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM