Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions apps/sim/blocks/blocks/microsoft_excel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,41 +234,6 @@ Return ONLY the JSON array - no explanations, no markdown, no extra text.`,
],
condition: { field: 'operation', value: 'write' },
},
{
id: 'values',
title: 'Values',
type: 'long-input',
placeholder:
'Enter values as JSON array of arrays (e.g., [["A1", "B1"], ["A2", "B2"]]) or an array of objects (e.g., [{"name":"John", "age":30}, {"name":"Jane", "age":25}])',
condition: { field: 'operation', value: 'update' },
required: true,
wandConfig: {
enabled: true,
prompt: `Generate Microsoft Excel data as a JSON array based on the user's description.

Format options:
1. Array of arrays: [["Header1", "Header2"], ["Value1", "Value2"]]
2. Array of objects: [{"column1": "value1", "column2": "value2"}]

Examples:
- "update with new prices" -> [["Product", "Price"], ["Widget A", 29.99], ["Widget B", 49.99]]
- "quarterly targets" -> [{"Q1": 10000, "Q2": 12000, "Q3": 15000, "Q4": 18000}]

Return ONLY the JSON array - no explanations, no markdown, no extra text.`,
placeholder: 'Describe the data you want to update...',
generationType: 'json-object',
},
},
{
id: 'valueInputOption',
title: 'Value Input Option',
type: 'dropdown',
options: [
{ label: 'User Entered (Parse formulas)', id: 'USER_ENTERED' },
{ label: "Raw (Don't parse formulas)", id: 'RAW' },
],
condition: { field: 'operation', value: 'update' },
},
{
id: 'values',
title: 'Values',
Expand Down
9 changes: 5 additions & 4 deletions apps/sim/tools/microsoft_excel/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
MicrosoftExcelV2ToolParams,
} from '@/tools/microsoft_excel/types'
import {
escapeODataString,
getItemBasePath,
getSpreadsheetWebUrl,
parseGraphErrorMessage,
Expand Down Expand Up @@ -79,7 +80,7 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
const rangeInput = params.range.trim()

if (!rangeInput.includes('!')) {
const sheetOnly = encodeURIComponent(rangeInput)
const sheetOnly = encodeURIComponent(escapeODataString(rangeInput))
return `${basePath}/workbook/worksheets('${sheetOnly}')/usedRange(valuesOnly=true)`
}

Expand All @@ -91,7 +92,7 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
)
}

const sheetName = encodeURIComponent(match[1])
const sheetName = encodeURIComponent(escapeODataString(match[1]))
const address = encodeURIComponent(match[2])

return `${basePath}/workbook/worksheets('${sheetName}')/range(address='${address}')`
Expand Down Expand Up @@ -128,7 +129,7 @@ export const readTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelReadRe
}

const basePath = getItemBasePath(spreadsheetId, driveId)
const rangeUrl = `${basePath}/workbook/worksheets('${encodeURIComponent(firstSheetName)}')/usedRange(valuesOnly=true)`
const rangeUrl = `${basePath}/workbook/worksheets('${encodeURIComponent(escapeODataString(firstSheetName))}')/usedRange(valuesOnly=true)`

const rangeResp = await fetch(rangeUrl, {
headers: { Authorization: `Bearer ${accessToken}` },
Expand Down Expand Up @@ -278,7 +279,7 @@ export const readV2Tool: ToolConfig<MicrosoftExcelV2ToolParams, MicrosoftExcelV2
}

const basePath = getItemBasePath(spreadsheetId, params.driveId)
const encodedSheetName = encodeURIComponent(sheetName)
const encodedSheetName = encodeURIComponent(escapeODataString(sheetName))

if (!params.cellRange) {
return `${basePath}/workbook/worksheets('${encodedSheetName}')/usedRange(valuesOnly=true)`
Expand Down
32 changes: 24 additions & 8 deletions apps/sim/tools/microsoft_excel/table_add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import type {
MicrosoftExcelTableAddResponse,
MicrosoftExcelTableToolParams,
} from '@/tools/microsoft_excel/types'
import { getItemBasePath, getSpreadsheetWebUrl } from '@/tools/microsoft_excel/utils'
import {
escapeODataString,
getItemBasePath,
getSpreadsheetWebUrl,
} from '@/tools/microsoft_excel/utils'
import type { ToolConfig } from '@/tools/types'

export const tableAddTool: ToolConfig<
Expand Down Expand Up @@ -59,15 +63,27 @@ export const tableAddTool: ToolConfig<

request: {
url: (params) => {
const tableName = encodeURIComponent(params.tableName)
const basePath = getItemBasePath(params.spreadsheetId, params.driveId)
return `${basePath}/workbook/tables('${tableName}')/rows/add`
const spreadsheetId = params.spreadsheetId?.trim()
if (!spreadsheetId) {
throw new Error('Spreadsheet ID is required')
}
const tableName = params.tableName?.trim()
if (!tableName) {
throw new Error('Table name is required')
}
const basePath = getItemBasePath(spreadsheetId, params.driveId)
return `${basePath}/workbook/tables('${encodeURIComponent(escapeODataString(tableName))}')/rows/add`
},
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
}),
headers: (params) => {
if (!params.accessToken) {
throw new Error('Access token is required')
}
return {
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
}
},
body: (params) => {
let processedValues: any = params.values || []

Expand Down
15 changes: 0 additions & 15 deletions apps/sim/tools/microsoft_excel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,13 @@ import type { ToolResponse } from '@/tools/types'
export type ExcelCellValue = string | number | boolean | null

interface MicrosoftExcelRange {
sheetId?: number
sheetName?: string
range: string
values: ExcelCellValue[][]
}

interface MicrosoftExcelMetadata {
spreadsheetId: string
spreadsheetUrl?: string
title?: string
sheets?: {
sheetId: number
title: string
index: number
rowCount?: number
columnCount?: number
}[]
}

export interface MicrosoftExcelReadResponse extends ToolResponse {
Expand Down Expand Up @@ -67,10 +57,7 @@ export interface MicrosoftExcelToolParams {
range?: string
values?: ExcelCellValue[][]
valueInputOption?: 'RAW' | 'USER_ENTERED'
insertDataOption?: 'OVERWRITE' | 'INSERT_ROWS'
includeValuesInResponse?: boolean
responseValueRenderOption?: 'FORMATTED_VALUE' | 'UNFORMATTED_VALUE' | 'FORMULA'
majorDimension?: 'ROWS' | 'COLUMNS'
}

export interface MicrosoftExcelTableToolParams {
Expand All @@ -79,7 +66,6 @@ export interface MicrosoftExcelTableToolParams {
driveId?: string
tableName: string
values: ExcelCellValue[][]
rowIndex?: number
}

export interface MicrosoftExcelWorksheetToolParams {
Expand Down Expand Up @@ -217,7 +203,6 @@ export interface MicrosoftExcelV2ToolParams {
values?: ExcelCellValue[][]
valueInputOption?: 'RAW' | 'USER_ENTERED'
includeValuesInResponse?: boolean
majorDimension?: 'ROWS' | 'COLUMNS'
}

export interface MicrosoftExcelV2ReadResponse extends ToolResponse {
Expand Down
29 changes: 19 additions & 10 deletions apps/sim/tools/microsoft_excel/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import type {
MicrosoftExcelV2WriteResponse,
MicrosoftExcelWriteResponse,
} from '@/tools/microsoft_excel/types'
import { getItemBasePath, getSpreadsheetWebUrl } from '@/tools/microsoft_excel/utils'
import {
escapeODataString,
getItemBasePath,
getSpreadsheetWebUrl,
} from '@/tools/microsoft_excel/utils'
import type { ToolConfig } from '@/tools/types'

/**
Expand Down Expand Up @@ -82,17 +86,22 @@ export const writeTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelWrite

request: {
url: (params) => {
const spreadsheetId = params.spreadsheetId?.trim()
if (!spreadsheetId) {
throw new Error('Spreadsheet ID is required')
}

const rangeInput = params.range?.trim()
const match = rangeInput?.match(/^([^!]+)!(.+)$/)

if (!match) {
throw new Error(`Invalid range format: "${params.range}". Use the format "Sheet1!A1:B2"`)
}

const sheetName = encodeURIComponent(match[1])
const sheetName = encodeURIComponent(escapeODataString(match[1]))
const address = encodeURIComponent(match[2])

const basePath = getItemBasePath(params.spreadsheetId!, params.driveId)
const basePath = getItemBasePath(spreadsheetId, params.driveId)
const url = new URL(
`${basePath}/workbook/worksheets('${sheetName}')/range(address='${address}')`
)
Expand Down Expand Up @@ -145,7 +154,7 @@ export const writeTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelWrite
}

const body: Record<string, any> = {
majorDimension: params.majorDimension || 'ROWS',
majorDimension: 'ROWS',
values: processedValues,
}

Expand Down Expand Up @@ -173,10 +182,10 @@ export const writeTool: ToolConfig<MicrosoftExcelToolParams, MicrosoftExcelWrite
return {
success: true,
output: {
updatedRange: data.updatedRange,
updatedRows: data.updatedRows,
updatedColumns: data.updatedColumns,
updatedCells: data.updatedCells,
updatedRange: data.address ?? '',
updatedRows: data.rowCount ?? 0,
updatedColumns: data.columnCount ?? 0,
updatedCells: (data.rowCount ?? 0) * (data.columnCount ?? 0),
metadata: {
spreadsheetId,
spreadsheetUrl: webUrl,
Expand Down Expand Up @@ -280,7 +289,7 @@ export const writeV2Tool: ToolConfig<MicrosoftExcelV2ToolParams, MicrosoftExcelV
}

const cellRange = params.cellRange?.trim() || 'A1'
const encodedSheetName = encodeURIComponent(sheetName)
const encodedSheetName = encodeURIComponent(escapeODataString(sheetName))
const encodedAddress = encodeURIComponent(cellRange)

const basePath = getItemBasePath(spreadsheetId, params.driveId)
Expand Down Expand Up @@ -337,7 +346,7 @@ export const writeV2Tool: ToolConfig<MicrosoftExcelV2ToolParams, MicrosoftExcelV
}

const body: Record<string, any> = {
majorDimension: params.majorDimension || 'ROWS',
majorDimension: 'ROWS',
values: processedValues,
}

Expand Down
Loading