# excelの複数ファイルを一つにする:Make multiple excel files one

**URL:** <https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293>\
**Category:** フォーラム\
**Created:** [June 5, 2018, 4:39am UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293 "2018-06-05T04:39:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![matrix99999](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/matrix99999/32/121413_2.png) [@matrix99999](https://forum.uipath.com/u/matrix99999)\
**Post date:** [June 5, 2018, 4:39am UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/1 "2018-06-05T04:39:14Z")

</div>

ファイル一覧より複数のexcelファイルを選択します。  
New DirectoryInfo(wk\_dir).GetFiles(“_._”)  
each forを利用して、New DirectoryInfo(wk\_dir).GetFiles(“_._”)で取得した複数excelファイルを指定のexcelファイルのシートにコピー・追記したいと思います。  
どのようにすれば１つのファイルおよびシートに複数ファイル情報を格納できますか。  
また、１つ目はヘッダーありと考えますが２つ以降の読み込んだexcelファイルのヘッダーは、不要にしたいと思います。よろしくお願いします。

Select multiple excel files from the file list.  
New DirectoryInfo (wk\_dir) .GetFiles (“\*. _“)  
I would like to copy / append multiple excel files acquired with New DirectoryInfo (wk\_dir) .GetFiles (”_. \*”) to the sheet of the specified excel file using each for.  
How can I store multiple file information in one file and sheet?  
Also, the first one seems to have a header, but I think that it is unnecessary to make headers of the excel files that have been read in and after.

---

<div class="post-metadata">

**Author:** ![yukino](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yukino/32/20624_2.png) [@yukino](https://forum.uipath.com/u/yukino)\
**Post date:** [June 5, 2018, 5:14am UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/2 "2018-06-05T05:14:17Z")

</div>

① [Merge Data Table] アクティビティを使って、[Read Range]で取得したデータテーブルを繰り返し連結する

> **[Merge Data Table](https://docs.uipath.com/activities/docs/merge-data-table)**
>
> UiPath.Core.Activities.MergeDataTable Merges the Destination with the Source, indicating whether to preserve changes and how to handle missing schema in the Source. Properties Common DisplayName - The display name of the activity. Input Destination -...

２件目以降の見出しはうまい具合に削ってくれるみたいです（実際にご確認ください）

② Excelを使って、[Ctrl-C] [Ctrl-V] でコピー＆ペーストを繰り返して実現する

の、どちらかでしょうかね。  
Excelのセル属性（色・背景色・書式など）も追記が必要な場合は②になります

①イメージ：

 ![To_matirix99999_san](https://global.discourse-cdn.com/uipath/original/3X/9/0/9085eca2715ef661b28fb7eadf0ddb21394b2c8e.jpg)

---

<div class="post-metadata">

**Author:** ![matrix99999](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/matrix99999/32/121413_2.png) [@matrix99999](https://forum.uipath.com/u/matrix99999)\
**Post date:** [June 5, 2018, 6:16am UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/3 "2018-06-05T06:16:55Z")

</div>

yukino様  
ありがとうございます。  
itemのvariable typeは、何になるでしょうか。  
また、DOのアクテビティは何を指定すればよいでしょうか。  
UIPATH始め１か月弱の初心者ですのでご教示いただければ幸甚です。

---

<div class="post-metadata">

**Author:** ![yukino](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yukino/32/20624_2.png) [@yukino](https://forum.uipath.com/u/yukino)\
**Post date:** [June 5, 2018, 12:02pm UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/4 "2018-06-05T12:02:55Z")

</div>

① 元の質問に[GetFiles(“.”)]で取得した複数Excelファイルを。。。との記載がありましたので、それでワークフローを組み立てて行くことにしたと理解しているのですが、相違ありますでしょうか？  
GetFiles()は複数のファイル名を配列に入れて返すので、ここの変数は文字列になると思いますよ。

② Doのアクティビティは、私が貼った画像の繰り返しの中のことを指していますよね。  
私は、「Merge Data Table」もしくは「Excelのキー操作」の方法があるとご提示したつもりなのですが、@Matrix99999 様はどちらでワークフローを組み立てていくことにされたのですか？  
その方針によりDoの中身は異なりますので、まずはその判断を教えてください。

※  
ちなみに、画像がブラウザ上切れているかもしれませんが、クリックすると全体像が表示されますので、クリックしてみてください。  
また、私の返信はときどき画像をつけていますが、「こう作ってね」ではなく、「私が作るならこうです」  
なので、是非 @matrix99999 さまの「このように作ってみたのだけど、どうかな？」を見せてくださいね。

---

<div class="post-metadata">

**Author:** ![matrix99999](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/matrix99999/32/121413_2.png) [@matrix99999](https://forum.uipath.com/u/matrix99999)\
**Post date:** [June 5, 2018, 12:45pm UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/5 "2018-06-05T12:45:59Z")

</div>

yukiko様  
申し訳ございません。  
こちらで作成してみましたが、each for で取得したファイルをループさせています。  
しかし属性等が理解不足でエラーとなり戸惑っています。  
ワークフローは、yukiko様の例示どおりに行いました。  
よろしければ精査していただけないでしょうか。[copy\_excel.xaml](https://global.discourse-cdn.com/uipath/original/3X/f/3/f3bed73eae42e7fcd2275b78e8b8fc29d4afc2ce.xaml) (9.3 KB)

---

<div class="post-metadata">

**Author:** ![yukino](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yukino/32/20624_2.png) [@yukino](https://forum.uipath.com/u/yukino)\
**Post date:** [June 5, 2018, 1:46pm UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/6 "2018-06-05T13:46:56Z")

</div>

[copy\_excel \_yukino.xaml](https://global.discourse-cdn.com/uipath/original/3X/d/3/d312a0526c51a789089ac7ac0d967e8058e0b87d.xaml) (11.9 KB)

軽くエラーを潰してみました。  
変更した箇所はコメントを入れておいたので、確認いただけると。

---

<div class="post-metadata">

**Author:** ![matrix99999](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/matrix99999/32/121413_2.png) [@matrix99999](https://forum.uipath.com/u/matrix99999)\
**Post date:** [June 6, 2018, 12:29am UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/7 "2018-06-06T00:29:07Z")

</div>

本当にお手数おかけしてしまいありがとうございます。  
フォルダのファイル取得とアウトプットのexcelファイルを指定して実行しました。  
こちらのミスと思いますがエラーがでます。  
エラー内容：  
copy\_excel \_20180606 has thrown an exception  
Source: Merge data table

Message: Object reference not set to an instance of an object. This error usually occurs when using a variable with no set value (not initialized).

Exception Type: NullReferenceException

System.NullReferenceException: Object reference not set to an instance of an object.  
at UiPath.Core.Activities.MergeDataTable.Execute(CodeActivityContext context)  
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)  
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)  
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

修正したxamlファイルも添付いたします。  
再度ご教示いただけないでしょうか。  
よろしくお願いします。[copy\_excel \_20180606.xaml](https://global.discourse-cdn.com/uipath/original/3X/a/4/a4eaec14f16135a627f4b093285ece3df09fa5d4.xaml) (13.1 KB)

---

<div class="post-metadata">

**Author:** ![yukino](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yukino/32/20624_2.png) [@yukino](https://forum.uipath.com/u/yukino)\
**Post date:** [June 6, 2018, 1:44am UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/8 "2018-06-06T01:44:28Z")

</div>

dt1の初期化がされていません。おそらく最初の１ループ時に、  
dt1 (中身なにもなし）と dt2 (Excelから読み取ったデータ）をくっつけようとして、片方に何も入っていないのでエラーになっているようですね。

dt1,dt2に初期値をセットしたり、見出しだけのダミーデータを入れたり、いきなり本物のロジックを作らないで、ご自身でアクティビティ（今回はMerge Data Table)の動作を検証しつつ、理解した内容でシナリオを作っていくことをお勧めします。

---

<div class="post-metadata">

**Author:** ![matrix99999](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/matrix99999/32/121413_2.png) [@matrix99999](https://forum.uipath.com/u/matrix99999)\
**Post date:** [June 6, 2018, 1:49am UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/9 "2018-06-06T01:49:16Z")

</div>

yukino様  
忙しいところご教示いただきありがとうございます。

---

<div class="post-metadata">

**Author:** ![matrix99999](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/matrix99999/32/121413_2.png) [@matrix99999](https://forum.uipath.com/u/matrix99999)\
**Post date:** [June 6, 2018, 10:57am UTC](https://forum.uipath.com/t/excel-make-multiple-excel-files-one/35293/10 "2018-06-06T10:57:52Z")

</div>

色々ありがとうございました。  
data tableに関して色々検証しました。  
build data tableでdt01に空データを格納しdt01にデータがあるようにして、  
Merge Data Tableで、dt01=dt01 + dt02としてwrite rangeで実態のexcelファイルに登録するように  
しました。  
本当に勉強になりました。  
ありがとうございます。
