fix: BuildViewFromSheetをセル座標指定からテーブル名(FilterTable/SorterTable)参照に変更

Filter表・Sorter表の配置をユーザーが移動したところ、固定セル座標(F3/J3)読み取りのため条件が反映されずViewが空になっていた。
ListObjects("FilterTable")/("SorterTable")をテーブル名で取得し、1列目=項目名・2列目=値/昇降順という列位置ベースで読むよう変更。テーブルをシート上のどこに配置しても動作する。
デバッグ用に追加していたリクエストボディ出力ログも削除。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Kenichiro NOGI 2026-09-14 09:43:27 +09:00
parent 3bfdf3b73e
commit 1eb1a7dc87

View File

@ -302,24 +302,48 @@ Private Function CollectionToArray(Byval col As Collection) As Variant
End Function End Function
'****************************************************************************** '******************************************************************************
'基本情報シートのFilter表(F2:G2見出し、F3以降データ)・Sorter表(H2:I2見出し、H3以降データ)を読み取り、 '基本情報シート上の「FilterTable」「SorterTable」という名前のExcelテーブルListObject
'APIリクエストのViewパラメータに渡すDictionaryを組み立てる。 'テーブル名で探して読み取り、APIリクエストのViewパラメータに渡すDictionaryを組み立てる。
'セルの絶対位置には依存しないテーブルを移動しても動作する。各テーブルは1列目=項目名、2列目=値/昇降順とする。
'Filter・Sorterともに0件の場合はNothingを返すViewパラメータ自体を付与しないため 'Filter・Sorterともに0件の場合はNothingを返すViewパラメータ自体を付与しないため
Function BuildViewFromSheet() As Object Function BuildViewFromSheet() As Object
Dim colFilter As New Dictionary Dim colFilter As New Dictionary
Dim r As Long Dim filterTbl As ListObject
r = 3 On Error Resume Next
Do While Trim(defaultSh.Cells(r, "F").Value) <> "" Set filterTbl = defaultSh.ListObjects("FilterTable")
colFilter.Add defaultSh.Cells(r, "F").Value, "[" & Chr(34) & CStr(defaultSh.Cells(r, "G").Value) & Chr(34) & "]" On Error GoTo 0
r = r + 1
Loop If Not filterTbl Is Nothing Then
If Not filterTbl.DataBodyRange Is Nothing Then
Dim r As Long
For r = 1 To filterTbl.DataBodyRange.Rows.count
Dim filterKey As String
filterKey = Trim(filterTbl.DataBodyRange.Cells(r, 1).Value)
If filterKey <> "" Then
colFilter.Add filterKey, "[" & Chr(34) & CStr(filterTbl.DataBodyRange.Cells(r, 2).Value) & Chr(34) & "]"
End If
Next r
End If
End If
Dim colSorter As New Dictionary Dim colSorter As New Dictionary
r = 3 Dim sorterTbl As ListObject
Do While Trim(defaultSh.Cells(r, "J").Value) <> "" On Error Resume Next
colSorter.Add defaultSh.Cells(r, "J").Value, defaultSh.Cells(r, "K").Value Set sorterTbl = defaultSh.ListObjects("SorterTable")
r = r + 1 On Error GoTo 0
Loop
If Not sorterTbl Is Nothing Then
If Not sorterTbl.DataBodyRange Is Nothing Then
Dim r2 As Long
For r2 = 1 To sorterTbl.DataBodyRange.Rows.count
Dim sorterKey As String
sorterKey = Trim(sorterTbl.DataBodyRange.Cells(r2, 1).Value)
If sorterKey <> "" Then
colSorter.Add sorterKey, sorterTbl.DataBodyRange.Cells(r2, 2).Value
End If
Next r2
End If
End If
If colFilter.count = 0 And colSorter.count = 0 Then If colFilter.count = 0 And colSorter.count = 0 Then
Set BuildViewFromSheet = Nothing Set BuildViewFromSheet = Nothing