繁体   English   中英

将 Excel 数据从 SharePoint 导入 Powershell

[英]Import Excel Data into Powershell from SharePoint

我在PowerShell中大量使用ImportExcel模块,它适用于本地和本地同步文件。 我很少有 Teams/SharePoint 库与我的 OneDrive 同步,我在这些行中使用了一些东西来导入 excel 数据,然后直接在 PowerShell 中操作它们(路径、文件名和链接是虚构的):

$File    = "C:\Users\Username\OneDriveFolder\File.xlsm"
$Sheet   = "Sheet1" 
$DataSet = Import-Excel -Path $File -WorkSheetname $Sheet -DataOnly -StartRow 2
$Data    = "Example"
$Query   =  $DataSet.Where({$_.$Data -like $Data})

I was wondering if it is was possible to use a SharePoint URL instead of a local path for the -Path attribute since I would like to import data from an Excel that is located on a SharePoint but it is not synced to my OneDrive:

$File    = "https://companygroup.sharepoint.com/sites/sitefolders/File.xlsm"
$Sheet   = "Sheet1" 
$DataSet = Import-Excel -Path $File -WorkSheetname $Sheet -DataOnly -StartRow 2
$Data    = "Example"
$Query   =  $DataSet.Where({$_.$Data -like $Data})

如果我尝试这样做,我会收到一个找不到文件的错误:

'https://companygroup.sharepoint.com/sites/sitefolders/File.xlsm' file not found
At C:\Program Files\WindowsPowerShell\Modules\ImportExcel\7.4.1\Public\Import-Excel.ps1:118 char:21
+                     throw "'$($Path)' file not found"
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: ('https://company... file not found:String) [], RuntimeException
    + FullyQualifiedErrorId : 'https://companygroup.sharepoint.com/sites/sitefolders/File.xlsm' file not found

有没有办法像这样使用ImportExcel模块? 如果它仅适用于本地/本地同步的文件,是否有替代方法来做我想做的事情?

谢谢

感谢一个讨论类似内容的页面,设法找到了方法: https://docs.microsoft.com/en-us/answers/questions/741691/how-to-load-and-read-excel-file-hosted -in-sharepoi.html

您只需像输入本地路径一样键入链接,例如:

$File    = "\\companygroup.sharepoint.com\sites\siteFolders\File.xlsm"
$Sheet   = "Sheet1" 
$DataSet = Import-Excel -Path $File -WorkSheetname $Sheet -DataOnly -StartRow 2
$Data    = "Example"
$Query   =  $DataSet.Where({$_.$Data -like $Data})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM