- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
03-03-2025 08:28 PM
Hi everyone,
I'm encountering an issue with an automation script in XSOAR that uses openpyxl to insert an image into an Excel file. Even though the Excel file I'm uploading is valid (I’ve tested it by downloading it and opening it in Excel—it opens without any problems), the script throws the following error when executed in XSOAR:
Error occurred: openpyxl does not support file format, please check you can open it with Excel first. Supported formats are: .xlsx, .xlsm, .xltx, .xltm
Here’s some context and what I’ve tried so far:
File Validation:
Custom Docker Image:
demisto/python3:3.11.10.116439
(or similar) and installed openpyxl and Pillow via a requirements.txt.
Below is a snippet of my script where I perform the header logging and open the workbook:
from openpyxl import load_workbook
from openpyxl.drawing.image import Image as XLImage
import os
def insert_image_to_excel(excel_path, image_path, cell="A1", sheet_name=None):
with open(excel_path, 'rb') as f:
header = f.read(8)
file_size = os.path.getsize(excel_path)
demisto.debug("Excel file header (first 8 bytes, hex): " + " ".join("{:02x}".format(b) for b in header))
demisto.debug("Excel file size: " + str(file_size))
wb = load_workbook(excel_path)
if sheet_name:
if sheet_name in wb.sheetnames:
ws = wb[sheet_name]
else:
return_error("Sheet '{}' not found.".format(sheet_name))
else:
ws = wb.active
img = XLImage(image_path)
ws.add_image(img, cell)
wb.save(excel_path)
03-12-2025 08:06 AM
I took a look at your script and I think the problem is the way that you are accessing the file. The XSOAR platform works with entryIDs as a handle rather than an actual path.
Check out this comment by @DougCouch on a different post: https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/issue-working-with-files/td-p/386556
Try using this method to get to the actual file https://xsoar.pan.dev/docs/reference/api/demisto-class#getfilepath. Ensure the actual file is accessible and then you can run openpyxl or other methods on it. Id recommend not using very large Excel files as this can be difficult to operate on.
Let me know if this helps.
MSysec
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!