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