以访问形式读取Excel文件并插入数据库 [英] Read excel file in access form and insert into database

查看:86
本文介绍了以访问形式读取Excel文件并插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个访问表,并且我必须阅读一个Excel文件(带有打开文件的对话框),
然后将行插入到当前数据库中.
请帮助我

I have a access form,and i must read an excel file(with open file dialog),
then insert rows into current db..

please help me

推荐答案

尝试类似的方法,

将MyRec调暗为DAO.Recordset
Dim xl作为Excel.Application
Dim xlsht作为Excel.Worksheet
Dim xlWrkBk作为Excel.Workbook



设置xl = CreateObject("Excel.Application")
设置xlWrkBk = GetObject("H:/ggg.xls")
设置xlsht = xlWrkBk.Worksheets(1)


myRec.AddNew
myRec.Fields("Test")= xlwrksht.cells(8,"E")
myRec.Fields("Test2")= xlwrksht.cells(9,"E")
myRec.Fields("Test3")= xlwrksht.cells(11,"E")
myRec.Update

或者,您也可以遍历行和列,从单元格中提取数据,然后将其插入数据库.
Try something like this,

Dim myRec As DAO.Recordset
Dim xl As Excel.Application
Dim xlsht As Excel.Worksheet
Dim xlWrkBk As Excel.Workbook



Set xl = CreateObject("Excel.Application")
Set xlWrkBk = GetObject("H:/ggg.xls")
Set xlsht = xlWrkBk.Worksheets(1)


myRec.AddNew
myRec.Fields("Test") = xlwrksht.cells(8, "E")
myRec.Fields("Test2") = xlwrksht.cells(9, "E")
myRec.Fields("Test3") = xlwrksht.cells(11, "E")
myRec.Update

or you can loop through the rows and columns, pull the data from the cells, and insert it into the database.


这篇关于以访问形式读取Excel文件并插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆