<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Issues with openpyxl: &amp;quot;openpyxl does not support file format&amp;quot; when processing valid Excel files from War Room in Cortex XSOAR Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/issues-with-openpyxl-quot-openpyxl-does-not-support-file-format/m-p/1222492#M3927</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AMuharramIshaq_0-1741062081151.png" style="width: 400px;"&gt;&lt;img src="https://live.paloaltonetworks.com/t5/image/serverpage/image-id/66303iF175A9AAC7553307/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AMuharramIshaq_0-1741062081151.png" alt="AMuharramIshaq_0-1741062081151.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Error occurred: openpyxl does not support file format, please check you can open it with Excel first. Supported formats are: .xlsx, .xlsm, .xltx, .xltm
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here’s some context and what I’ve tried so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI data-start="735" data-end="956"&gt;
&lt;P data-start="738" data-end="760"&gt;&lt;STRONG data-start="738" data-end="758"&gt;File Validation:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-start="764" data-end="956"&gt;
&lt;LI data-start="764" data-end="858"&gt;The file is uploaded as a valid .xlsx (and I’ve also tested with .xlsm, .xltx, and .xltm).&lt;/LI&gt;
&lt;LI data-start="862" data-end="956"&gt;I manually downloaded the file from War Room and confirmed that it opens correctly in Excel.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI data-start="1330" data-end="1753"&gt;
&lt;P data-start="1333" data-end="1359"&gt;&lt;STRONG data-start="1333" data-end="1357"&gt;Custom Docker Image:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-start="1363" data-end="1753"&gt;
&lt;LI data-start="1363" data-end="1509"&gt;I built a custom Docker image based on &lt;CODE data-start="1404" data-end="1436"&gt;demisto/python3:3.11.10.116439&lt;/CODE&gt; (or similar) and installed openpyxl and Pillow via a requirements.txt.&lt;/LI&gt;
&lt;LI data-start="1513" data-end="1647"&gt;The Docker image builds successfully and basic tests (e.g., running a simple script that prints Python’s version) work fine locally.&lt;/LI&gt;
&lt;LI data-start="1651" data-end="1753"&gt;However, when the automation script runs in XSOAR (using my custom image), I receive the same error.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Below is a snippet of my script where I perform the header logging and open the workbook:&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;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)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Mar 2025 04:28:37 GMT</pubDate>
    <dc:creator>A.MuharramIshaq</dc:creator>
    <dc:date>2025-03-04T04:28:37Z</dc:date>
    <item>
      <title>Issues with openpyxl: "openpyxl does not support file format" when processing valid Excel files from War Room</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/issues-with-openpyxl-quot-openpyxl-does-not-support-file-format/m-p/1222492#M3927</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AMuharramIshaq_0-1741062081151.png" style="width: 400px;"&gt;&lt;img src="https://live.paloaltonetworks.com/t5/image/serverpage/image-id/66303iF175A9AAC7553307/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AMuharramIshaq_0-1741062081151.png" alt="AMuharramIshaq_0-1741062081151.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Error occurred: openpyxl does not support file format, please check you can open it with Excel first. Supported formats are: .xlsx, .xlsm, .xltx, .xltm
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here’s some context and what I’ve tried so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI data-start="735" data-end="956"&gt;
&lt;P data-start="738" data-end="760"&gt;&lt;STRONG data-start="738" data-end="758"&gt;File Validation:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-start="764" data-end="956"&gt;
&lt;LI data-start="764" data-end="858"&gt;The file is uploaded as a valid .xlsx (and I’ve also tested with .xlsm, .xltx, and .xltm).&lt;/LI&gt;
&lt;LI data-start="862" data-end="956"&gt;I manually downloaded the file from War Room and confirmed that it opens correctly in Excel.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI data-start="1330" data-end="1753"&gt;
&lt;P data-start="1333" data-end="1359"&gt;&lt;STRONG data-start="1333" data-end="1357"&gt;Custom Docker Image:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-start="1363" data-end="1753"&gt;
&lt;LI data-start="1363" data-end="1509"&gt;I built a custom Docker image based on &lt;CODE data-start="1404" data-end="1436"&gt;demisto/python3:3.11.10.116439&lt;/CODE&gt; (or similar) and installed openpyxl and Pillow via a requirements.txt.&lt;/LI&gt;
&lt;LI data-start="1513" data-end="1647"&gt;The Docker image builds successfully and basic tests (e.g., running a simple script that prints Python’s version) work fine locally.&lt;/LI&gt;
&lt;LI data-start="1651" data-end="1753"&gt;However, when the automation script runs in XSOAR (using my custom image), I receive the same error.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Below is a snippet of my script where I perform the header logging and open the workbook:&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;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)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 04:28:37 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/issues-with-openpyxl-quot-openpyxl-does-not-support-file-format/m-p/1222492#M3927</guid>
      <dc:creator>A.MuharramIshaq</dc:creator>
      <dc:date>2025-03-04T04:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with openpyxl: "openpyxl does not support file format" when processing valid Excel files from War Room</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/issues-with-openpyxl-quot-openpyxl-does-not-support-file-format/m-p/1223586#M3943</link>
      <description>&lt;P&gt;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/1511941051"&gt;@A.MuharramIshaq&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check out this comment&amp;nbsp; by &lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/152909"&gt;@DougCouch&lt;/a&gt;&amp;nbsp;on a different post:&amp;nbsp;&amp;nbsp;&lt;A href="https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/issue-working-with-files/td-p/386556" target="_blank"&gt;https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/issue-working-with-files/td-p/386556&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try using this method to get to the actual file &lt;A href="https://xsoar.pan.dev/docs/reference/api/demisto-class#getfilepath" target="_blank"&gt;https://xsoar.pan.dev/docs/reference/api/demisto-class#getfilepath&lt;/A&gt;. Ensure the actual file is accessible and then you can run &lt;SPAN&gt;openpyxl or other methods on it. Id recommend not using very large Excel files as this can be difficult to operate on.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Let me know if this helps.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;MSysec&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2025 15:06:58 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/issues-with-openpyxl-quot-openpyxl-does-not-support-file-format/m-p/1223586#M3943</guid>
      <dc:creator>michaelsysec242</dc:creator>
      <dc:date>2025-03-12T15:06:58Z</dc:date>
    </item>
  </channel>
</rss>

