将Excel文件读入Access数据库的最佳方式 [英] Best way to read an Excel file into an Access database
问题描述
从Access 2007应用程序中读取(只读)Excel文件的最佳方式是什么。我只想循环移动行并将数据放入Access表。
What's the "best" way to read (just read) an Excel file from within an Access 2007 application. I only want to loop trough the rows and put the data into an Access table.
我不想手动导入(获取外部数据对话框),而是VBA。用户获取具有浏览按钮的窗体,然后指向具有定义的内容/格式的Excel文件。之后,VBA代码读取数据并将其放入Access数据库。
I don't want a manually import (Get External Data dialog) but by VBA. The user gets a Form with a Browse button and then points to a Excel file with a defined content/format. After that the VBA code reads the data and puts it into the Access database.
推荐答案
您可以尝试DoCmd.TransferSpreadsheet方法。
You could try the DoCmd.TransferSpreadsheet method.
DoCmd.TransferSpreadsheet acImport, , "from_excel","C:\Access\demo.xls", True
将电子表格数据导入名为from_excel的表格,并假定电子表格的第一行包含字段名称。请参阅访问TransferSpreadsheet或联机的帮助 here ,更多细节。
That imports spreadsheet data into a table named from_excel, and assumes the first row of the spreadsheet contains field names. See Access help for TransferSpreadsheet or online here, for more details.
这篇关于将Excel文件读入Access数据库的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!