良渚新城城北副中心:VB实现从EXECL中上传到SQLSERVER,跪求答案,谢谢.

来源:百度文库 编辑:神马品牌网 时间:2024/04/24 15:20:00
VB实现从EXECL中上传到SQLSERVER,如何定位EXECL中的具体单元格啊.我的做法是把EXECL的单元格放入数组中,再上传到SQL的存储过程中,让存储过程来筛选数据.跪求答案(假如能有完整的答案更好),谢谢.
可否给出更具体的代码,具体过程是:将EXECL中某一列的数据传给一个值,然后通过VB传给SQL的存储过程,最后由数据过程筛选数据.判断哪些写入.存储过程就不用给出来了.VB阶段的代码.谢谢

我有导出的例子,也许会对你有帮助
Private Function ExportDetail(strFileName As String) As Boolean

Dim iRow As Long
Dim myExcel As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

On Error GoTo ErrAction
ExportDetail = False

Set myExcel = New Excel.Application
myExcel.Visible = False
myExcel.SheetsInNewWorkbook = 1
Set xlBook = myExcel.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)

xlSheet.Columns.ClearFormats
xlSheet.Cells(1, 1) = "物料BOM【" & TreeFile.SelectedItem.Text & "】"
xlSheet.Range("A1:U1").MergeCells = True

xlSheet.Cells(2, 1) = "标题项"
xlSheet.Cells(2, 2) = "中文名称"
xlSheet.Cells(2, 3) = "英文名称"
xlSheet.Cells(2, 4) = "文档号"
xlSheet.Cells(2, 5) = "物料号"
xlSheet.Cells(2, 6) = "数量"
xlSheet.Cells(2, 7) = "总数量"
xlSheet.Cells(2, 8) = "单位"
xlSheet.Cells(2, 9) = "物料关联文档1"
xlSheet.Cells(2, 10) = "物料关联文档2"
xlSheet.Cells(2, 11) = "所属装配文档号"
xlSheet.Cells(2, 12) = "所属装配物料号"
xlSheet.Cells(2, 13) = "装配物料关联文档1"
xlSheet.Cells(2, 14) = "装配物料关联文档2"
xlSheet.Cells(2, 15) = "物料技术参数"
xlSheet.Cells(2, 16) = "物料类型"
xlSheet.Cells(2, 17) = "物料备注"
xlSheet.Cells(2, 18) = "重量"
xlSheet.Cells(2, 19) = "备注"
xlSheet.Cells(2, 20) = "清单文档号"
xlSheet.Cells(2, 21) = "工艺分工"

For iRow = 1 To DocList.ListItems.Count
xlSheet.Cells(iRow + 2, 1) = DocList.ListItems(iRow).ListSubItems(1)
xlSheet.Cells(iRow + 2, 2) = DocList.ListItems(iRow).ListSubItems(2)
xlSheet.Cells(iRow + 2, 3) = DocList.ListItems(iRow).ListSubItems(3)
xlSheet.Cells(iRow + 2, 4) = DocList.ListItems(iRow).ListSubItems(4)
xlSheet.Cells(iRow + 2, 5) = DocList.ListItems(iRow).ListSubItems(5)
xlSheet.Cells(iRow + 2, 6) = DocList.ListItems(iRow).ListSubItems(6)
xlSheet.Cells(iRow + 2, 7) = DocList.ListItems(iRow).ListSubItems(7)
xlSheet.Cells(iRow + 2, 8) = DocList.ListItems(iRow).ListSubItems(8)
xlSheet.Cells(iRow + 2, 9) = DocList.ListItems(iRow).ListSubItems(9)
xlSheet.Cells(iRow + 2, 10) = DocList.ListItems(iRow).ListSubItems(10)
xlSheet.Cells(iRow + 2, 11) = DocList.ListItems(iRow).ListSubItems(11)
xlSheet.Cells(iRow + 2, 12) = DocList.ListItems(iRow).ListSubItems(12)
xlSheet.Cells(iRow + 2, 13) = DocList.ListItems(iRow).ListSubItems(13)
xlSheet.Cells(iRow + 2, 14) = DocList.ListItems(iRow).ListSubItems(14)
xlSheet.Cells(iRow + 2, 15) = DocList.ListItems(iRow).ListSubItems(15)
xlSheet.Cells(iRow + 2, 16) = DocList.ListItems(iRow).ListSubItems(16)
xlSheet.Cells(iRow + 2, 17) = DocList.ListItems(iRow).ListSubItems(17)
xlSheet.Cells(iRow + 2, 18) = DocList.ListItems(iRow).ListSubItems(18)
xlSheet.Cells(iRow + 2, 19) = DocList.ListItems(iRow).ListSubItems(19)
xlSheet.Cells(iRow + 2, 20) = DocList.ListItems(iRow).ListSubItems(20)
xlSheet.Cells(iRow + 2, 21) = DocList.ListItems(iRow).ListSubItems(21)
Next

xlSheet.Columns.AutoFit
xlSheet.Rows(2).Font.Bold = True
xlBook.SaveAs strFileName
myExcel.Quit
Set myExcel = Nothing

ExportDetail = True
Exit Function

ErrAction:
ExportDetail = False
MsgBox "导出失败:" & Err.Description, vbCritical, "导出到EXCEL"
End Function

一般也就是这种办法了,虽然不是很简单但是实用

要想方便还是导如ACCESS数据库操作

针对将Excel各单元格的内容读入到数组中:
Set xlapp = GetObject(FileName)
xlapp.Parent.Windows(1).Visible = True
Array[Index]=xlapp.Application.Worksheets(1).Cells(1, 5).value

我的BLOG上有一点,你可以去看一下
hi.baidu.com/toven