The other replies covered the main issue, Microsoft’s Graph API just doesn’t play nice with xlsm files for writes. But if you really need to keep the macros intact and can’t convert to xlsx, the download-edit-reupload approach Msquare mentioned is probably your best path forward.
You’d grab the file as binary from OneDrive, use a Code node with the xlsx library (which does support xlsm), make your edits there, then push it back up. Something like this should get you started:
```
{
“nodes”: [
{
"parameters": {
"method": "GET",
"url": "https://graph.microsoft.com/v1.0/me/drive/items/YOUR_FILE_ID/content",
"authentication": "oAuth2",
"options": {
"response": {
"response": {
"responseFormat": "file"
}
}
}
},
"name": "Download XLSM",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": \[
240,
300
\],
"credentials": {
"microsoftOneDriveOAuth2Api": {
"id": "your-credential-id",
"name": "Microsoft OneDrive"
}
}
},
{
"parameters": {
"jsCode": "const XLSX = require('xlsx');\\n\\n// Read the binary file\\nconst workbook = XLSX.read($input.first().binary.data.data, { type: 'buffer', bookType: 'xlsm' });\\n\\n// Get first sheet\\nconst sheet = workbook.Sheets\[workbook.SheetNames\[0\]\];\\n\\n// Edit cell A1\\nsheet\['A1'\] = { t: 's', v: 'Your new value' };\\n\\n// Write back to buffer\\nconst output = XLSX.write(workbook, { type: 'buffer', bookType: 'xlsm' });\\n\\nreturn \[{ binary: { data: await this.helpers.prepareBinaryData(Buffer.from(output), 'edited.xlsm') } }\];"
},
"name": "Edit XLSM",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": \[
460,
300
\]
},
{
"parameters": {
"method": "PUT",
"url": "https://graph.microsoft.com/v1.0/me/drive/items/YOUR_FILE_ID/content",
"authentication": "oAuth2",
"sendBody": true,
"contentType": "binaryData",
"inputDataFieldName": "data"
},
"name": "Upload XLSM",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": \[
680,
300
\],
"credentials": {
"microsoftOneDriveOAuth2Api": {
"id": "your-credential-id",
"name": "Microsoft OneDrive"
}
}
}
],
“connections”: {
"Download XLSM": {
"main": \[
\[
{
"node": "Edit XLSM",
"type": "main",
"index": 0
}
\]
\]
},
"Edit XLSM": {
"main": \[
\[
{
"node": "Upload XLSM",
"type": "main",
"index": 0
}
\]
\]
}
}
}
```
You’ll need to swap out YOUR_FILE_ID with the actual OneDrive item ID and adjust the cell editing logic in the Code node to match what you’re actually trying to do. The xlsx library preserves macros when you read/write xlsm files this way, which is the whole point since the Graph API’s workbook endpoints would strip them anyway.