如何使用代码将SharePoint列表导出到Excel

时间:2019-01-21 22:20:50

标签: sharepoint-2013

我找到了上一个问题,它看起来正是我要寻找的。但是,当我运行代码时,出现调试错误(突出显示urlpatterns = [ path('', FilmListView.as_view(), name='search-home'), path('films/', SearchedFilmListView.as_view(), name='searched-films'), path('user/<str:username>', UserFilmListView.as_view(), name='user-films'), path('film/<int:pk>/', FilmDetailView.as_view(), name='film-detail'), path('film/new/', FilmCreateView.as_view(), name='film-create'), path('film/<int:pk>/update/', FilmUpdateView.as_view(), name='film-update'), path('film/<int:pk>/delete/', FilmDeleteView.as_view(), name='film-delete'), path('about/', views.about, name='search-about'), ] 的最后一行。以下是我用于特定路径和GUID的代码。我尝试调整共享点地址,但列出了一个是指向该库的那个。我也只尝试了家庭地址(在“ TEP”处停止),并一直尝试包含“ All Items.aspx”。我敢肯定我缺少了一些“简单”的东西,但是以为我会在这里问。

"Set ObjMyList . . . . ("A1"))"

1 个答案:

答案 0 :(得分:0)

下面的代码在我的本地计算机上可用

Sub ExportList()
    Dim objWksheet As Worksheet
    Dim strSPServer As String
    Const SERVER As String = "sp/sites/team"
    Const LISTNAME As String = "{3e47ff9c-9aab-4a40-9d6a-c47e9b793484}" 'From source code
    Const VIEWNAME As String = "{67709eda-c975-4669-85e5-d95e263dadc6}" 'From source code

   ' The SharePoint server URL pointing to the SharePoint list to import into Excel.
    strSPServer = "http://" & SERVER & "/_vti_bin"
    Set objWksheet = Sheets("Sheet1")
    ' Add a list range to the newly created worksheet
    ' and populated it with the data from the SharePoint list.
    Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, Array(strSPServer, LISTNAME, VIEWNAME), True, , Range("A1"))
    Set objMyList = Nothing
    Set objWksheet = Nothing
End Sub