PowerAutomate: *.xls → *.xlsx 変換（3rd Party Connector）

# 背景
以下の記事で必要となった、*.xls → *.xlsx の変換コネクターの動作確認
3rd Party 製なので会社の DLP　上は使えないんですが・・

外部のオープンデータなら、自宅環境で変換かけて、変化検知時に送り込めば自動化は出来るな、と思い直しての動作確認

https://qiita.com/baku2san/items/45245c7cbe6bf7288fde

ちなみに、PAD の場合は以下

https://qiita.com/baku2san/items/01adccbff94156133ef0

# 概要
世の中そんなうまい方法ない・・ってのが結論。

- [plumsail](https://docs.microsoft.com/ja-jp/connectors/plumsail/) コネクターを使って変換
いい感じなんだけど、一定数無償、とかではないので、この用途には使いたくない、という結論に・・

- [Cloudmersive](https://docs.microsoft.com/ja-jp/connectors/cloudmersiveconvert/#convert-excel-xls-(97-03)-spreadsheet-to-xlsx) コネクターを使って変換
動けば、Free Tier もあっていいんだけど・・同一フローで何故か 10回に 1回以下の正常動作。
原因がわからないので使えず・・


# 制約と価格
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/a0d7cfa7-e53b-0974-02d1-c6aa9965c92c.png)

## [plumsail](https://docs.microsoft.com/ja-jp/connectors/plumsail/) コネクター
有償 30day Free Trial
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/eae3c502-eb06-f645-0f48-e00512d0b33d.png)

https://plumsail.com/actions/store/

## [Cloudmersive](https://docs.microsoft.com/ja-jp/connectors/cloudmersiveconvert/#convert-excel-xls-(97-03)-spreadsheet-to-xlsx) コネクター
無償で全然いける。ただ、会社用はアウト

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/9b25d9a9-41e0-43db-94c1-d5c06774add0.png)

https://cloudmersive.com/pricing

# 試行例

## plumsail

以下で [plumsail にログイン](https://docs.microsoft.com/ja-jp/connectors/plumsail/#register-account)：既存の Google/Microsoft アカウントで連携もOK

https://auth.plumsail.com/account/login?returnUrl=https://account.plumsail.com/documents/help

[API キーの生成](https://docs.microsoft.com/ja-jp/connectors/plumsail/#generate-api-key)

1. API Keys ページへ
1. Add new で、新規追加
1. コピーしておく

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/f9222c94-e77a-2469-406e-f5207115998d.png)

Connector にて接続情報をコピペ
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/f9a1d9d2-7d40-1dc3-1679-b7f9ea547e14.png)

あとは、Content を渡すだけなので、外部ファイルの場合は、以下のようにすれば完了
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/3b202da3-4f5d-baf6-d953-312d3554a11d.png)

### クリップボードコピペ用

https://qiita.com/baku2san/items/ad4f7fa744d104b23f50

```json: 外部オープンデータの xls → xlsx 変換
{"id":"5823509b-86f7-4db9-ab71-ca99576fb743","brandColor":"#8C3900","connectionReferences":{"shared_onedriveforbusiness":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness/connections/shared-onedriveforbu-60023b13-318a-4e0f-a004-302d9501e437"}},"shared_plumsail":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_plumsail/connections/shared-plumsail-99e4b27a-ce01-4129-9f2b-4d194c37e75f"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"外部オープンデータの_xls_→_xlsx_変換","operationDefinition":{"type":"Scope","actions":{"Upload_file_from_URL":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"CopyFile","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"source":"https://media.japanmetaldaily.com/data/KS10001.xls","destination":"ForAutomate/ConvertXls2Xlsx/KS10001.xls","overwrite":true},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{}},"Get_file_content":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"GetFileContent","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"id":"@outputs('Upload_file_from_URL')?['body/FileLocator']","inferContentType":true},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{"Upload_file_from_URL":["Succeeded"]}},"Convert_XLS_to_XLSX":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_plumsail","operationId":"FlowV1DocumentsJobsXls2XlsxPost","apiId":"/providers/Microsoft.PowerApps/apis/shared_plumsail"},"parameters":{"request/documentContent":"@body('Get_file_content')"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{"Get_file_content":["Succeeded"]}},"Create_file":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"CreateFile","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"folderPath":"/ForAutomate/ConvertXls2Xlsx","name":"KS10001.xlsx","body":"@body('Convert_XLS_to_XLSX')"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{"Convert_XLS_to_XLSX":["Succeeded"]},"runtimeConfiguration":{"contentTransfer":{"transferMode":"Chunked"}}}},"runAfter":{}}}
```

### 参考
https://docs.microsoft.com/ja-jp/connectors/plumsail/#actions

## [Cloudmersive](https://docs.microsoft.com/ja-jp/connectors/cloudmersiveconvert/#convert-excel-xls-(97-03)-spreadsheet-to-xlsx) コネクター
ほぼ同様なので省略

以下の例のように、成功・失敗でのフローの利用方法の差異が無く、Automate ではどうしようもないかなぁ・・と

### 成功例
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/1f48f107-c241-da39-235f-34e6fb78866f.png)

### 失敗例

成功例で、そのまま Resubmit するだけでエラーになる。

> The response is not in a JSON format.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/a3f2bd78-3b6d-cc05-7822-114cfd94488b.png)

> 1 Calls/Second 

ここに引っかかってるのかと思ったが、秒単位だし、ファイルも小さいので全然問題なさそう・・

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/930fc05c-b1d0-2630-22f7-ce35e80ebbd7.png)

## [Cloudmersive](https://docs.microsoft.com/ja-jp/connectors/cloudmersiveconvert/#convert-excel-xls-(97-03)-spreadsheet-to-xlsx) を HTTP Post で直接
提供されてるコネクターに問題があるのかと思い、HTTP POST で直接実行してみる
### 成功例 by HTTP
初っ端成功して、やっぱりコネクターか？と思った・・が、
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/809d5437-553b-fcf3-8d46-0b6c0449ea4b.png)

Resubmitするだけで、以下のようなエラーになる・・
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/d1ff9827-891e-6aa5-5904-c69bdd5db97a.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/120072/51b8d3cd-3a1b-1d80-29e0-c06ae8f56615.png)

ということで、諦め

# あとがき
どちらにせよ、個人利用じゃないと後者のコネクターも使えないので、今回は諦めて手動更新・・かな・・

# keyword
how to convert xls to xlsx by Power Automate instead of Power Automate Desktop