admin管理员组

文章数量:1122832

I am very new to Python and getting an error that I can't seem to resolve. In my Python script I am querying a Snowflake database and then turning the results into a dataFrame (df). Following this, I simply write an .xlsx file.

This all works fine until I open the Excel file. I'm greeted by a message "We found a problem with some content in the ‘file.XLSX’. Do you want us to try to recover as much as we can?" Upon clicking "yes" the file contains all of the data in a repaired version of the file. The log of repairs is as follows "Removed Records: Formula from /xl/worksheets/sheet1.xml part"

I've tried to leverage a number of solutions with no luck. I experimented with using xlwings and cleaning my columns to strip any potential leading "=". Again, I'm new to Python so I don't really know where to go from here.

import os
import snowflake.connector
import pandas as pd
from openpyxl import load_workbook

#SQL Code - Removed for Privacy

# Execute the query
cursor_clm_dm = conn_clm_dm.cursor()
cursor_clm_dm.execute(query)

# Fetch the results
results = cursor_clm_dm.fetchall()

# Convert the results to a Pandas DataFrame
columns = [desc[0] for desc in cursor_clm_dm.description]
df = pd.DataFrame(results, columns=columns)

# Close the cursor and connection
cursor_clm_dm.close()
conn_clm_dm.close()
conn_clm_dw.close()

# Display the DataFrame
print(df)

df.to_excel('C:\\Users\\JohnG\\Downloads\\file.xlsx', index=False)
print('done')

本文标签: