<?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 Re: Generating Multiple Excels for SQL Query in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/generating-multiple-excels-for-sql-query/m-p/114324#M44785</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/142418"&gt;@libpekin&lt;/a&gt;, is filepath pointing to a DBFS path? Because writing directly to DBFS paths using to_excel() is not supported due to DBFS limitations with certain file operations, especially random writes.&lt;/P&gt;&lt;P&gt;As a workaround, first save the Excel file to a local path on the driver node, using &lt;STRONG&gt;to_excel()&lt;/STRONG&gt;, then use &lt;STRONG&gt;dbutils.fs.cp()&lt;/STRONG&gt; to move it to DBFS.&lt;/P&gt;&lt;P&gt;Let me know if this doesn’t work.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Apr 2025 19:11:44 GMT</pubDate>
    <dc:creator>Renu_</dc:creator>
    <dc:date>2025-04-02T19:11:44Z</dc:date>
    <item>
      <title>Generating Multiple Excels for SQL Query</title>
      <link>https://community.databricks.com/t5/data-engineering/generating-multiple-excels-for-sql-query/m-p/111616#M43952</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am getting "OSError: Errno 95: Operation not supported for the code below. I have 'openpyxl 3.1.5' installed on the cluster and have imported all required modules. I am sure this is something small, but I can't put my finger on it why this is erroring out. Thanks for taking a look!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;df = spark.sql(f"""
    SELECT
        custId,
        locId
    FROM salesorders
    WHERE year = '2025'
    LIMIT 100
""")

df_region = spark.sql(f"""
    SELECT DISTINCT Id
    FROM sales.region
    WHERE isactive = 1 AND year = '2025'
""")

for row in df_region.rdd.collect():
    regId = row.__getitem__('Id')
    df_filtered = df.where(df.locId == regId)
    df_filtered.toPandas().to_excel(filePath.format(locId=regId), index=False, engine='openpyxl')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 17:43:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/generating-multiple-excels-for-sql-query/m-p/111616#M43952</guid>
      <dc:creator>libpekin</dc:creator>
      <dc:date>2025-03-03T17:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Generating Multiple Excels for SQL Query</title>
      <link>https://community.databricks.com/t5/data-engineering/generating-multiple-excels-for-sql-query/m-p/114324#M44785</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/142418"&gt;@libpekin&lt;/a&gt;, is filepath pointing to a DBFS path? Because writing directly to DBFS paths using to_excel() is not supported due to DBFS limitations with certain file operations, especially random writes.&lt;/P&gt;&lt;P&gt;As a workaround, first save the Excel file to a local path on the driver node, using &lt;STRONG&gt;to_excel()&lt;/STRONG&gt;, then use &lt;STRONG&gt;dbutils.fs.cp()&lt;/STRONG&gt; to move it to DBFS.&lt;/P&gt;&lt;P&gt;Let me know if this doesn’t work.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2025 19:11:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/generating-multiple-excels-for-sql-query/m-p/114324#M44785</guid>
      <dc:creator>Renu_</dc:creator>
      <dc:date>2025-04-02T19:11:44Z</dc:date>
    </item>
  </channel>
</rss>

