Python Sending Excel Attachment corrupts file - python

Using the ezgmail library, I am sending an E-mail with an Excel file attached.
I am able to send the E-mail with the attached Excel file, but when I open the Excel file from the sent E-mail, it seems it becomes corrupt for some reason because I get this message:
We found a problem with some content in 'attached_file.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.
When I click "Yes" I get:
Excel cannot open the file 'attached_file.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
The excel file that I attach opens fine from my desktop, or if I E-mail it manually. I get these prompts only after E-mailing it via my python script which leverages ezgmail. Does anyone have ideas?

Related

Accessing an Excel file in a .dtsx that was generated through Xlwt library (Python) raises error CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER

I have a web scraper written in Python, fetching raw data from the HTML of a page and writing it onto a 97-2003 Workbook Excel file, using the Xlwt library. I then have a .dtsx file with some tasks, where one of them is an Excel Source task to fetch data from an Excel file. Later down the road, that data is inserted into a SQL Server table.
If I try to access my newly-generated Excel file with said task, I get an OLE DB error
External table is not in the expected format
And I cannot run my dtsx. However, if I manually access the Excel file through my File Explorer, open it and close it again (don't even need to save it), suddenly my SSIS task works without a problem, fetching all the columns and all the info. What could possibly be causing this behavior?
External table is not in the expected format
The error above happens when the Excel file is corrupted and cannot be opened by Access Database Engine (OLE DB provider) even if you can open the file from Excel.
In general, the solution is to open this Excel manually which will auto repair it. In a similar case and if the process is repeated many times, you can automate opening and repairing excel using a C# script using Interop.Excel library.
Additional Information
What .xlsx file format is this?
Getting "External table is not in the expected format." error while trying to import an Excel File in SSIS

How Open PASSWORD PROTECTED pdf file using textract

I'm working on pdf's and have created full project but now facing one problem that how to parse through contents of Password Protected PDF files (I know that password).

Open password protected excel and find last row and read till that|| Python

SO POST LINK
With reference from above content am able to open a password protected excel, but i have a requirement to read the excel data as well with the password protected excel that is opened. We cant use the method openpyxl.load_workbook('sample.xlsx') as again it prompts error when opening a password protected file, is there any other method to read the excel as a continuation of the shared link.

Excel saved with openpyxl can't be opened in another system

we have a reporting system which display some dashboards, and we need to update a data table which has the numbers for the dashboard everyday. The problem is the excel file which is saved with openpyxl can't be opened in the reporting system, Everyday after updating the numbers in the excel file, I need to open the excel file and click "save" button, then upload the excel file to the reporting server, then the numbers in the excel file can be read. if I just upload the excel file to the server without doing anything with the excel file, then the server won't able to read data from it. what can be the problem? my code is:
wb = load_workbook('Datasource_klip.xlsx')
ws=wb["Day"]
ws['B%d'%(row_index)]=month
...
wb.save('Datasource_klip.xlsx')

How to use python cgi code to search file and display in browser along with its name

I have a simple html file with text input for file name. It will search the file in the folders and display contents in the browser using cgi script. The file can be pdf or image file. Wish to display 'file name as well as the contents in the browser'. Currently it displays either file name or contents but not both depending on Content type selected. Kindly guide. I need the exact code.

Categories