将图片从piturebox插入excel [英] Inserting picture from piturebox to excel
问题描述
我有一个代码,可以将文本框中的所有信息插入到excel文件中。我试图使用此代码也从picturebox添加图片。因此图片将插入同一行中文本框中的数据。
I have a code which inserting all information from textboxes to excel file. What I trying to do to using this code also add a picture from picturebox. So the picture will be inserted with data from textboxes in the same row.
Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DATA\DATA.xlsm;Extended Properties = ""Excel 12.0 Xml;HDR=YES"""
'Create an INSERT INTO SQL statement
Dim insertStatement As String = "INSERT INTO [DATA$] ([WEEK], [DATE], [PART NAME], [PART NUMBER], [REASON FOR SCRAP], [LINE], [MACHINE], [TOOLING], [MTO], [QTY], [WHO SCRAP IT]) VALUES ('" + WEEK_TEXT.Text + "','" + DATEE_TEXT.Text + "','" + PARTNAME_TEXT.Text + "','" + PARTNUMBER_TEXT.Text + "','" + SCRAP_REASON_TEXT.Text + "','" + LINE_text.Text + "','" + MACHINE_TEXT.Text + "','" + SIDE_TEXT.Text + "','" + MTO_TEXT.Text + "','" + QUANTITY_TEXT.Text + "','" + TL_TS_TEXT.Text + "')"
Dim insertStatement1 As String = "INSERT INTO [QAD DATA$] ([WEEK], [DATE], [PART NAME], [QAD NUMBER], [REASON FOR SCRAP], [LINE], [MACHINE], [TOOLING], [MTO], [QTY], [WHO SCRAP IT]) VALUES ('" + WEEK_TEXT.Text + "','" + DATEE_TEXT.Text + "','" + PictureBox1 + "','" + QAD_NUMBER_TEXT.Text + "','" + SCRAP_REASON_TEXT.Text + "','" + LINE_text.Text + "','" + MACHINE_TEXT.Text + "','" + SIDE_TEXT.Text + "','" + MTO_TEXT.Text + "','" + QUANTITY_TEXT.Text + "','" + TL_TS_TEXT.Text + "')"
'Create a connection object to connect to the Excel Workbook
Dim connection As New OleDbConnection(connectionString)
Dim connection1 As New OleDbConnection(connectionString)
'Create a command object that will execute the insert statement
Dim command As New OleDbCommand(insertStatement, connection)
Dim command1 As New OleDbCommand(insertStatement1, connection1)
'Open the connection, execute the statement and close the connection
connection.Open()
connection1.Open()
command.ExecuteNonQuery()
command1.ExecuteNonQuery()
connection.Close()
connection1.Close()
'Dispose of the connection and command objects
connection.Dispose()
command.Dispose()
command1.Dispose()
我尝试了什么:
我从互联网上检查了很多代码,但当我尝试转移时要在单元格中表现出色的数据应该是图片说
What I have tried:
I check many codes from the internet, but when I try to transfer data to excel in the cell where should be picture its say "
System.Drawing.Bitmap
推荐答案
( [WEEK],[DATE],[PART NAME],[PART PARTBER],[SCRAP],[LINE],[MACHINE],[TOOLING],[MTO],[QTY],[WHO SCRAP IT]) VALUES(' + WEEK_TEXT.Text + ',' + DATEE_TEXT.Text + ',' + PARTNAME_TEXT.Text + ',' + PARTNUMBER_TEXT.Text + ',' + SCRAP_REASON_TEXT.Text + ',' + LINE_text .Text + ',' + MACHINE_TEXT.Text + ',' + SIDE_TEXT.Text + ',' + MTO_TEXT.Text + ',' + QUANTITY_TEXT.Text + ',' + TL_TS_TEXT .Text + ')
Dim insertStatement1 As String = INSERT INTO [QAD DATA
([WEEK], [DATE], [PART NAME], [PART NUMBER], [REASON FOR SCRAP], [LINE], [MACHINE], [TOOLING], [MTO], [QTY], [WHO SCRAP IT]) VALUES ('" + WEEK_TEXT.Text + "','" + DATEE_TEXT.Text + "','" + PARTNAME_TEXT.Text + "','" + PARTNUMBER_TEXT.Text + "','" + SCRAP_REASON_TEXT.Text + "','" + LINE_text.Text + "','" + MACHINE_TEXT.Text + "','" + SIDE_TEXT.Text + "','" + MTO_TEXT.Text + "','" + QUANTITY_TEXT.Text + "','" + TL_TS_TEXT.Text + "')" Dim insertStatement1 As String = "INSERT INTO [QAD DATA
([WEEK],[DATE],[PART NAME],[QAD NUMBER],[SCRAP的原因] ],[LINE],[MACHINE],[TOOLING],[MTO],[QTY],[WHO SCRAP IT])VALUES(' + WEEK_TEXT.Text + ',' + DATEE_TEXT.Text + ',' + PictureBox1 + ' ,' + QAD_NUMBER_TEXT.Text + ',' + SCRAP_REASON_TEXT.Text + ',' + LINE_text.Text + ',' + MACHINE_TEXT.Text + ',' + SIDE_TEXT.Text + ',' + MTO_TEXT。文字+ ',' + QUANTITY_TEXT.Text + ',' + TL_TS_TEXT.Text + ')
' 创建连接对象以进行连接Excel工作簿
Dim connection As 新 OleDbConnection(connectionString)
Dim connection1 As 新 OleDbConnection(connectionString)
' 创建命令对象将执行insert语句
Dim 命令 As 新 OleDbCommand(insertStatement,connection)
Dim command1 As 新 OleDbCommand(insertStatement1,connection1)
' < span class =code-comment>打开连接,执行语句和关闭连接
connection.Open()
connection1.Open()
command.ExecuteNonQuery()
command1.ExecuteNonQuery()
connection.Close()
connection1.Close()
' 处理连接和命令对象
connection.Dispose()
command.Dispose()
command1.Dispose()
([WEEK], [DATE], [PART NAME], [QAD NUMBER], [REASON FOR SCRAP], [LINE], [MACHINE], [TOOLING], [MTO], [QTY], [WHO SCRAP IT]) VALUES ('" + WEEK_TEXT.Text + "','" + DATEE_TEXT.Text + "','" + PictureBox1 + "','" + QAD_NUMBER_TEXT.Text + "','" + SCRAP_REASON_TEXT.Text + "','" + LINE_text.Text + "','" + MACHINE_TEXT.Text + "','" + SIDE_TEXT.Text + "','" + MTO_TEXT.Text + "','" + QUANTITY_TEXT.Text + "','" + TL_TS_TEXT.Text + "')" 'Create a connection object to connect to the Excel Workbook Dim connection As New OleDbConnection(connectionString) Dim connection1 As New OleDbConnection(connectionString) 'Create a command object that will execute the insert statement Dim command As New OleDbCommand(insertStatement, connection) Dim command1 As New OleDbCommand(insertStatement1, connection1) 'Open the connection, execute the statement and close the connection connection.Open() connection1.Open() command.ExecuteNonQuery() command1.ExecuteNonQuery() connection.Close() connection1.Close() 'Dispose of the connection and command objects connection.Dispose() command.Dispose() command1.Dispose()
我尝试过:
我从网上查了很多代码,但是当我尝试将数据传输到单元格中的excel应该是图片时说
What I have tried:
I check many codes from the internet, but when I try to transfer data to excel in the cell where should be picture its say "
System.Drawing.Bitmap
Dim insertStatement As String = "INSERT INTO [DATA
这篇关于将图片从piturebox插入excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!