View Full Version : Upload of xlsx file (Office 2007)
paulafernandes
01-14-2009, 06:25 PM
Hello everyone,
I need to be able to upload a several kind of files with data: xls, txt, csv and xlsx. The first 3 are working fine, but I can't seem to get the xlsx upload working!
I mean, the upload is done, but when it gets to the server is corrupted.
I've been done a lot of reading, but I can't find anything about this!
I hope someone here can help me, because I really don't know how am I going to do this!
Thank you,
Paula
bermanbp
01-14-2009, 08:59 PM
Well, I doubt that this is the problem since you say the file is being uploaded but...
Make sure that you have the mime type for the newer Office 2007 documents configured in IIS. I know IIS 6 doesn't have these by default in some cases.
If that's not the issue, can you supply any more information and/or code?
-b
paulafernandes
01-16-2009, 12:16 PM
Hello bermanbp
I believe I read everything there is about MIME Types, but it still not working.
I followed your instructions and added the on the IIS the MIME Types for Office 2007.
But I still get the same behaviour: The xlsx file is uploaded, but when I try to work with it in ASP, I get the following error:
Microsoft Office Access Database Engine error '80004005'
External table is not in the expected format.
When I try to open it, office gives me this message:
"Excel found unreadable content in ***.xlsx. Do you want to recover the contents of this workbook?"
When I click yes, this appear:
"Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded."
So I concluded that the file is uploaded but it gets to the server corrupted.
On my ASP page I have the following code for the upload that is exactly the same I use to upload txt, csv and xls files.:
Public Function saveToFile(name, path)
If dict.Exists(name) Then
Dim temp
temp = dict(name).Item("Value")
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fso.CreateTextFile(path)
For tPoint = 1 to LenB(temp)
file.Write Chr(AscB(MidB(temp,tPoint,1)))
Next
file.Close
saveToFile = True
Else
saveToFile = False
End If
End Function
And I believe this is where all goes wrong...
And I'm again in a stage where I can get further...
What else can I do? Any ideas?
Thank you!
Paula
paulafernandes
01-16-2009, 05:53 PM
Update on my situation:
The files of Office 2007 are compressed files, if you try to change the extension to .zip and then extract it, you get some folders and a lot of xml files where the information is spread.
So... The options are:
- Read the file on client side, save the content and then create a xlsx file on server side and write the information. I don't think this is a good solution, it would depend on the client machine and we work with large files.
- Do the zip/unzip stuff and create a routine to get all the data.
Right now, neither are good solutions for me.
So if someone knows another way to do this, I would be very appreciated.
If not, well, maybe could help someone else.
Thank you,
Paula
SouthwaterDave
01-17-2009, 10:19 PM
As xls uploads are OK then your saveToFile function is happy writing binary data. So it should be OK writing xlsx files. Xlsx files are (as you say) zip files so they are binary files although the unzipped contents are text files containing xml.
It appears that your upload has let you down. I use ASP.NET these days so I have forgotten how to upload files in ASP. You need a specially written DLL don't you? If so, can you get a better upload DLL?
Failing that, could you ask the user to cut and paste from Excel to a <textbox>? The rows wiill be delimited by vbCrLf and the columns will be delimited by vbTab.
Another option might be an ftp server (which can be password protected) to allow users to upload files. They would logon in Internet Explorer (or possibly Firefox) and drag and drop files from Windows Explorer to the target directory in the browser window.
paulafernandes
01-19-2009, 09:45 AM
Hello SouthwaterDave
Thank you for your response.
Right now, I have to leave this project because I have to give priority to other projects. I've already thought on the FTP option, and probably it's what I'll do when I pick on this project again. Or I'll try to do this in .NET. I don't know...
Thank you!
Paula
SouthwaterDave
01-19-2009, 12:47 PM
I didn't offer ASP.NET as a possible solution because I know there is a lot to learn in moving from ASP to ASP.NET. But if you already know ASP.NET then that is a good option. File uploads are easy: I've done it on at least 2 different projects. I could even provide an example if you need one.
Another possible option, in an intranet only, would be to provide a network share on the web server and allow users to copy their files to that. Your ASP application would then be able to use those files as required...
paulafernandes
01-19-2009, 03:08 PM
Hi SouthwaterDave
Yes, I've already worked with ASP.NET on my previous job. Since I'm working in my new company I have to work in old applications that are in classic ASP.
For me it was a huge setback, but I have no choice...
This upload is to an web application where people upload files with their contacts to send SMS's. Then that data is saved on a database.
Now I have to work in another module of the application, but when I get back to this I will try the upload in ASP.NET.
If not, I already have an FTP upload working in another project, I will use it to do this.
I'm only insisting on this because I'm really curious to know if there is no other way to do it.
But I have others alternatives, and that is what is important. :)
Thank you again!
Paula
trazek
04-24-2009, 06:53 PM
Hello everyone!
I am new to the forum and am having the same problem as posted. I am using classic ASP and have an upload form that works for xls files. When I try and upload xlsx files it works some times but not others. Here is what happens:
- I create an xlsx file(file #1), upload it successfully and recreate a new xlsx file(file #2) on the server. File #2 is fine.
- I edit file #1 by say, deleting an entire column and upload it again, creating file #3
- When I open file #3 it Excel tells me it found unreadable data.
Now sometimes the following will happen:
- Create file #1 and upload it using same code. File #2 is created and is fine.
- I edit file #1 but this time just replace values in existing cells. No deletion of columns.
- Upload newly edited file #1, creating file #3. File #3 is fine.
Any help with this inconsistency would be appreciated! Thanks!
trazek
04-28-2009, 05:03 PM
Well if anyone is still having issues with this, I found this excerpt from a book titled "Excel 2007 VBA":
http://books.google.com/books?id=c54m541Y6kcC&pg=PA266&lpg=PA266&dq=command+line+unzip+excel+2007&source=bl&ots=kGNb2AAmFK&sig=efxY8rjwYJVyo1jhCJYO8f7om4A&hl=en&ei=3KvwSe3BJeawtgfF6tGvDw&sa=X&oi=book_result&ct=result&resnum=1#PPA266,M1
The technique requires you to have XP on the server but that's probably not a problem. This worked perfectly for me on files Excel had trouble opening and zip files my zip program couldn't open. Good luck!
chetan.akarte
04-30-2009, 05:49 AM
Hi,
Here is a good example to Upload of xlsx file - (Office 2007) Read and Display Data From an Excel File (.xsl or .xlsx) in ASP.NET (http://www.tipsntracks.com/100/read-and-display-data-from-an-excel-file-xsl-or-xlsx-in-aspnet.html)
While for reading xlsx (Excel 2007). xlsx (Excel 2007) contains Microsoft.ACE.OLEDB.12.0 as the provider. This is the new Access database engine OLE DB driver and is also capable of reading Excel 2003. We are going to use it to read xlsx (Excel 2007) data.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.