BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Eusuee
Fluorite | Level 6

Yesterday I tried to attach a file in email via SAS the first time, but the weird thing was, it worked fine if I attached the CSV file, but if I tried to attach a xlsx file, the attachment in email couldn't be opened.

I then clicked on the attached file, it said "Excel found unreadable content in "filename.xlsx". Do you want to recover the contents of this workbook? If you trust the source of this workbook, click yes."

Then I clicked on yes, it showed another error message "Excel cannot open the file "filename.xlsx" because the file format or the file extension is not valid. Verify that the file has not been corrupted and the the file extension matches the format of the file."

I checked the xlsx file, it looked all good and could be opened on local computer without question. Does anybody know what could cause the issue? Thanks!

filename outmail email 'xxxx@xxxxxx.COM'

                      subject="xxxxxxxxxxxxx"

                      attach="/xxx/xxxx/xxxx.xlsx";

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Try this, perhaps ordering is required. This works for me.

 

attach=("Spreadsheet.xlsx"  content_type="application/xlsx")

 

If sending multiple files, specify the content type for each attachment.  Example:

 

attach=("Spreadsheet1.xlsx"  content_type="application/xlsx" 
"Spreadsheet2.xlsx"  content_type="application/xlsx" 
"Spreadsheet3.xlsx"  content_type="application/xlsx" 
"Spreadsheet4.xlsx"  content_type="application/xlsx")

 

 

View solution in original post

12 REPLIES 12
ballardw
Super User

The issue may be with how the xlsx file was created. If created in SAS provide example code.

Eusuee
Fluorite | Level 6

 

proc export data=outlib.test outfile="test.xlsx"

dbms=xlsx replace;

sheet="Data";

run;

SASKiwi
PROC Star

With Excel you need to add this to your FILENAME:

content_type="application/xlsx"

Eusuee
Fluorite | Level 6

Thanks SASKiwi. I added content_type as you suggested but failed with the same error again.

SASKiwi
PROC Star

Try this, perhaps ordering is required. This works for me.

 

attach=("Spreadsheet.xlsx"  content_type="application/xlsx")

 

If sending multiple files, specify the content type for each attachment.  Example:

 

attach=("Spreadsheet1.xlsx"  content_type="application/xlsx" 
"Spreadsheet2.xlsx"  content_type="application/xlsx" 
"Spreadsheet3.xlsx"  content_type="application/xlsx" 
"Spreadsheet4.xlsx"  content_type="application/xlsx")

 

 

Eusuee
Fluorite | Level 6

Yeah it works now!!! So excited! Thanks a million SASKiwi!

mg02492
Calcite | Level 5

Thank you SO much.  Just used this with a file created with the new ODS excel destination.

pathanfahim1986
Fluorite | Level 6

Hi , I had a same problem. And took long time around this. With above solution. It is working fine. Thanks you very much. Fahim

brulard
Pyrite | Level 9
Experienced the same problem and this solved for it. Thanks!
SuryaKiran
Meteorite | Level 14

Thanks @SASKiwi

 

This solved my problem. I was sending some xlsx files to sharepoint by email and encountered with this problem. In my case I have several files to attach, so it worked for me only if I have content_type="application/xlsx" next to all the files.

 

Like this:

attach=("Spreadsheet1.xlsx"  content_type="application/xlsx" "Spreadsheet2.xlsx"  content_type="application/xlsx" "Spreadsheet3.xlsx"  content_type="application/xlsx" "Spreadsheet4.xlsx"  content_type="application/xlsx")

 

Thanks,
Suryakiran
SASKiwi
PROC Star

Wow! Good to see this tip has helped so many.

mkeintz
PROC Star

Because of @brulard's recent reply to this topic, it showed up on recent activity.

 

@Eusuee.  If you are still around, why not mark this topic as solved?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 23080 views
  • 23 likes
  • 8 in conversation