拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 如何在不将整个项目档案夹下载到本地机器的情况下直接在AzureGit存盘库中更新excel输入档案

如何在不将整个项目档案夹下载到本地机器的情况下直接在AzureGit存盘库中更新excel输入档案

白鹭 - 2022-01-23 1972 0 0

我在 Azure Git 存盘库中有一个 java maven 项目(Eclipse)。这是一个基于excel中给出的输入在系统中创建资料的测验项目。目前,在运行测验之前,我使用 git 在本地机器上克隆了整个项目,更新输入的 excel 档案并推送到 Azure 存盘库。有没有办法直接将更改推送到存盘库中的输入 excel 档案,而无需将整个项目档案夹下载到本地?

uj5u.com热心网友回复:

也许,使用如何在不将整个项目档案夹下载到本地机器的情况下直接在 Azure Git 存盘库中更新 excel 输入档案

...自然地,它会创建一个提交,但这很容易。我之前在没有 IDE 的情况下通过简单地在线编辑 repo 中的现有档案进行了代码更改。

uj5u.com热心网友回复:

您可以使用 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

uj5u.com热心网友回复:

我们没有办法直接在 Web 浏览器上打开和编辑 Git 存盘库中的 Excel 档案。

我尝试过几个基于 Git 的版本控制平台(Azure Git Repos、GutHub、GitLab、Bitbucket 等)。然后都不能允许用户直接打开和编辑 Git 存盘库中的 Excel 档案。

我也没有找到任何可用的扩展可以帮助做到这一点。

因此,您需要将 Excel 档案下载到安装 MS Office 的本地,然后在本地打开并编辑它。

标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *