Wrox Programmer Forums
|
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
 
Old October 10th, 2007, 05:22 AM
Registered User
 
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to courtney_ctisn
Default 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!

 
Old October 10th, 2007, 07:55 AM
Registered User
 
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to courtney_ctisn
Default

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.

 
Old October 10th, 2007, 08:02 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Total stab in the dark here but, let me guess, you are opening the file through Office 2007, right?


================================================== =========
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
================================================== =========
 
Old October 10th, 2007, 08:09 AM
Registered User
 
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to courtney_ctisn
Default

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.

 
Old October 10th, 2007, 08:15 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
 
Old October 10th, 2007, 08:41 AM
Registered User
 
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to courtney_ctisn
Default

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.

 
Old October 11th, 2007, 03:05 AM
Registered User
 
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to courtney_ctisn
Default

Anybody else got any more thoughts on this one??

:D

 
Old October 18th, 2007, 09:50 AM
Registered User
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ryanegt
Default

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.
 
Old October 18th, 2007, 09:57 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I really think this has to do with Office 2007 and not with any of your code. Unfortunately it doesnt seem like there is a fix:
http://blogs.msdn.com/erikaehrli/arc...ffice2007.aspx

Have you tested your apps using, say, office 2003?

================================================== =========
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
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in Import/Export surendraparashar SQL Server 2000 5 November 6th, 2007 01:16 PM
problem with export to excel supreeth Access VBA 2 September 10th, 2007 03:04 AM
Crystal Report Export problem to excel spmano1983 VB.NET 0 August 17th, 2007 01:33 AM
Import & Export Excel File prasanta2expert ASP.NET 1.0 and 1.1 Basics 5 March 5th, 2007 09:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.