怎么用excel和access实现局域网数据库?
研究了半天,都摸不到头脑,希望大家能帮下忙。
用excel通过局域网链接到access上其实我已经做到了,只是有个问题,就是当excel表打开的时候,access数据库就不能写入了,只有关掉excel表才能写数据,不知道为什么,有没有什么办法能解决的? 展开
2015-06-28 · 知道合伙人互联网行家
知道合伙人互联网行家
向TA提问 私信TA
您好,方法有很多的
例如
局域网中有Sharepoint服务端,可以直接通过Excel访问服务端上的数据库,
如下图,但Sharepoint似乎并不是非常普及,所以还提供了其他方法
以下是最适合新手的最简方法,只要求Excel/Access及局域网的通畅不需要其他工具或知识,假设要与Access连接的Excel表格如下:
3.打开Access,点击外部数据(如下图所示),再点击Excel(如下图所示)
4.点击【浏览】或直接输入Excel路经,局域网中要先将Excel文档共享,
选中【通过创建链接表....】项,单击【确定】
5.如果Excel中数据包含分类标题,例如“姓名”、"性别"等,请勾选【第一行包含标题】,点击【下一步】或【完成】即可完成对接
注意:
1.此方法的缺点在于仅限单向连接,即Excel端发生更改,Access端可同步接收Excel的数据变动,但在Access端无法对数据进行操作
2.务必常常对Access进行存档,否则Excel端关闭后Access端可能发生数据丢失
拓展:
另外还可以通过VB创建控件的方法,在IE中进行数据的浏览与更改,此方法将同时同步Excel与Access中的数据,但需要一定的VB编程基础,这里提供源码,有兴趣可以研究研究,并不是很难
Imports System
Imports System.Windows.Forms
Imports Microsoft.Office.Excel.WebUI
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebPartPages
Namespace AddEWATool
''' <summary>
''' Form1 class derived from System.Windows.Forms.
''' </summary>
Partial Public Class Form1
Inherits Form
Private appName As String = "AddEWATool"
Private specifyInputError As String = "Please add a site URL, for example, http://myserver/site/"
Private openSiteError As String = "There was a problem with the site name. Please check that the site exists."
Private addWebPartError As String = "There was a problem adding the Web Part."
Private successMessage As String = "Web Part successfully added."
''' <summary>
''' Add the Excel Web Access Web Part to the Default.aspx page of the specified site.
''' </summary>
''' <param name="siteName">URL of the SharePoint site</param>
''' <param name="book">URI to the workbook</param>
''' <returns>Returns true if the WebPart was successfully added; otherwise, false.</returns>
Public Function AddWebPart(ByVal siteName As String, ByVal book As String) As Boolean
Dim site As SPSite = Nothing
Dim targetWeb As SPWeb = Nothing
Dim webPartManager As SPLimitedWebPartManager = Nothing
Dim b As Boolean = False
progressBar1.Visible = True
progressBar1.Minimum = 1
progressBar1.Maximum = 4
progressBar1.Value = 1
progressBar1.Step = 1
If String.IsNullOrEmpty(siteName) Then
MessageBox.Show(specifyInputError, appName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Return b
End If
Try
Try
site = New SPSite(siteName)
targetWeb = site.OpenWeb()
Catch exc As Exception
MessageBox.Show(openSiteError & vbLf & exc.Message, appName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
progressBar1.Value = 1
Return b
End Try
progressBar1.PerformStep()
Try
' Get the shared Web Part manager on the Default.aspx page.
webPartManager = targetWeb.GetLimitedWebPartManager( _
"Default.aspx", _
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared)
Catch exc As Exception
MessageBox.Show(openSiteError & vbLf & exc.Message, appName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
progressBar1.Value = 1
Return b
End Try
progressBar1.PerformStep()
'Instantiate Excel Web Access Web Part.
'Add an Excel Web Access Web Part in a shared view.
Dim ewaWebPart As New ExcelWebRenderer()
ewaWebPart.WorkbookUri = book
progressBar1.PerformStep()
Try
webPartManager.AddWebPart(ewaWebPart, "Left", 0)
Catch exc As Exception
MessageBox.Show(addWebPartError & vbLf & exc.Message, appName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
progressBar1.Value = 1
Return b
End Try
Finally
If Not IsNothing(site) Then
site.Dispose()
End If
If Not IsNothing(targetWeb) Then
targetWeb.Dispose()
End If
If Not IsNothing(webPartManager) Then
webPartManager.Dispose()
End If
End Try
progressBar1.PerformStep()
b = True
Return b
End Function
''' <summary>
''' AddEWAButton click handler.
''' </summary>
''' <param name="sender">caller</param>
''' <param name="e">event</param>
Private Sub AddEWAButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim siteUrl As String = textBox1.Text
Dim bookUri As String = textBox2.Text
Dim succeeded As Boolean = AddWebPart(siteUrl, bookUri)
If succeeded Then
MessageBox.Show(successMessage, appName, MessageBoxButtons.OK, MessageBoxIcon.Information)
progressBar1.Value = 1
End If
End Sub
End Class
End Namespace
将服务器上的数据库放到一个共享目录,设置为只读属性。
客户机打开EXCEL,在数据菜单里面选择导入外部数据,在打开的对话框里面,选择网上邻居,找到那个目录,打开数据库,导入数据库对话框点确定。就把数据导入进来了。
保存这个EXCEL文件。下次打开的时候,在导入的数据上面点右键,有个刷新数据。就可以看到数据库里面的最新数据。