Avatar of gdemaria
Flag for United States of America asked on

XML created Excel sheet opens with warnings

I am creating an Excel spreadsheet using XML, I've written the XML via Coldfusion, but I don't think it matters which language is used.

Problem 1) When opening the file, I get the warning message "You are trying to open 'myFile.xls' in a different format than specified by the file extension.  Verify that it is not corrupted and from a trusted source before opening the file"     I've tried many different content types, etc.  How do I get rid of this message?

Problem 2)  When I save the file to my desktop it wants to save it as an .XML file and I have to change the type manually.   I can't ask my users to do this.   I need to generate the file and have it act like an Excel file.

For content types, I have used every variation of Excel such as..


Thanks for any help!
Microsoft ExcelColdFusion Language

Avatar of undefined
Last Comment

8/22/2022 - Mon


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

btw ScriptAddict - the code from Ben's site produces the warning as well.

Hey Sid,  I feared that answer.

Would you know of a way I can get Coldfusion to open the file and do a "Save As" so I can change the data type automatically?

That would help with my other problem (#2 above), the user is going to be asked to save it as a .xml file which will make no sense to them at all
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

if you add

    value="attachment; filename=myfile.xls"

it will name it .xls no matter what the source is

(I think that's what you are asking for?)

But even saved, when they open it they'll get the warning.

Stupid security features. Why can't Microsoft be more like Apple - they -never- have security problems <cough> :)

> it will name it .xls no matter what the source is

actually, I am naming it xls.   I open the file from a web link, when I try to save it to my desktop it wants to save it as .xml even though I named it xls.   I think that is worse than the warning.   Users will be saving the file as .xml and have no idea what to do with it

Unfortunately as long as the actual content and extension differ, I don't think there's anything you can do about it.  As that's exactly what the "extension hardening" stuff is designed to do.  Aside from generating a real excel file or the user changing their registry settings, there isn't a way to avoid it AFAIK.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

so you're generating a static xml file and dropping a link for the user?

<a href="test.xls">Open</a>

and it's trying to open it as an xml file??

Don't see that behaviour here.

or am I confused (more than usual at least)

(fwiw I thought POI might be able to generate "real" excel files but apparently not http://forums.adobe.com/thread/209449)

Thanks agx,  it makes sense in some ways, but then again, why does MS offer XML as a method to create an Excel file if they won't let it become an Excel file! :)

Do you know of a way to automatically open a file and do a "save as" perhaps using CFEXECUTE or something?

Sid, I am using XML to generate an Excel worksheet.  I use cfcontent to "name" the file and associate the file type.  I never actually save the file on the server-side, just generate it and the user can open it.  

I named the file .xls in hopes that when opened it would become an Excel file.  Although it gives this warning we've been discussing and it does open it in Excel, there is one more negative side effect - when the user goes to save the file to their desktop, the "file type" is defaulted to xml.   Most users don't pay attention to the file type and just give it a name and save it.  This is much worse to me than the warning, the user has to save it to their computer as an .xls file or they will lose it or not know what to do with it.

aha! yes I can reproduce that here when saving the file which is downloaded as xls but excel tries to name it xml on save or save as. Probably nothing you can do about that....Silly excel.

afaik cfexecute won't help as it's execute server side...
Your help has saved me hundreds of hours of internet surfing.

I've been digging around trying to find a little script or .ini file or something that would open the file and do a "save as" under a different type (the real Excel type).

I could do this on the server side before delivering the file to the user, perhaps?

I was just thinking the same thing - If you've got excel on the server you could probably open the file xml & save as xls maybe http://www.visualbasicscript.com/Convert-XML-file-to-Excel-2003-XLS-file-m66035.aspx

I believe that openoffice has an API which may do something similar without needing an excel license
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

> I believe that openoffice has an API which may do something similar
> without needing an excel license

Yeah. Though I rarely recommend COM, it is way easier in this case :)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Coast Line

hi, check if this website can be of any help


That's what Sid already suggested above ie Use COM
Coast Line

bit late in jumping into question ;)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

Thanks for the help guys.

I ended up leaving the extension as .xml so the warning does not appear.   The file, even though .xml, does open Excel.   But I put a note on the page recommending users to do a SAVE AS and set the type to their preferred version of Excel (2010, 2003..)

Not a solution I would like for the general public, but this is limited to the more advance and limited set of administrators; so I think it is ok.

Thanks agian