 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 10th, 2007, 05:22 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Excel Export then Import problem
Iâm sure this problem probably has been answered on this forum, but Iâm not finding the solution and Iâve been looking for over half an hour.
Basically Iâm exporting a Excel from an ASP page, and then once updated I want to import the same excel file. Now at the moment the exported Excel file doesnât seem to be formatted correctly, here is the code I use to create it.
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=file.xls"
if results.eof <> true then
%>
<HTML><BODY>
<TABLE>
<TR>
<TH>Header</TH>
</TR>
<%
while not results.eof
response.write "<TR>" &_
"<TD>" & results.fields("field") & "</TD>" &_
"</TR>"
results.movenext
wend
response.write "</TABLE></BODY></HTML>"
end if
set results=nothing
If I attempt to upload that created Excel file it throws this error:
Microsoft JET Database Engine (0x80004005)
External table is not in the expected format.
But if I upload a file created directly from Excel, no problem at allâ¦need help, this is doing my bloody head in!
|
|

October 10th, 2007, 07:55 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No reply? :(
When I open the exported Excel file I get a prompt saying:
The file you are trying to open, 'filename', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source blah blah
The prompt options are Yes No and Help, if you click yes it does display the file in Excel exactly how its intended, but clearly there is something wrong with the way the file is exported.
|
|

October 10th, 2007, 08:09 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the reply, appreciate it.
Yes mate, office 2007.
I thought it could be an office 2007 compat prob, but why is it if I re-save the file as an Excel book, my upload works, but if I attempt to upload the exported file it has problems?
Here is a snippit my upload code:
strExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data Source=" & strPath & ";" &_
"Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;"""
Set cnnExcel = Server.CreateObject("ADODB.Connection")
With cnnExcel
.ConnectionTimeout = 20
.ConnectionString = strExcelConn
.Open
End With
' set up record set for excel doc
Set rsExcel = Server.CreateObject("ADODB.Recordset")
With rsExcel
.ActiveConnection = cnnExcel
.CursorType = 3
.LockType = 2
End With
rsExcel.Source = "SELECT * FROM [sheet1$]"
rsExcel.open
I'm treating the Excel file like a database, then while reading I'm going to inport the data to SQLserver 2005.
|
|

October 10th, 2007, 08:15 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
My guess would be because once you save the file, after opening it and receiving the error message, the format gets corrupted, though I can't explain it. (I had the same problem in my r.a.d. controls)
2 things to try would be: A) save the file as file.xlsx or B) Change the file extension after the file has been downloaded.
hth.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
|
|

October 10th, 2007, 08:41 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Tried that, even less luck.
Excel 2007 just won't load it if I change the extension to xlsx. I think it could be something to do with the header when the file is written because when I attempt to "save as" the exported file it treats the document as a "web page", obviously something isn't being set when the file is created.
|
|

October 11th, 2007, 03:05 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Anybody else got any more thoughts on this one??
:D
|
|

October 18th, 2007, 09:50 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I also have been looking for a solution to a problem similar to this dealing with Excel 2007. I think it stems from the exported data being in an HTML table format which is now a deprecated feature. I'm doing the same sort of thing - exporting text data from a PHP (not asp) file with the Excel MIME. The file opens, but not without displaying the notice:
"The file you are trying to open, 'test.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source... Do you want to open the file now?"
Again, the conflict I believe arises from having a .xls file with HTML formatted data. If I rename my "test.xls" to "test.html" and open it with excel, I see no such error. If somebody finds a work-around to this issue (without reducing my data to binary), please let me know. The fact that I'm working with open source, does add an additional degree of difficulty handling MS products.
|
|
 |