( address: string | undefined, sheetName?: string )
| 161 | * Throws when a worksheet name cannot be determined or the combined format is invalid. |
| 162 | */ |
| 163 | export function resolveSheetAndAddress( |
| 164 | address: string | undefined, |
| 165 | sheetName?: string |
| 166 | ): { sheetName: string; address: string } { |
| 167 | const trimmedAddress = address?.trim() |
| 168 | if (!trimmedAddress) { |
| 169 | throw new Error('A cell range is required (e.g., "A1:B2" or "Sheet1!A1:B2")') |
| 170 | } |
| 171 | |
| 172 | const trimmedSheet = sheetName?.trim() |
| 173 | if (trimmedSheet) { |
| 174 | return { sheetName: trimmedSheet, address: trimmedAddress } |
| 175 | } |
| 176 | |
| 177 | const match = trimmedAddress.match(/^([^!]+)!(.+)$/) |
| 178 | if (!match) { |
| 179 | throw new Error( |
| 180 | `Invalid range format: "${address}". Provide a sheet name, or use the combined format "Sheet1!A1:B2"` |
| 181 | ) |
| 182 | } |
| 183 | |
| 184 | return { sheetName: match[1], address: match[2] } |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Builds the Graph API URL for a worksheet range object, resolving the sheet name |
no outgoing calls
no test coverage detected