[英]How to update excel input file directly in Azure Git repository without downloading the entire project folder to local machine
I have a java maven project (Eclipse) in Azure Git repository.我在 Azure Z0BCC70105AD27957B66B7 中有一个 java maven 项目(Eclipse)。 It is a test project to create data in system based on the input given in the excel.
这是一个基于 excel 中给出的输入在系统中创建数据的测试项目。 Currently I have the entire project cloned in local machine with git, update the input excel file and push to Azure repository, before running the test.
目前,我已使用 git 在本地计算机上克隆了整个项目,更新输入 excel 文件并推送到 Azure 存储库,然后再运行测试。 Is there a way to push changes to the input excel file directly in repository, without downloading the entire project folder to local?
有没有办法直接在存储库中推送对输入 excel 文件的更改,而无需将整个项目文件夹下载到本地?
Maybe, using the Azure DevOps Services REST / Pushes - Create也许,使用Azure DevOps Services REST / Pushes - Create
POST https://dev.azure.com/fabrikam/_apis/git/repositories/{repositoryId}/pushes?api-version=6.0
But that seems a lot of work compared to a simple script which would, every time you have modified locally your Excel file:但与一个简单的脚本相比,这似乎需要做很多工作,每次你在本地修改你的 Excel 文件时:
git add
git commit
git push
You can use REST and Powershell to update files on remote repo.... as an example:您可以使用 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
We have no method to directly open and edit an Excel file in Git repository on the web browser.我们无法在 web 浏览器上的 Git 存储库中直接打开和编辑 Excel 文件。
I have tried on several Git-based version control platforms (Azure Git Repos, GutHub, GitLab, Bitbucket, etc..).我尝试了几个基于 Git 的版本控制平台(Azure Git Repos、GutHub、GitLab、Bitbucket 等)。 None of then can allow users to directly open and edit an Excel file in Git repository.
然后都不允许用户直接打开和编辑 Git 存储库中的 Excel 文件。
I also did not find any available extension can help to do this.我也没有找到任何可用的扩展可以帮助做到这一点。
So, you need to download the Excel file to the local where the MS Office installed, then open and edit it locally.因此,您需要将Excel文件下载到MS Office安装的本地,然后在本地打开并编辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.