UiPath Documentation
studiox
2020.10
false
StudioX ユーザー ガイド
重要 :
このコンテンツの一部は機械翻訳によって処理されており、完全な翻訳を保証するものではありません。 新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。

チュートリアル: Word の操作を自動化する

このチュートリアルでは、チームの各メンバーに対する個人別実績レビューを Word 文書として生成するオートメーション プロジェクトを作成します。この Word 文書は、テンプレートの Word ファイルと、複数の Excel およびテキスト ファイルから収集したデータに基づいて生成します。テンプレート ファイルには Word アクティビティを使用して値を入力することのできる、プレースホルダーのテキストとブックマークが設定されています。データのコピー元となる Excel とテキスト ファイルの名前は、従業員名を含む特定のパターンに従っているものとします。

[ Excel ファイルを使用 ] アクティビティをオートメーション プロジェクトに追加して、追加する従業員情報が記載された Excel ファイルを指定することから始めます。その中に、従業員データが含まれる行を反復処理するために [ 繰り返し (Excel の各行 )] アクティビティを追加します。[繰り返し (Excel の各行)] 内で、[ Word ファイルを使用 ] アクティビティでテンプレート ドキュメントをオートメーション プロジェクトに追加し、[ テキストを置換]、[ ブックマークのコンテンツを設定]、[ ドキュメントにデータテーブルを挿入 ] の一連のアクティビティで、Excel ファイルとテキスト ファイルから Word ファイルに各従業員に必要な情報を入力します。最後に、テンプレート ドキュメントを従業員ごとに別のファイルとして保存するために、[ 名前を付けて Word ファイルを保存 ] アクティビティを追加します。

  1. 手順 1: プロジェクトを設定し、必要なファイルを取得する

    1. Create a new blank project using the default settings.
    2. このチュートリアルでは、このページ下部にあるボタンを使用して、オートメーション プロジェクトを収めたアーカイブをダウンロードして展開します。プロジェクト フォルダーに Files フォルダーをコピーします。
    3. プロジェクト フォルダーに Output という名前のフォルダーを作成します。
  2. 手順 2: 従業員データを含む Excel ファイルをプロジェクトに追加し、ファイル内の行を反復処理する

    1. In StudioX, click Add activity ドキュメントの画像 in the Designer panel, and then find the Use Excel File activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.

    2. アクティビティで次の操作を行います。

      • Click Browseドキュメントの画像 next to the Excel file field, and then browse to the Files folder and select the file Employees.xlsx.

      • [参照名] フィールドに「EmployeeData」と入力します。

        これで、このオートメーションでは名前を EmployeeData としたファイル Employees.xlsx を操作対象として指定したことになります。

    3. Click Add activity ドキュメントの画像 inside Use Excel File, and then find the For Each Excel Row activity in the search box at the top of the screen and select it. The activity is added to the Designer panel inside the Use Excel File activity.

    4. [繰り返し (Excel の各行)] アクティビティで、次の操作を行います。

      • [繰り返し] テキスト ボックスの CurrentRowEmployee に置換します。

      • [ ドキュメントの画像対象範囲] フィールドの右側にある プラス 記号 をクリックし、[ EmployeeData > Sheet1 [シート]] を選択します。

        これで、Employees スプレッドシートの Sheet1 の行に対して反復処理を実行するように指定したことになります。各行には 1 名の従業員に関する情報が含まれているため、反復処理の現在の行の名前を Employee に変更しました。これは、オートメーション プロジで行に含まれる情報を識別しやすくするためです。

  3. 手順 3: テンプレートの Word ファイルをオートメーション プロジェクトに追加する

    1. Click Add activity ドキュメントの画像 inside For Each Excel Row, and then find the Use Word File activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.

    2. [Word ファイルを使用] アクティビティで、次の操作を行います。

      • Click Browseドキュメントの画像 next to the Word file field, and then browse to the Files folder and select the file PerformanceReviewDoc_template.docx.

      • [自動保存] のチェック ボックスをオフにします。これにより、各従業員のデータが追加された状態でテンプレート ファイルが保存されてしまうのを確実に避けることができます。

        ここでは、PerformanceReviewDoc_template.docx というファイルを使用して作業するように指定しました。

  4. 手順 4: 従業員データを含む Excel ファイルから Word ファイルに情報を追加する

    1. Click Add activity ドキュメントの画像 inside Use Word File, and then find the Replace Text activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.

    2. [テキストを置換] アクティビティで、次の操作を行います。

      • Click Plusドキュメントの画像 on the right side of the Search for field, and then select Text. In the Text Builder, enter <<FullName>>.

      • [ドキュメントの画像 次で置換] フィールドの右側にある プラス 記号 をクリックし、[ Employee (従業員の> フルネーム)] を選択します。

        ここでは、Word ファイル内のプレースホルダー テキスト <<FullName>> を、Excel ファイル Employees (従業員) の Full Name (フル ネーム) 列のセルからコピーした各従業員のフル ネームで置き換えるように指定しました。

    3. Click Add activity ドキュメントの画像 below the Replace Text activity, and then find the Set Bookmark Content activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.

    4. [ブックマークのコンテンツを設定] アクティビティで、次の操作を行います。

      • Click Plusドキュメントの画像 on the right side of the Bookmark name field, and then select Text. In the Text Builder, enter DirectManager.

      • [ドキュメントの画像 ブックマーク] テキスト フィールドの右側にある プラス 記号 をクリックし、[ Employee > Direct Manager] を選択します。

        ここでは、各従業員について、Excel ファイル Employees (従業員) の Direct Manager (課長) 列のセルの内容をコピーし、Word ファイルのブックマーク DirectManager (課長) の場所に貼り付けることで、Word ファイルに直属の上司の名前を追加するように指定しました。

    5. ステップ 3 ~ 4 を 3 回繰り返し、各従業員の Full Name (フル ネーム)、Location (勤務地)、Title (役職) を Word ファイルに追加する [ブックマークのコンテンツを設定] アクティビティを追加します。各アクティビティを次のように設定します。

      • [ブックマーク名] FullName、[ブックマーク テキスト] Employee > Full Name

      • [ブックマーク名] Location、[ブックマーク テキスト] Employee > Location

      • [ブックマーク名] PositionTitle、[ブックマーク テキスト] Employee > Position Title

  5. 手順 5: プロジェクトに関するデータを含む Excel ファイルから Word ファイルに情報を追加する

    1. Click Add activity ドキュメントの画像 below the last Set Bookmark Content, and then find the Use Excel File activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.

    2. [Excel ファイルを使用] アクティビティで次の操作を行います。

      • [ ドキュメントの画像Excel ファイル] フィールドの右側にある プラス 記号 をクリックし、[ テキスト] を選択します。

        テキスト ビルダーで

        1. Files\」と入力します。

        2. Click Plusドキュメントの画像 on the right side of the Text Builder, and then select Employee > Full Name.

        3. _Projects.xlsx」と入力します。

          テキストは「Files\[Employee]FullName_Projects.xlsx」のようになります。

        4. テキスト ビルダーで [保存] をクリックします。

      ここでは、従業員ごとにプロジェクトの Excel ファイルをオートメーション プロジェクトに追加するように指定しました。Excel ファイルの選択では動的なファイル パスを使用し、プロジェクト ファイルを使用するアクティビティでデータを選択できるように、ファイルの 1 つをテンプレート ファイルとして指定しました。

    3. Click Add activity ドキュメントの画像 inside the newly added Use Excel File activity, and then find the Insert DataTable in Document activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.

    4. [ドキュメントにデータテーブルを挿入] アクティビティで、次の操作を行います。

      • Click Plusドキュメントの画像 on the right side of the Table to insert field, and then select Projects > Sheet1 [Sheet] > Table1 [Table].
      • [次を基準にして挿入] ドロップダウン メニューから [ブックマーク] を選択します。
      • Click Plusドキュメントの画像 on the right side of the Bookmark to search for field, and then select Text. In the Text Builder, enter Projects.
      • [挿入位置] ドロップダウン メニューから [後] を選択します。

      これで、各従業員について、Projects Excel ファイルから Table1 をコピーし、Word ファイルの Projects という名前のブックマークの後に貼り付けるように指定したことになります。

  6. 手順 6: 上司からのフィードバックを含むテキスト ファイルから Word ファイルに情報を追加し、従業員ごとに別のファイルに保存する

    オートメーションにより、Outputs フォルダーに各従業員のパフォーマンス レビューが記載された Word 文書が個別に作成されます。この Word 文書には、従業員データとプロジェクト情報を含む Excel ファイルからの情報と、マネージャーからのフィードバックを含むテキスト ファイルからの情報が入力されます。

    1. Click Add activity ドキュメントの画像 below the newly added Use Excel File activity, and then find the Read Text File activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.

    2. [テキスト ファイルを読み込み] アクティビティで、次の操作を行います。

      • Click Plus ドキュメントの画像 on the right side of the File name field, and then select Text.

        テキスト ビルダーで

        1. Files\」と入力します。

        2. Click Plusドキュメントの画像 on the right side of the Text Builder, and then select Employee > Full Name.

        3. _ManagerFeedback.txt」と入力します。

          テキストは「Files\[Employee]FullName_ManagerFeedback.txt」のようになります。

        4. テキスト ビルダーで [保存] をクリックします。

      • In the Properties panel, click Plusドキュメントの画像 on the right side of the Content field, and then select Save for Later Use. Enter the name ManagerFeedback, and click OK.

      ここでは、各従業員について、ファイル名に従業員名を含むテキスト ファイルから上司のフィードバックをコピーし、後からオートメーション プロジで使用するために保存するように指定しました。

    3. Click Add activity ドキュメントの画像 below the Read Text File activity, and then find the Set Bookmark Content activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.

    4. [ブックマークのコンテンツを設定] アクティビティで、次の操作を行います。

      • Click Plusドキュメントの画像 on the right side of the Bookmark name field, and then select Text. In the Text Builder, enter DirectManagerFeedback.

      • [ ドキュメントの画像ブックマーク] テキスト フィールドの右側にある プラス 記号 をクリックし、[ ManagerFeedback > 保存された値を使用] を選択します。

        ここでは、各従業員について、後で使用するために [テキスト ファイルを読み込み] アクティビティで保存しておいた上司のフィードバックをコピーし、Word ファイルのブックマーク DirectManagerFeedback の場所に貼り付けるように指定しました。

    5. Click Add activity ドキュメントの画像 below the Set Bookmark Content activity, and then find the Save Word File As activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.

    6. [名前を付けて Word ファイルを保存] アクティビティで、次の操作を行います。

      • [ドキュメントの画像 ファイルとして保存] フィールドの右側にある プラス 記号 をクリックし、[ テキスト] を選択します。

        テキスト ビルダーで

        1. Output\」と入力します。

        2. Click Plusドキュメントの画像 on the right side of the Text Builder, and then select Employee > Full Name.

        3. _PerformanceReview.docx」と入力します。

          テキストは「Output\[Employee]FullName_PerformanceReview.docx」のようになります。

        4. テキスト ビルダーで [保存] をクリックします。

      • その他のオプションは、既定の選択のままにします。

      ここでは、各従業員のデータに基づいて変更したテンプレート ファイルを、Output (出力) という名前の新規フォルダーに保存するように指定しました。Excel ファイル Employees (従業員) の Full Name (フル ネーム) 列の値に基づいて、各従業員のフル ネームがファイル名に追加されます。

    7. StudioX のリボンで [保存] をクリックしてオートメーションを保存し、[実行] をクリックしてオートメーションを実行します。

このページは役に立ちましたか?

接続

ヘルプ リソース サポート

学習する UiPath アカデミー

質問する UiPath フォーラム

最新情報を取得