分享

使用Power Automate 的超快速更新 Excel

 F2967527 2023-06-20 发布于北京

Have you tried to update Excel from a Power Automate flow? This can be slow if you do this the wrong way.

Write to Excel files

In the past I write articles on reading large Excel files but so far I didn’t look at writing to excel files.

Like with the super fast reading of excel files using Microsoft Graph, you can do the same for data updates.

Json data example

I’m going to start by building a large json list of records. It doesn’t matter too much how complex the data is, the number of records is going to be the most limiting part that I’m going to look at within this post.

I’m starting by creating a Compose action and set its content to the following json.

[
  {
    "Title": "Title 1",
    "Description": "Description 1"
  },
  {
    "Title": "Title 2",
    "Description": "Description 2"
  },
  ...
  {
    "Title": "Title 19",
    "Description": "Description 19"
  },
  {
    "Title": "Title 20",
    "Description": "Description 20"
  }
]

This will result in json data displayed in the compose

Super Fast Update Excel using Power Automate Microsoft Office 365 image 28

Example Excel file

No that I have my json, I will prepare an Excel file in SharePoint with a table:

Super Fast Update Excel using Power Automate Microsoft Office 365 image 29

Now that all the prerequisites are in place it’s time to complete my flow.

The slow way to update Excel

With my 20 records of json I could create a row in my Excel using a flow like this:

超快速更新 Excel 使用 Power Automate Microsoft Office 365 图像 30

每个“将行添加到表中”操作大约需要 1 秒才能运行。该流程总共运行了 27 秒!

想象一下,如果您有 1000 条 json 记录。这将需要超过15分钟!

快速添加行

首先阅读 MS 图形的 向 Excel 添加行文档可能会很有用。

因此,我们需要从流调用以下端点。

https://graph.microsoft.com/v1.0/me/drive/root:/demo.xlsx:/workbook/tables/Table1/rows/add

在流中,您需要配置 Ms 图形身份验证。为此,我想参考其他帖子

现在棘手的一点来了!我们如何创建新记录。这并不明显!

您需要为请求创建一个如下所示的正文:

{"index":1,
 "values": [
  ["Title 1","Description 1"],
  ["Title 2","Description 2"]
  ]
}

好吧,这并不漂亮!

图形调用现在只会将数据添加到表中,并且不会验证列名称。您只需要提供数据,这些数据将被复制到表中。

将 JSON 转换为 JSON

要转换我的 json,我将配置我的流以使用选择操作

超快速更新 Excel 使用 Power Automate Microsoft Office 365 图像 33

在上面的操作中,我使用以下代码为我的选择映射中的每条记录获取正确的信息。

[
  @{item()['Title']},
  @{item()['Description']}
]

现在,这在 0 秒内为我生成以下 json

超快速更新 Excel 使用 Power Automate Microsoft Office 365 图像 31

这让我在一个动作中获得了完全正确的格式。这应该是一个非常快速的流程,因为我几乎不需要任何操作。还记得等待流程完成的 15 分钟吗?此流程将在几秒钟内运行!

对图形 API 的调用

现在,我需要做的就是配置 HTTP 请求以在 SharePoint 中更新我的 excel 文件。有关 MS 图形调用的详细信息,请查看用于写入 excel 文件的图形 api 调用。

使用来自电源自动化的 MS 图形调用更新 excel

上述 URI 设置为以下详细信息。

https://graph.microsoft.com/v1.0/sites/pieterveenstramvp.sharepoint.com/lists/a8bcb564-c8f1-4c88-9324-bb872bd6bbfc/drive/root:/book1.xlsx:/workbook/tables/Table1/rows/add

您可以识别我使用的 excel 文件的网站 URL、列表 ID 和名称。在我的 excel 文件中还有一个名为 Table1 的表。这是我将使用我的电源自动化流更新的表。

最后,将正文设置为以下代码。这是我使用 http 请求中使用的选择操作生成的输出的地方。

{
  "index": 1,
  "values": @{body('Select')}
}

现在,当我运行流程时,它会在 2 秒内完成。比原来的15分钟好多了!

更多 Power Automate Excel 帖子

https:///2020/08/04/populate-excel-template-power-automate/

喜欢这个:

Like 装载。。。

相关

使用“自动功能”更快地填充 1 个 Excel 模板

Over the last week I've had multiple clients asking me about populating Excel template files with data. Excel templates There are a couple of things that we first need to have a look at. I'm going to split up all the requirements into smaller requirements. For a lot of the…

在“Microsoft Power Automate”中

使用 Power Automate 比较 2 个 Excel 文件

使用 Power Automate 比较 2 个 Excel 文件

This is such a common scenario. You receive Excel files on a regular basis and you want to compare the files collect the new rows with Power Automate. SharePoint Setup I'm starting this Tutorial with the creation of my two Excel files in SharePoint. You could also create them in…

在“Microsoft Office 365”中

Power Automate – 在几秒钟内读取大型 Excel 文件,而无需使用 Microsoft Graph 创建表格

In Microsoft Flow it is possible to use the Excel connectors to read data form a spreadsheet. When you want to read large Excel files you might run into issues. Excel connector issues There few major issues with the excel connector are:  You data needs to exist within Excel Tables.…

在“微软流”中

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多