473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Exporting to Excel using new version of Excel

Can anoyne tell me why this VBScript will create the file to Excel
just fine, but the Excel file will not open up? I am saving it as a
xlsx file instead of an xls one and I have the new version of Excel on
my machine and have opened other Excel files with that extension but
this one I get the following error:

"Excel cannot open the file 'Test.xlsx' because the file format or
file extension is not valid. Verify that the file has not been
corrupted and the file extension matches the format of the file."

If I switch the file type to be .xls instead of .xlsx, it will save
the file and open with no problems. Below is an example of the VB
script I'm using.

dim Cn,Rs
set Cn=server.createobject("ADODB.connection")
set Rs=server.createobject("ADODB.recordset")
Cn.open "MyConnectionString"
Rs.open "mysqlquery",Cn,1,3
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;
filename=Test.xlsx"
if Rs.eof <true then
response.write "<table border=1>"
while not Rs.eof
response.write "<tr><td>" & Rs.fields("mydatafield") & "</
td></tr>"
Rs.movenext
wend

response.write "</table>"
end if

set rs=nothing
Cn.close
Nov 19 '08 #1
1 3100
This is a newsgroup for asp.NET , not "classic" asp.

..........

You'll find better luck in another newsgroup.

Maybe this one:
microsoft.public.inetserver.asp.general


"Doogie" <dn******@dtgnet.comwrote in message
news:68**********************************@y18g2000 yqn.googlegroups.com...
Can anoyne tell me why this VBScript will create the file to Excel
just fine, but the Excel file will not open up? I am saving it as a
xlsx file instead of an xls one and I have the new version of Excel on
my machine and have opened other Excel files with that extension but
this one I get the following error:

"Excel cannot open the file 'Test.xlsx' because the file format or
file extension is not valid. Verify that the file has not been
corrupted and the file extension matches the format of the file."

If I switch the file type to be .xls instead of .xlsx, it will save
the file and open with no problems. Below is an example of the VB
script I'm using.

dim Cn,Rs
set Cn=server.createobject("ADODB.connection")
set Rs=server.createobject("ADODB.recordset")
Cn.open "MyConnectionString"
Rs.open "mysqlquery",Cn,1,3
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;
filename=Test.xlsx"
if Rs.eof <true then
response.write "<table border=1>"
while not Rs.eof
response.write "<tr><td>" & Rs.fields("mydatafield") & "</
td></tr>"
Rs.movenext
wend

response.write "</table>"
end if

set rs=nothing
Cn.close

Nov 19 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: barma16 | last post by:
I've hit a bit of a brick wall here, and could use some advice. I have an Access application whose output is a four-tab Excel spreadsheet where three of the four tabs are the result of database...
7
by: Gal Zilberman | last post by:
Hi I've found a code which should work, but it doesn't. Please Help Imports Microsoft.Office.Interop ' Refence in the Class Dim oExcel As New Object Dim oBook As Object Dim oSheet As Object...
18
by: John Bailo | last post by:
I want to write an Excel file (.xls format) from some database data. I don't want to use Excel.exe because of all the automation and security issues. Does Microsoft document the .xls file...
1
by: Girish | last post by:
Hi, I want to embed a txt document into an excel using python. Here is my code, but i get an error message =================================================== Traceback (most recent call...
0
by: bebek_tetangga | last post by:
Hello, I'm trying to open a .txt file in Excel using C#. Here is my code: clsWorkbook = clsExcel.Workbooks.Open(dailyPath + "\\070701N.txt", 2, false, 5, "", "", true,...
4
by: sadc1986 | last post by:
How does one introduce multiple worksheets in a excel using Xslt Transforms my code... Please suggest <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
0
by: wankhusairi | last post by:
hallo sir .. i am still new on using vb and i have tried to load an excel using a visual basic interface.. but if i wanted to plot my excel data what should i do.. must i cahnge my program on loading...
1
by: rameshmandapati | last post by:
hi i have a problem with Excel. iam adding data to a cell in Excel using java script var excel = new ActiveXObject ("Excel.Application"); but i want image also i search in google i...
3
by: nandithadevaraj | last post by:
When exporting a report to excel, is it possible to keep the properties around numeric values? More specifically - when exporting a report into excel, all of the numbers in a currency column are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.