图片来自 Excel 到 vb.net Picturebox
Image from Excel to vb.net Picturebox
我发现了很多关于 vb.net 到 excel 相反的问题,但是 none 从 excel cell(row,column)
中获取图片到图片框中.我的应用程序是一个从 excel 文件中获取文本字符串的模板。效果很好,但现在我也在尝试传输图片。我试过 picSpindle.Image = shXL.Cells(19, 2).Value
但什么也没做。不过不会出错!
复制粘贴有用吗?
代码:
Imports System
Imports System.IO
Imports System.Text
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim appXL As Excel.Application
Dim wbXl As Excel.Workbook
Dim shXL As Excel.Worksheet
Dim raXL As Excel.Range
Dim PartID As String
Dim RefCard As String
Private Sub Form1_Activated(sender As System.Object, e As System.EventArgs) Handles MyBase.Activated
'Dispaly Brembo Logo
picLogo.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Read File Source with part number ******************Example From TXT
PartID = ("19.N111.10")
' Start Excel and get Application object.
appXL = CreateObject("Excel.Application")
appXL.Visible = False
'Open Reference Card*************************************************************************************
wbXl = appXL.Workbooks.Open("C:\Users\aholiday\Desktop\Visual Studios Projects\Reference Card App\" & PartID & ".xlsx")
shXL = wbXl.Worksheets("Sheet1")
' Copys Reference Card Text from Cells To App labels
lblCODE.Text = shXL.Cells(3, 9).Value
Debug.Print(lblCODE.Text)
lblREV.Text = shXL.Cells(3, 13).Value
lblDate.Text = shXL.Cells(5, 9).Value
lblCustomer.Text = shXL.Cells(8, 2).Value
lblPart.Text = shXL.Cells(11, 2).Value
lblSpindleType.Text = shXL.Cells(15, 2).Value
lblPaintType.Text = shXL.Cells(7, 6).Value
lblDunnageType.Text = shXL.Cells(8, 8).Value
lblPartsLayer.Text = shXL.Cells(11, 11).Value
lblLayers.Text = shXL.Cells(15, 11).Value
lblTotalParts.Text = shXL.Cells(20, 11).Value
lblPackagingInstructs.Text = shXL.Cells(20, 11).Value
'Works up to here!
' Copys Reference Card Pictures from Cells To App Pictureboxs
picSpindle.Image = shXL.Cells(19, 2).Value
picRotorTop.Image = shXL.Cells(10, 6).Value
picRotorBottom.Image = shXL.Cells(19, 6).Value
picDunnageFinal.Image = shXL.Cells(10, 8).Value
picDunnageLayer.Image = shXL.Cells(19, 8).Value
' Close objects
raXL = Nothing
shXL = Nothing
wbXl = Nothing
appXL.Quit()
appXL = Nothing
End Sub
End Class
shXL.Cells(19, 2).Value
等等将不起作用,因为图片不存储在 cells
中,而是存储在它们之上
意思是 values
其中 cells
将是 nothing
试试这些链接
图像不在单元格内。但是左上角的坐标指向一个单元格,使用上面的代码你可以制作自己的搜索图像的功能。
你可以这样做:
shXL = wbXl.Worksheets("Sheet1")
' # Loop for all Shapes
' But I don't know what other controls over
' the images are considered "shapes",
' Perhaps the best way is to verify that
' in the "clipboard" there is truly a picture
For i = 0 To shXL.Shapes.Count - 1
'THIS IS THE MAIN POINT
' # get the pictures and copy to clipboard
'shXL.Shapes.Item(i).Copy()
' # paste the picture in the pictureBox from clipboard
'PictureBox1.Image = Clipboard.GetImage
'AND OTHER PROPERTIS
MsgBox(shXL.Shapes.Item(i).Name) ' the name in excel
MsgBox(shXL.Shapes.Item(i).AlternativeText) 'the name of the file
MsgBox(shXL.Shapes.Item(i).TopLeftCell.Column) 'the column position (of the top left corner)
MsgBox(shXL.Shapes.Item(i).TopLeftCell.Row) 'the row position (of the top left corner)
MsgBox(shXL.Shapes.Item(i).Width) 'the with in px
MsgBox(shXL.Shapes.Item(i).Height) 'the height in px
MsgBox(shXL.Shapes.Item(i).Top) 'the top in px
MsgBox(shXL.Shapes.Item(i).Left) 'the left in px
Next
我发现了很多关于 vb.net 到 excel 相反的问题,但是 none 从 excel cell(row,column)
中获取图片到图片框中.我的应用程序是一个从 excel 文件中获取文本字符串的模板。效果很好,但现在我也在尝试传输图片。我试过 picSpindle.Image = shXL.Cells(19, 2).Value
但什么也没做。不过不会出错!
复制粘贴有用吗?
代码:
Imports System
Imports System.IO
Imports System.Text
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim appXL As Excel.Application
Dim wbXl As Excel.Workbook
Dim shXL As Excel.Worksheet
Dim raXL As Excel.Range
Dim PartID As String
Dim RefCard As String
Private Sub Form1_Activated(sender As System.Object, e As System.EventArgs) Handles MyBase.Activated
'Dispaly Brembo Logo
picLogo.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Read File Source with part number ******************Example From TXT
PartID = ("19.N111.10")
' Start Excel and get Application object.
appXL = CreateObject("Excel.Application")
appXL.Visible = False
'Open Reference Card*************************************************************************************
wbXl = appXL.Workbooks.Open("C:\Users\aholiday\Desktop\Visual Studios Projects\Reference Card App\" & PartID & ".xlsx")
shXL = wbXl.Worksheets("Sheet1")
' Copys Reference Card Text from Cells To App labels
lblCODE.Text = shXL.Cells(3, 9).Value
Debug.Print(lblCODE.Text)
lblREV.Text = shXL.Cells(3, 13).Value
lblDate.Text = shXL.Cells(5, 9).Value
lblCustomer.Text = shXL.Cells(8, 2).Value
lblPart.Text = shXL.Cells(11, 2).Value
lblSpindleType.Text = shXL.Cells(15, 2).Value
lblPaintType.Text = shXL.Cells(7, 6).Value
lblDunnageType.Text = shXL.Cells(8, 8).Value
lblPartsLayer.Text = shXL.Cells(11, 11).Value
lblLayers.Text = shXL.Cells(15, 11).Value
lblTotalParts.Text = shXL.Cells(20, 11).Value
lblPackagingInstructs.Text = shXL.Cells(20, 11).Value
'Works up to here!
' Copys Reference Card Pictures from Cells To App Pictureboxs
picSpindle.Image = shXL.Cells(19, 2).Value
picRotorTop.Image = shXL.Cells(10, 6).Value
picRotorBottom.Image = shXL.Cells(19, 6).Value
picDunnageFinal.Image = shXL.Cells(10, 8).Value
picDunnageLayer.Image = shXL.Cells(19, 8).Value
' Close objects
raXL = Nothing
shXL = Nothing
wbXl = Nothing
appXL.Quit()
appXL = Nothing
End Sub
End Class
shXL.Cells(19, 2).Value
等等将不起作用,因为图片不存储在 cells
中,而是存储在它们之上
意思是 values
其中 cells
将是 nothing
试试这些链接
图像不在单元格内。但是左上角的坐标指向一个单元格,使用上面的代码你可以制作自己的搜索图像的功能。
你可以这样做:
shXL = wbXl.Worksheets("Sheet1")
' # Loop for all Shapes
' But I don't know what other controls over
' the images are considered "shapes",
' Perhaps the best way is to verify that
' in the "clipboard" there is truly a picture
For i = 0 To shXL.Shapes.Count - 1
'THIS IS THE MAIN POINT
' # get the pictures and copy to clipboard
'shXL.Shapes.Item(i).Copy()
' # paste the picture in the pictureBox from clipboard
'PictureBox1.Image = Clipboard.GetImage
'AND OTHER PROPERTIS
MsgBox(shXL.Shapes.Item(i).Name) ' the name in excel
MsgBox(shXL.Shapes.Item(i).AlternativeText) 'the name of the file
MsgBox(shXL.Shapes.Item(i).TopLeftCell.Column) 'the column position (of the top left corner)
MsgBox(shXL.Shapes.Item(i).TopLeftCell.Row) 'the row position (of the top left corner)
MsgBox(shXL.Shapes.Item(i).Width) 'the with in px
MsgBox(shXL.Shapes.Item(i).Height) 'the height in px
MsgBox(shXL.Shapes.Item(i).Top) 'the top in px
MsgBox(shXL.Shapes.Item(i).Left) 'the left in px
Next