Issues with openpyxl: "openpyxl does not support file format" when processing valid Excel files from War Room

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issues with openpyxl: "openpyxl does not support file format" when processing valid Excel files from War Room

L0 Member

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:

 

AMuharramIshaq_0-1741062081151.png

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:

    • The file is uploaded as a valid .xlsx (and I’ve also tested with .xlsm, .xltx, and .xltm).
    • I manually downloaded the file from War Room and confirmed that it opens correctly in Excel.
  • Custom Docker Image:

    • I built a custom Docker image based on demisto/python3:3.11.10.116439 (or similar) and installed openpyxl and Pillow via a requirements.txt.
    • The Docker image builds successfully and basic tests (e.g., running a simple script that prints Python’s version) work fine locally.
    • However, when the automation script runs in XSOAR (using my custom image), I receive the same error.

 

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)

 

1 REPLY 1

L3 Networker

@A.MuharramIshaq 

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

 

PCSAE
  • 237 Views
  • 1 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

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!