teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

結果反映

2016/03/12 07:46

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -89,7 +89,23 @@
89
89
  Find(${word},$After,$LookIn,$LookAt,$SeachOrder,$SearchDirection,$MatchCase,$MatchByte,$SearchFormat)
90
90
  ```
91
91
 
92
+ ###結果(解決)
92
93
 
94
+ ```powershell
95
+
96
+ ${FindFirst} = ${FindResult} = `
97
+ ${SheetName}.Range(${CellRange}).Find(${xText},${FirstCell},${LookIn},`
98
+ ${LookAt},${SeachOrder},${SearchDirection},${MatchCase},${MatchByte},`
99
+ ${SearchFormat})
100
+ ```
101
+ ${SheetName} : シート名。オープンしたブックから取得するか、事前設定。
102
+ ${CellRange} : セル範囲。お約束。Rangeの代わりにCellsでも好いと思うけど、範囲絞る方が?!
103
+ ${xText} : 検索語句
104
+ ${FirstCell} : 検索開始位置となるセル番号。
105
+ ${FindFirst} : 初回検索結果を格納。取得できない時はNull。AddressやらRowやら全部入り。
106
+ ${FindResult} :二回目以降の検索結果を格納。取得できない時は・・・以下同文。
107
+
108
+
93
109
  ###参考にした情報
94
110
  ```ここに言語を入力
95
111
  PowerShellで複数のExcelファイルを一括検索する

2

問題点を追記

2016/03/12 07:46

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -12,7 +12,84 @@
12
12
  ###発生している問題・エラーメッセージ
13
13
 
14
14
  検索条件の指定方法がわからない。
15
+ 参考にしたサイトより、FindとFindNextの引数として、何らかの書式で
16
+ 指定すれば好いと思うのですが・・・・。
15
17
 
18
+ エラー1:
19
+ ```
20
+ "FindNext" のオーバーロードで、引数の数が "9" であるものが見つかりません
21
+ ```
22
+ エラー2:
23
+ ```
24
+ Range クラスの FindNext プロパティを取得できません。
25
+ 発生場所 E:\GitRoot\PS1\test_val.ps1:65 文字:13
26
+ + ${FindResult} = $SheetName.Cells.FindNext(${FindResult})
27
+ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28
+ + CategoryInfo : OperationStopped: (:) [], COMException
29
+ + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
30
+
31
+ HRESULT からの例外:0x800A01A8
32
+ 発生場所 E:\GitRoot\PS1\test_val.ps1:69 文字:18
33
+ + if ( ${FindFirst}.Address() -eq ${FindResult}.Address() )
34
+ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35
+ + CategoryInfo : OperationStopped: (:) [], COMException
36
+ + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
37
+ ```
38
+
39
+ ポイントとなる処理:
40
+ ```powershell
41
+ ${first} = ${result} = ${ws}.Cells.Find(${word})
42
+ while (${result} -ne $null) {
43
+ echo "${childPath}[${wsName}][$(${result}.Row), $(${result}.Column)] : $(${result}.Text)"
44
+ ${result} = ${ws}.Cells.FindNext(${result})
45
+ if (${result}.Address() -eq ${first}.Address()) {
46
+ break
47
+ }
48
+ }
49
+ ```
50
+
51
+ こんな感じ??:
52
+ ```powershell
53
+
54
+ ## After
55
+ set-variable -name After -value "`$A`$1" -option constant
56
+
57
+ ## LookIn
58
+ set-variable -name xlFormulas -value -4123 -option constant
59
+ set-variable -name xlValues -value -4163 -option constant
60
+ #xlComments
61
+
62
+ ## LookAt
63
+ set-variable -name xlWhole -value 1 -option constant
64
+ set-variable -name xlPart -value 2 -option constant
65
+
66
+ ## SeachOrder
67
+ set-variable -name xlByColumns -value 2 -option constant
68
+ set-variable -name xlByRows -value 1 -option constant
69
+
70
+ ## SearchDirection
71
+ set-variable -name xlNext -value 1 -option constant
72
+ set-variable -name xlPrevious -value 2 -option constant
73
+
74
+ ## MatchCase (True or False)
75
+ set-variable -name MatchCase -value $false -option constant
76
+
77
+ ## MatchByte (True or False)
78
+ set-variable -name MatchByte -value $false -option constant
79
+
80
+ ## SearchFormat (True or False)
81
+ set-variable -name SearchFormat -value $false -option constant
82
+
83
+
84
+ $LookIn = $xlValues #値
85
+ $LookAt = $xlPart #部分一致
86
+ $SeachOrder = $xlByColumns #列方向に検索
87
+ $SearchDirection = $xlNext #全方向に検索
88
+
89
+ Find(${word},$After,$LookIn,$LookAt,$SeachOrder,$SearchDirection,$MatchCase,$MatchByte,$SearchFormat)
90
+ ```
91
+
92
+
16
93
  ###参考にした情報
17
94
  ```ここに言語を入力
18
95
  PowerShellで複数のExcelファイルを一括検索する

1

誤記修正

2016/02/07 04:53

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- PowerShel: Excelブック検索時の条件を指定したい
1
+ PowerShel: Excelブック検索時の条件を指定したい
body CHANGED
File without changes