Solved

Exporting Data into Excel from ASP page generates a warning when opening the file

Posted on 2008-10-10
2
305 Views
Last Modified: 2011-10-03
I have an ASP page that extracts info from a database and writes it to an excel file.  When I open the file in Excel I get the following warning:

The File you are trying to open is in a different format than specified by the file extension.

I open the file anyway and it is correct.  Can someone tell me what I'm doing wrong so the warning is not displayed?
Dim sOutput
strFileName = "fcuevaluation" & syear
Response.expires= 0
Response.Expires=-1
Response.Expiresabsolute = Now() - 1 
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "content-disposition", "attachment;filename=" & strFileName & ".xls"
' Remove the charset from the Content-Type header.
Response.Charset = ""
sOutput = "<html><body>"
sOutput = sOutput & "<table border='0' bordercolor='#000000' cellpadding='3' cellspacing='0' width='100%'><tr><th>Date</th><th>Program</th><th>Overall Quality of CD Program</th><th>Quality of Information Presented</th><th>Quality of Presentation</th><th>Relevance of Information</th><th>Free From Bias</th><th>Free From Bias Explanation</th><th>Learned About This Activity From</th><th>Information Will Help My Practice</th><th>Help My Practice Explain</th><th>Identified Areas of Weakness</th><th>Future Presentations That May Help</th><th>Will Make Changes in Practice</th><th>Change in Practice Explain</th><th>Comments</th></tr>"
do while NOT rs.EOF
  sOutput = sOutput & "<tr><td>"& rs("Date") & "</td>"
  sOutput = sOutput & "<td>" & rs("Program") & "</td>"
  sOutput = sOutput & "<td>" & formatCDRating(rs("QualCDProg")) & "</td>"
  sOutput = sOutput & "<td>" & formatRating(rs("InfoRating")) & "</td>"
  sOutput = sOutput & "<td>" & formatRating(rs("PresentationRating")) & "</td>"
  sOutput = sOutput & "<td>" & formatRating(rs("InfoRelvance")) & "</td>"
  if rs("FreeBias") = true Then
     sOutput = sOutput & "<td>Yes</td>"
  else
     sOutput = sOutput & "<td>No</td>"
  end if
  sOutput = sOutput & "<td>" & rs("Balanced") & "</td>"
  if rs("LearnAboutActivity") = "DDW" then
     sOutput = sOutput & "<td>DDW</td>"
  end if
  if rs("LearnAboutActivity") = "Website" then
     sOutput = sOutput & "<td>AGA Website</td>"
  end if
  if rs("LearnAboutActivity") = "Email" then
     sOutput = sOutput & "<td>AGA Email</td>"
  end if
  if rs("LearnAboutActivity") = "Publication" then
     sOutput = sOutput & "<td>AGA Publication</td>"
  end if
  if rs("LearnAboutActivity") = "Other" then
     sOutput = sOutput & "<td>Other</td>"
  end if
  if rs("HelpMyPractice") = true Then
     sOutput = sOutput & "<td>Yes</td>"
  else
     sOutput = sOutput & "<td>No</td>"
  end if
  sOutput = sOutput & "<td>" & rs("HelpMyPracticeHow") & "</td>"
  if rs("PersonalKnowledge") = true Then
     sOutput = sOutput & "<td>Yes</td>"
  else
     sOutput = sOutput & "<td>No</td>"
  end if
  sOutput = sOutput & "<td>" & rs("PersonalKnowledgeHow") & "</td>"
  sOutput = sOutput & "<td>" & rs("Topics") & "</td>"
  if rs("ChangePractice") = true Then
      sOutput = sOutput & "<td>Yes</td>"
  else
      sOutput = sOutput & "<td>No</td>"
  end if
  sOutput = sOutput & "<td>" & rs("ChangePracticeHow") & "</td>"
  sOutput = sOutput & "<td>" & rs("Comments") & "</td></tr>"
  rs.MoveNext
loop
sOutput = sOutput & "</table></body></html>"
Response.Write sOutput
Response.End()

Open in new window

0
Comment
Question by:dyarosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

Accepted Solution

by:
LZ1 earned 500 total points
ID: 22689101
What version of Excel are you using???
If you are using Excel 2007 then the warning will be there and there is nothing you can do about it.  This is a known issue that Microsoft acknowledges, but hasn't done anything about it.
 
0
 

Author Closing Comment

by:dyarosh
ID: 31505071
I'm using Excel 2007 and getting the error.  The person who will be using the file is using an earlier version of excel.  I just tried it using Excel 2002 and did not get the error.  Thank you.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question