![](/img/trans.png)
[英]How to read an Excel data file through Selenium without Interop and Microsoft Excel installed in the Local machine in C#?
[英]How to update excel input file directly in Azure Git repository without downloading the entire project folder to local machine
我在 Azure Z0BCC70105AD27957B66B7 中有一個 java maven 項目(Eclipse)。 這是一個基於 excel 中給出的輸入在系統中創建數據的測試項目。 目前,我已使用 git 在本地計算機上克隆了整個項目,更新輸入 excel 文件並推送到 Azure 存儲庫,然后再運行測試。 有沒有辦法直接在存儲庫中推送對輸入 excel 文件的更改,而無需將整個項目文件夾下載到本地?
也許,使用Azure DevOps Services REST / Pushes - Create
POST https://dev.azure.com/fabrikam/_apis/git/repositories/{repositoryId}/pushes?api-version=6.0
但與一個簡單的腳本相比,這似乎需要做很多工作,每次你在本地修改你的 Excel 文件時:
git add
git commit
git push
您可以使用 REST 和 Powershell 來更新遠程倉庫上的文件....例如:
$user = ""
$token = "<PAT>" #https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$orgUrl = "https://dev.azure.com/<org>"
$teamProject = "TestProject"
$repoName = "Repo1"
$localFilePath = 'c:/temp/tst.xlsx'
$gitFilePath = 'testfolder/tst.xlsx'
$gitBranch = "master"
$restApiUpdateFile = "$orgUrl/$teamProject/_apis/git/repositories/$repoName/pushes?api-version=6.1-preview.2"
$restApiGetMasterRef = "$orgUrl/$teamProject/_apis/git/repositories/$repoName/refs?filter=heads/$gitBranch`&api-version=6.1-preview.1"
$fileContentToUpdate = [convert]::ToBase64String((Get-Content -path $localFilePath -Encoding byte))
function InvokeGetRequest ($GetUrl)
{
return Invoke-RestMethod -Uri $GetUrl -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
}
function InvokePostRequest ($PostUrl, $body)
{
return Invoke-RestMethod -Uri $PostUrl -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body
}
$updateBody = @"
{
"refUpdates": [
{
"name": "refs/heads/{gitbranchpath}",
"oldObjectId": "{mainBranchObjectId}"
}
],
"commits": [
{
"comment": "Updates file",
"changes": [
{
"changeType": "edit",
"item": {
"path": "{filePathToUpdate}"
},
"newContent": {
"content": "{newFileContentToUpdate}",
"contentType": "base64encoded"
}
}
]
}
]
}
"@
$res = InvokeGetRequest $restApiGetMasterRef
$updateBody = $updateBody.Replace("{gitbranchpath}", $gitBranch);
$updateBody = $updateBody.Replace("{mainBranchObjectId}", $res.value[0].objectId);
$updateBody = $updateBody.Replace("{filePathToUpdate}", $gitFilePath);
$updateBody = $updateBody.Replace("{newFileContentToUpdate}", $fileContentToUpdate);
InvokePostRequest $restApiUpdateFile $updateBody
我們無法在 web 瀏覽器上的 Git 存儲庫中直接打開和編輯 Excel 文件。
我嘗試了幾個基於 Git 的版本控制平台(Azure Git Repos、GutHub、GitLab、Bitbucket 等)。 然后都不允許用戶直接打開和編輯 Git 存儲庫中的 Excel 文件。
我也沒有找到任何可用的擴展可以幫助做到這一點。
因此,您需要將Excel文件下載到MS Office安裝的本地,然后在本地打開並編輯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.