简体   繁体   English

如何直接在 Azure Git 存储库中更新 excel 输入文件,而无需将整个项目文件夹下载到本地计算机

[英]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

Just upload it directly...直接上传就行了...

上传

... naturally, it will create a commit but this is easy enough. ...自然,它会创建一个提交,但这很容易。 I've made code changes before without an IDE by simply editing existing files in the repo online.我之前在没有 IDE 的情况下通过简单地在线编辑存储库中的现有文件进行了代码更改。

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.

相关问题 如何通过Selenium读取一个Excel的数据文件,而C#的本机没有安装Interop和Microsoft Excel? - How to read an Excel data file through Selenium without Interop and Microsoft Excel installed in the Local machine in C#? Azure 机器学习工作室:如何从本地 Excel 文件添加数据集? - Azure Machine Learning Studio: how to add a dataset from a local Excel file? 如何直接在服务器中更新供应商文件,例如本地中的作曲家更新 - How to update vendor file directly in server like composer update in local 如何在不下载的情况下将excel文件保存在php的本地目录中 - how to save excel file in my local directory in php with out downloading 如何将大量的excel文件从虚拟机服务器复制粘贴到本地计算机? - How do I copy-paste a massive excel file from a virtual machine server to my local machine? 直接在Excel中下载股价 - Downloading share prices directly in excel 如何在不创建本地文件的情况下使用 OpenXML 创建 Excel 文件? - How to create Excel file using OpenXML without creating a local file? 从谷歌驱动器读取 excel 文件而不下载文件 - Read excel file from google drive without downloading file 我们如何使用Excel VBA将一个文件从远程桌面复制到本地计算机 - How can we copy a one file from Remote desktop to local machine using Excel VBA 如何生成excel文件(xls)并将其保存到服务器位置而不使用ColdFusion下载 - How to generate excel file (xls) and save it to a server location without downloading it using ColdFusion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM