473,659 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.creat eobject("ADODB. connection")
set Rs=server.creat eobject("ADODB. recordset")
Cn.open "MyConnectionSt ring"
Rs.open "mysqlquery",Cn ,1,3
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der "Content-Disposition", "attachment ;
filename=Test.x lsx"
if Rs.eof <true then
response.write "<table border=1>"
while not Rs.eof
response.write "<tr><td>" & Rs.fields("myda tafield") & "</
td></tr>"
Rs.movenext
wend

response.write "</table>"
end if

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

..........

You'll find better luck in another newsgroup.

Maybe this one:
microsoft.publi c.inetserver.as p.general


"Doogie" <dn******@dtgne t.comwrote in message
news:68******** *************** ***********@y18 g2000yqn.google groups.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.creat eobject("ADODB. connection")
set Rs=server.creat eobject("ADODB. recordset")
Cn.open "MyConnectionSt ring"
Rs.open "mysqlquery",Cn ,1,3
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der "Content-Disposition", "attachment ;
filename=Test.x lsx"
if Rs.eof <true then
response.write "<table border=1>"
while not Rs.eof
response.write "<tr><td>" & Rs.fields("myda tafield") & "</
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
6184
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 queries. A number of fields in the queries are designed to become formulae in Excel after the export has taken place (and they need to be in Excel rather than Access). I need to use the TransferSpreadsheet Method rather than the OutputTo to enable...
7
2014
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 'Start a new workbook in Excel.
18
25716
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 format anywhere? Is there any c# class that will let me do this?
1
4799
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 last): File "C:\Documents and Settings\kusumap\Desktop\Girish.py", line 7, in ? worksheet.OLEObjects.Add(Filename="C:\Documents and Settings
0
1743
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, Excel.XlPlatform.xlWindows, Excel.XlTextParsingType.xlDelimited, Excel.XlTextQualifier.xlTextQualifierDoubleQuote, true, 0, false, true, Excel.XlCorruptLoad.xlNormalLoad);
4
7123
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" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"> <xsl:output method="html" encoding="UTF-8"/>
1
10488
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 trying to export to Excel using a command in an Access Form. RowID strFY AccountID CostElementWBS 1 2008 1 7 2 2008 1 7 I want to...
0
1911
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 the excel by using OLE or Msflexgrid.. i am very confuse..hope u can give me some tip on how should i plot my graph using the visual basci interface. here i gave my program: Option Explicit Dim Excel As Object Dim ExcelSheet As Object Dim...
1
4470
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 didnt find any thing regarding this
3
11625
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 stored as text once placed into excel. Is there a way to keep them as a currency value? Regards, Nanditha
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.