dba123
asked on
Trying to get XML to Export into Excel Doc from ASP
References:
Here is my code below. The following is happening:
1) I get a save prompt but it states in the prompt:
FileName: my current asp page name
From: my site.com
2) When I try to SAve the file, I get the error "Internet Explorer cannot download asp page name from my site.com. Internet Explorer was not able to open this Internet site"
3) Why is it trying to download an asp page rather than export to Excel and prompt me to save an Excel file? Or will it if I get this to stop erroring out?
My code
<%@Language="VBScript"%>
<%
'Using the Northwind as an example:
'works for Excel 2000 and Excel 2002
Response.AddHeader "Content-Disposition", "attachment;filename=invoi ce.xls"
Response.ContentType = "application/vnd.ms-excel"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso ft-com:off ice:spread sheet"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:x="urn:schemas-micro soft-com:o ffice:exce l"
xmlns:ss="urn:schemas-micr osoft-com: office:spr eadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microso ft-com:off ice:office ">
<Author>dba123</Author>
<LastAuthor>dba123</LastAu thor>
<Created>1/1/2004</Created >
<Company>Company Name</Company>
<Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso ft-com:off ice:office ">
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C D1\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso ft-com:off ice:excel" >
<WindowHeight>6135</Window Height>
<WindowWidth>8445</WindowW idth>
<WindowTopX>240</WindowTop X>
<WindowTopY>120</WindowTop Y>
<ProtectStructure>False</P rotectStru cture>
<ProtectWindows>False</Pro tectWindow s>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, Query, strSQL
oCon.ConnectionString "Provider=sqloledb;Data Source=somedatasource;Init ial Catalog=cataolognamehere;U ser Id=sa;Password=passwordher e;"
oCon.Open
Set Query = Server.CreateObject("ADODB .Recordset ")
strSQL = "SELECT TOP 15 * FROM mytable"
Set Query = oCon.Execute(strSQL)
Dim count
count = 0
While Not Query.EOF
count = count + 1
%>
<Worksheet ss:Name="<%=Query("Email_D ate")%>">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="4" x:FullColumns="1" x:FullRows="1" ID="Table<%=count%>">
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">CSR Id</Data></Cell>
<Cell><Data ss:Type="String"><%=Query( "CSR_Id")% ></Data></ Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">Email</Da ta></Cell>
<Cell><Data ss:Type="String"><%=Query( "Email")%> </Data></C ell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso ft-com:off ice:excel" >
<% if count = 1 then %>
<Selected />
<% end if %>
<ProtectObjects>False</Pro tectObject s>
<ProtectScenarios>False</P rotectScen arios>
</WorksheetOptions>
<%
Query.MoveNext
Wend
oCon.Close
%>
</Workbook>
Here is my code below. The following is happening:
1) I get a save prompt but it states in the prompt:
FileName: my current asp page name
From: my site.com
2) When I try to SAve the file, I get the error "Internet Explorer cannot download asp page name from my site.com. Internet Explorer was not able to open this Internet site"
3) Why is it trying to download an asp page rather than export to Excel and prompt me to save an Excel file? Or will it if I get this to stop erroring out?
My code
<%@Language="VBScript"%>
<%
'Using the Northwind as an example:
'works for Excel 2000 and Excel 2002
Response.AddHeader "Content-Disposition", "attachment;filename=invoi
Response.ContentType = "application/vnd.ms-excel"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microso
<Author>dba123</Author>
<LastAuthor>dba123</LastAu
<Created>1/1/2004</Created
<Company>Company Name</Company>
<Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso
<WindowHeight>6135</Window
<WindowWidth>8445</WindowW
<WindowTopX>240</WindowTop
<WindowTopY>120</WindowTop
<ProtectStructure>False</P
<ProtectWindows>False</Pro
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, Query, strSQL
oCon.ConnectionString "Provider=sqloledb;Data Source=somedatasource;Init
oCon.Open
Set Query = Server.CreateObject("ADODB
strSQL = "SELECT TOP 15 * FROM mytable"
Set Query = oCon.Execute(strSQL)
Dim count
count = 0
While Not Query.EOF
count = count + 1
%>
<Worksheet ss:Name="<%=Query("Email_D
<Table ss:ExpandedColumnCount="2"
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">CSR Id</Data></Cell>
<Cell><Data ss:Type="String"><%=Query(
</Row>
<Row>
<Cell><Data ss:Type="String">Email</Da
<Cell><Data ss:Type="String"><%=Query(
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso
<% if count = 1 then %>
<Selected />
<% end if %>
<ProtectObjects>False</Pro
<ProtectScenarios>False</P
</WorksheetOptions>
<%
Query.MoveNext
Wend
oCon.Close
%>
</Workbook>
Its working for me now..
Go to your IE and clear all offline content (Tools | Internet Option | Delet Files | Delete all offline content)
Also, try running this from a new browser window.
Cheers!!
Go to your IE and clear all offline content (Tools | Internet Option | Delet Files | Delete all offline content)
Also, try running this from a new browser window.
Cheers!!
ASKER
I don't know, it is just not working even after that. Can you post your code?
ASKER
so is your filename showing an asp page also? how is it working? are you getting an excel file as output?
ASKER
I give up
Mine clearly shows invoice.xls.. Here is the code.. Also try clearing history and deleting all the offline content. Also try rebooting your server/ pC. I think it is being served from the cache.
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=invoi ce.xls"
Response.ContentType = "application/vnd.ms-excel"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%><?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso ft-com:off ice:spread sheet"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:x="urn:schemas-micro soft-com:o ffice:exce l"
xmlns:ss="urn:schemas-micr osoft-com: office:spr eadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microso ft-com:off ice:office ">
<Author>Fritz_the_Blank</A uthor>
<LastAuthor>Fritz_the_Blan k</LastAut hor>
<Created><%=GetIsoDate()%> </Created>
<Company>ABC Inc</Company>
<Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso ft-com:off ice:office ">
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C D1\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso ft-com:off ice:excel" >
<WindowHeight>6135</Window Height>
<WindowWidth>8445</WindowW idth>
<WindowTopX>240</WindowTop X>
<WindowTopY>120</WindowTop Y>
<ProtectStructure>False</P rotectStru cture>
<ProtectWindows>False</Pro tectWindow s>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, oCmd, oRS, oXml, oXslt, oElement
Set oCon = Server.CreateObject("ADODB .Connectio n")
Set oCmd = Server.CreateObject("ADODB .Command")
Set oRS = Server.CreateObject("ADODB .Recordset ")
oCon.ConnectionString = "Provider=SQLOLEDB;Initial Catalog=NorthWind;Data Source=(local);User Id=sa;Password=pass;"
oCon.Open
Set oCmd.ActiveConnection = oCon
oCmd.CommandText = "SELECT TOP 15 * FROM Orders"
Dim count
count = 0
Set oRS = oCmd.Execute
While Not oRS.EOF
count = count + 1
%>
<Worksheet ss:Name="<%=oRS("OrderId") %>">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="4" x:FullColumns="1" x:FullRows="1" ID="Table<%=count%>">
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Order Id</Data></Cell>
<Cell><Data ss:Type="String"><%=oRS("O rderId")%> </Data></C ell>
</Row>
<Row>
<Cell><Data ss:Type="String">Order Date</Data></Cell>
<Cell><Data ss:Type="String"><%=oRS("O rderDate") %></Data>< /Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">Required Date</Data></Cell>
<Cell><Data ss:Type="String"><%=oRS("R equiredDat e")%></Dat a></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">Freight</ Data></Cel l>
<Cell><Data ss:Type="Number"><%=(oRS(" Freight")) %></Data>< /Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso ft-com:off ice:excel" >
<% if count = 1 then %>
<Selected />
<% end if %>
<ProtectObjects>False</Pro tectObject s>
<ProtectScenarios>False</P rotectScen arios>
</WorksheetOptions>
</Worksheet>
<%
oRS.MoveNext
Wend
oCon.Close
%>
</Workbook>
Cheers!!
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=invoi
Response.ContentType = "application/vnd.ms-excel"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%><?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microso
<Author>Fritz_the_Blank</A
<LastAuthor>Fritz_the_Blan
<Created><%=GetIsoDate()%>
<Company>ABC Inc</Company>
<Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso
<WindowHeight>6135</Window
<WindowWidth>8445</WindowW
<WindowTopX>240</WindowTop
<WindowTopY>120</WindowTop
<ProtectStructure>False</P
<ProtectWindows>False</Pro
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, oCmd, oRS, oXml, oXslt, oElement
Set oCon = Server.CreateObject("ADODB
Set oCmd = Server.CreateObject("ADODB
Set oRS = Server.CreateObject("ADODB
oCon.ConnectionString = "Provider=SQLOLEDB;Initial
oCon.Open
Set oCmd.ActiveConnection = oCon
oCmd.CommandText = "SELECT TOP 15 * FROM Orders"
Dim count
count = 0
Set oRS = oCmd.Execute
While Not oRS.EOF
count = count + 1
%>
<Worksheet ss:Name="<%=oRS("OrderId")
<Table ss:ExpandedColumnCount="2"
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Order Id</Data></Cell>
<Cell><Data ss:Type="String"><%=oRS("O
</Row>
<Row>
<Cell><Data ss:Type="String">Order Date</Data></Cell>
<Cell><Data ss:Type="String"><%=oRS("O
</Row>
<Row>
<Cell><Data ss:Type="String">Required Date</Data></Cell>
<Cell><Data ss:Type="String"><%=oRS("R
</Row>
<Row>
<Cell><Data ss:Type="String">Freight</
<Cell><Data ss:Type="Number"><%=(oRS("
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso
<% if count = 1 then %>
<Selected />
<% end if %>
<ProtectObjects>False</Pro
<ProtectScenarios>False</P
</WorksheetOptions>
</Worksheet>
<%
oRS.MoveNext
Wend
oCon.Close
%>
</Workbook>
Cheers!!
ASKER
When you say shows an .xls, do you mean shows it in a browswer? I am not wanting that, I want an actual phsyical Excel doc on my desktop or something, not a web page showing excel. Is that what this all is doing?
Thanks much for all the help so far.
Thanks much for all the help so far.
Try running the above code as is.. It should throw an error.. that way we can be sure that is is not being served from cache.
Then make the changes to the connection and try executing it from a new window.
Cheers!!
Then make the changes to the connection and try executing it from a new window.
Cheers!!
ASKER
The only difference I see is that you are using a local DB and I'm trying to access a DB on our server. While I am able to edit and do stuff in ASP on my server Databases, maybe that is the problem but I don't know what needs to be tweaked on the server to prevent me from getting that error...if this is indeed the problem.
As you know, I received help with that question. When it finally worked for me, the database was Access on a Windows 2000 server. No special components were on my computer.
The page displays as an Excel sheet in the browser, which could be saved locally via the file menu.
FtB
The page displays as an Excel sheet in the browser, which could be saved locally via the file menu.
FtB
ASKER
tried your code, got an error. Changed the damn connection...same errror. I don't have Local registered in my SQL Server Enterprise Manager to try on either since i am using WinXP and when installing SQL Server, you get that messages stating that you cannot install the server portion on my pC, otherwise I'd try locally.
ASKER
Can you answer my question also which is a biggie for me:
When you say shows an .xls, do you mean shows it in a browswer? I am not wanting that, I want an actual phsyical Excel doc on my desktop or something, not a web page showing excel. Is that what this all is doing?
When you say shows an .xls, do you mean shows it in a browswer? I am not wanting that, I want an actual phsyical Excel doc on my desktop or something, not a web page showing excel. Is that what this all is doing?
Try adding the code in a new page and try calling it. I dont think that the database being in a different machine is a problem. Also, make sure that there is a northwind database in your server.
I strongly believe it has something to do with caching. maybe the previous xml file that you generated is still in the cache or something. Otherwise the code should work perfectly fine.
Cheers!!
I strongly believe it has something to do with caching. maybe the previous xml file that you generated is still in the cache or something. Otherwise the code should work perfectly fine.
Cheers!!
When the page is called, a dialogue box appears offering you the choice to view the page in your browser, to save the file locally, or to cancel. There is no real way for this to write the file directly locally or else that would be a big security issue.
FtB
FtB
ASKER
nevermind, my connection was messed up. It starts to go to excel after download then getting this error..looking into it
End tag 'Workbook' does not match the start tag 'Worksheet'
End tag 'Workbook' does not match the start tag 'Worksheet'
phew... Atleast we have crossed the initial hurdle.
Cheers!!
Cheers!!
Okay, that should be easy to find--you just have a mismatched tag.
FtB
FtB
ASKER
1) I am now getting the error after I try opening the Excel doc
"Problems came up in the following areas during load
Workbook setting"
I have looked up and down my code. I don't see any problems in it.
2) What is Set oCmd = Server.CreateObject("ADODB .Command") . I took that out.
3) ap_sajith, are you getting your Excel file to open with data without any errors?
My latest code:
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=invoi ce.xls"
Response.ContentType = "application/vnd.ms-excel"
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso ft-com:off ice:spread sheet"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:x="urn:schemas-micro soft-com:o ffice:exce l"
xmlns:ss="urn:schemas-micr osoft-com: office:spr eadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microso ft-com:off ice:office ">
<Author>IT Dept</Author>
<LastAuthor>IT Dept</LastAuthor>
<Created>1/1/2004</Created >
<Company>Company Name</Company>
<Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso ft-com:off ice:office ">
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C D1\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso ft-com:off ice:excel" >
<WindowHeight>6135</Window Height>
<WindowWidth>8445</WindowW idth>
<WindowTopX>240</WindowTop X>
<WindowTopY>120</WindowTop Y>
<ProtectStructure>False</P rotectStru cture>
<ProtectWindows>False</Pro tectWindow s>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, Query, strSQL, count
Set oCon = Server.CreateObject("ADODB .Connectio n")
oCon.Open "Provider=sqloledb;Data Source=somesource;Initial Catalog=somecatalog;User Id=sa;Password=somepasswor d;"
Set Query = Server.CreateObject("ADODB .Recordset ")
strSQL = "SELECT TOP 15 * FROM my_table"
count = 0
Set Query = oCon.Execute(strSQL)
Do While Not Query.EOF
count = count + 1
%>
<Worksheet ss:Name="test">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="4" x:FullColumns="1" x:FullRows="1" ID="Table<%=count%>">
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Email</Da ta></Cell>
<Cell><Data ss:Type="String"><%=Query( "Email")%> </Data></C ell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso ft-com:off ice:excel" >
<% if count = 1 then %>
<Selected />
<% end if %>
<ProtectObjects>False</Pro tectObject s>
<ProtectScenarios>False</P rotectScen arios>
</WorksheetOptions>
</Worksheet>
<%
Query.MoveNext
loop
Query.Close
%>
</Workbook>
"Problems came up in the following areas during load
Workbook setting"
I have looked up and down my code. I don't see any problems in it.
2) What is Set oCmd = Server.CreateObject("ADODB
3) ap_sajith, are you getting your Excel file to open with data without any errors?
My latest code:
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=invoi
Response.ContentType = "application/vnd.ms-excel"
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microso
<Author>IT Dept</Author>
<LastAuthor>IT Dept</LastAuthor>
<Created>1/1/2004</Created
<Company>Company Name</Company>
<Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso
<WindowHeight>6135</Window
<WindowWidth>8445</WindowW
<WindowTopX>240</WindowTop
<WindowTopY>120</WindowTop
<ProtectStructure>False</P
<ProtectWindows>False</Pro
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, Query, strSQL, count
Set oCon = Server.CreateObject("ADODB
oCon.Open "Provider=sqloledb;Data Source=somesource;Initial Catalog=somecatalog;User Id=sa;Password=somepasswor
Set Query = Server.CreateObject("ADODB
strSQL = "SELECT TOP 15 * FROM my_table"
count = 0
Set Query = oCon.Execute(strSQL)
Do While Not Query.EOF
count = count + 1
%>
<Worksheet ss:Name="test">
<Table ss:ExpandedColumnCount="2"
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Email</Da
<Cell><Data ss:Type="String"><%=Query(
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso
<% if count = 1 then %>
<Selected />
<% end if %>
<ProtectObjects>False</Pro
<ProtectScenarios>False</P
</WorksheetOptions>
</Worksheet>
<%
Query.MoveNext
loop
Query.Close
%>
</Workbook>
>>2) What is Set oCmd = Server.CreateObject("ADODB .Command") . I took that out.
You dont really need that.. what you have written is correct.
>>3) ap_sajith, are you getting your Excel file to open with data without any errors?
I got it working perfectly. Was it working fine before you made the modifications?
I am looking at your code for any possible errors.. Shall let you know if i come across any.
Cheers!!
You dont really need that.. what you have written is correct.
>>3) ap_sajith, are you getting your Excel file to open with data without any errors?
I got it working perfectly. Was it working fine before you made the modifications?
I am looking at your code for any possible errors.. Shall let you know if i come across any.
Cheers!!
ASKER
No, it hs never worked yet, this is my last error....THEN IT WILL WORK....ahhhh
ASKER
Thanks
One problem that I frequently encountered was that if the sheet name was too long, let's say greater than 10 characters, the code threw an error.
FtB
FtB
ASKER
thanks, it is definitely not the name...I tried even a two character name for both the spreadsheet and worksheet.
Try this...
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=invoi ce.xls"
Response.ContentType = "application/vnd.ms-excel"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%><?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso ft-com:off ice:spread sheet"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:x="urn:schemas-micro soft-com:o ffice:exce l"
xmlns:ss="urn:schemas-micr osoft-com: office:spr eadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microso ft-com:off ice:office ">
<Author>Fritz_the_Blank</A uthor>
<LastAuthor>Fritz_the_Blan k</LastAut hor>
<Created><%=GetIsoDate()%> </Created>
<Company>ABC Inc</Company>
<Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso ft-com:off ice:office ">
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C D1\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso ft-com:off ice:excel" >
<WindowHeight>6135</Window Height>
<WindowWidth>8445</WindowW idth>
<WindowTopX>240</WindowTop X>
<WindowTopY>120</WindowTop Y>
<ProtectStructure>False</P rotectStru cture>
<ProtectWindows>False</Pro tectWindow s>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
Cheers!!
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=invoi
Response.ContentType = "application/vnd.ms-excel"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%><?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microso
<Author>Fritz_the_Blank</A
<LastAuthor>Fritz_the_Blan
<Created><%=GetIsoDate()%>
<Company>ABC Inc</Company>
<Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso
<WindowHeight>6135</Window
<WindowWidth>8445</WindowW
<WindowTopX>240</WindowTop
<WindowTopY>120</WindowTop
<ProtectStructure>False</P
<ProtectWindows>False</Pro
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
Cheers!!
ASKER
sorry, same error
Atleast i've managed to replicate the error at my end.. Let me try and fix it.
Cheers!!
Cheers!!
ASKER
man, I hope so...thanks
ASKER
I have been spending all day on this damn thing
ASKER
Did you change your code to produce that error or did it just suddenly come up?
I changed the code to retrieve data from one of my databases and got the worksheet error while trying to open it.
Cheers!!
Cheers!!
ASKER
Well, I can tell you one thing, I changed my query to select All files instead of Top 15. I can see that Excel is downloading the data because the processing bar takes about 5 seconds. At the end then of course that error.
ASKER
Ok, I tried running it on my server and the Excel file opens fine.
Me too... Just got it working and was about to post the code here..
Glad that it worked finally.
Cheers!!
Glad that it worked finally.
Cheers!!
ASKER
yea, but this still poses a major problem wtih the end user. It is useless if they can't go to the page and download the document.
ASKER
Fritz
>>When the page is called, a dialogue box appears offering you the choice to view the page in your browser, to save the file locally, or to cancel. There is no real way for this to write the file directly locally or else that would be a big security issue
So basically you are saying I'm getting this worksheet error because I am trying to save it locally? If so, then how in the hell do we get it so that the end user can download the excel doc to their desktop....or a work around to where they can call the asp page, it downloads it to the server and I provide a link back to the created excel doc? I don't see how the user can produce the excel file even on the server if this error occurs every time.
>>When the page is called, a dialogue box appears offering you the choice to view the page in your browser, to save the file locally, or to cancel. There is no real way for this to write the file directly locally or else that would be a big security issue
So basically you are saying I'm getting this worksheet error because I am trying to save it locally? If so, then how in the hell do we get it so that the end user can download the excel doc to their desktop....or a work around to where they can call the asp page, it downloads it to the server and I provide a link back to the created excel doc? I don't see how the user can produce the excel file even on the server if this error occurs every time.
I tried it from a different machine on the server. It is saving the file properly and opening it and displaying the data perfectly.
Try clearing the cache on your local PC and try executing the code again.
Cheers!!
Try clearing the cache on your local PC and try executing the code again.
Cheers!!
ASKER
Furthermore, there are 2 major problems:
1) If I try this, it still is putting everything in one row in Excel
<Row>
<Cell><Data ss:Type="String">Resolutio n</Data></ Cell>
<Cell><Data ss:Type="String">Email To</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number"><%=Query( "Resolutio n")%></Dat a></Cell>
<Cell><Data ss:Type="String"><%=Query( "Email")%> </Data></C ell>
</Row>
which shows like this in Excel
2) How in the heck can we then format the Excel spreadsheet cell background, font, etc. when going through this using XML? I assume I have to use XML to format the Excel cells somehow? and if so where the heck would I start? I have to color code rows in the Excel spreadsheet.
1) If I try this, it still is putting everything in one row in Excel
<Row>
<Cell><Data ss:Type="String">Resolutio
<Cell><Data ss:Type="String">Email To</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number"><%=Query(
<Cell><Data ss:Type="String"><%=Query(
</Row>
which shows like this in Excel
2) How in the heck can we then format the Excel spreadsheet cell background, font, etc. when going through this using XML? I assume I have to use XML to format the Excel cells somehow? and if so where the heck would I start? I have to color code rows in the Excel spreadsheet.
Try adding this at the top of your page to disable caching..
Response.Buffer=True
Response.AddHeader "Content-Disposition", "attachment;filename=invoi ce.xls"
Response.ContentType = "application/vnd.ms-excel"
' ** DISABLE CACHING **
Response.Expires=-1
Response.AddHeader "Pragma", "no-cache"
Response.CacheControl="no- cache"
Response.CacheControl = "Private"
Cheers!!
Response.Buffer=True
Response.AddHeader "Content-Disposition", "attachment;filename=invoi
Response.ContentType = "application/vnd.ms-excel"
' ** DISABLE CACHING **
Response.Expires=-1
Response.AddHeader "Pragma", "no-cache"
Response.CacheControl="no-
Response.CacheControl = "Private"
Cheers!!
1) If I try this, it still is putting everything in one row in Excel
<Row>
<Cell><Data ss:Type="String">Resolutio n</Data></ Cell>
<Cell><Data ss:Type="String">Email To</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number"><%=Query( "Resolutio n")%></Dat a></Cell>
<Cell><Data ss:Type="String"><%=Query( "Email")%> </Data></C ell>
</Row>
Well.. It shous the data in one row.. isnt that what you want?
As for the second question, i'll have to look around..
Cheers!!
<Row>
<Cell><Data ss:Type="String">Resolutio
<Cell><Data ss:Type="String">Email To</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number"><%=Query(
<Cell><Data ss:Type="String"><%=Query(
</Row>
Well.. It shous the data in one row.. isnt that what you want?
As for the second question, i'll have to look around..
Cheers!!
ASKER
No, I want the data to be like this
Label Label2
value Value 2
I am creating a matrix-like report, not a one liner!...that doesn't make sense having label value lable 2 value2
Label Label2
value Value 2
I am creating a matrix-like report, not a one liner!...that doesn't make sense having label value lable 2 value2
ASKER
actually it is inserting the data like this in excel with those rows
label label 2 value value2
so I have 2 labels followed by 2 values....that is just plain stupid
label label 2 value value2
so I have 2 labels followed by 2 values....that is just plain stupid
ASKER
DISABLE CACHING still produces a worksheet error. You're telling me that you can go to another client computer and download and open the excel file fine? And you are actually opening the Excel file with no errors?
I tried on another computer as well but still got the error.
I tried on another computer as well but still got the error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>So basically you are saying I'm getting this worksheet error because I am trying to save it locally? If so, then how in the hell do we get it so that the end user can download the excel doc to their desktop....or a work around to where they can call the asp page, it downloads it to the server and I provide a link back to the created excel doc? I don't see how the user can produce the excel file even on the server if this error occurs every time.<<
No, I was answering an earlier post in the thread about how to get the file to the client machine. Once the page renders, a dialog box appears giving the user the choice of viewing it in the browser or to download it to the users machine. Either way it does not stay on the server.
FtB
No, I was answering an earlier post in the thread about how to get the file to the client machine. Once the page renders, a dialog box appears giving the user the choice of viewing it in the browser or to download it to the users machine. Either way it does not stay on the server.
FtB
>>actually it is inserting the data like this in excel with those rows
label label 2 value value2
so I have 2 labels followed by 2 values....that is just plain stupid<<
Actually i am able to display the cells like
Label1 Label2
Value 1 Value2
The above code does that for me.
>>I tried on another computer as well but still got the error.<<
Do the machines have Excel200 or above installed?.
I tried on two different machines besides the server and both seems to work fine.
Cheers!!
label label 2 value value2
so I have 2 labels followed by 2 values....that is just plain stupid<<
Actually i am able to display the cells like
Label1 Label2
Value 1 Value2
The above code does that for me.
>>I tried on another computer as well but still got the error.<<
Do the machines have Excel200 or above installed?.
I tried on two different machines besides the server and both seems to work fine.
Cheers!!
ASKER
we are using Excel 2002
ASKER
well, I don't see how yours is possible working on the client and I don't see why my server would format the rows differently than you are saying, that just doesn't seem possible.
ASKER
what version are you using may I ask of Excel?
Try modifying the code that i last postd. just modify the connection string, the select query and the database column names and the cell headings.
Also, make sure that you are not using windows authentication to log into SQL server.
Otherwise i dont quite see how it works on the server and not on the clients??..
Repeating what i said earlier.. try clearing the cache and execute the code from a new browser window.
Cheers!!
Also, make sure that you are not using windows authentication to log into SQL server.
Otherwise i dont quite see how it works on the server and not on the clients??..
Repeating what i said earlier.. try clearing the cache and execute the code from a new browser window.
Cheers!!
Excel 2002.. But i dont think thats an issue.
Cheers!!
Cheers!!
ASKER
clearing the cache and execute the code from a new browser window.
tried that a million times on 2 computers
tried that a million times on 2 computers
So do you mean to say that it is working only from the server?.
Think about it.. The code is executed on the server and only the output is sent to the browser irrespective of the fact that the browser resides on the server or not.
BTW.. Do you have authentication enabled on the server ie, is anonymous access disabled on the server?
Cheers!!
Think about it.. The code is executed on the server and only the output is sent to the browser irrespective of the fact that the browser resides on the server or not.
BTW.. Do you have authentication enabled on the server ie, is anonymous access disabled on the server?
Cheers!!
ASKER
I uninstalled and reinstalled office. Now I am finally getting the XMLError.log where before I was getting some string log like 23ENNOK.log in which didn't exist.
the log which is now showing up after I reinstalled Office (XMLerr.log)is stating that I have to many tages
XML ERROR in Workbook Setting
REASON: Too many tags
FILE: C:\Documents and Settings\myname\Local Settings\Temporary Internet Files\Content.IE5\TTWQWZLJ \invoice[1 ].xls
GROUP: Workbook
TAG: Worksheet
ATTRIB: Name
VALUE: t
the log which is now showing up after I reinstalled Office (XMLerr.log)is stating that I have to many tages
XML ERROR in Workbook Setting
REASON: Too many tags
FILE: C:\Documents and Settings\myname\Local Settings\Temporary Internet Files\Content.IE5\TTWQWZLJ
GROUP: Workbook
TAG: Worksheet
ATTRIB: Name
VALUE: t
ASKER
>>BTW.. Do you have authentication enabled on the server ie, is anonymous access disabled on the server?
Are you talking about NTFS or SQL Server Enterprise Manager here. Please be specific.
Are you talking about NTFS or SQL Server Enterprise Manager here. Please be specific.
ASKER
I have had no problems hitting this database from other asp pages in the same directory so how would access be a problem here? I have never had any access problems and I can see that before I get the error on my client, that it is downloading data for sure because I can see Excel processing (bar) moving slower if I select all records.
Hmm... Wish i was ther to checkout things first hand.
I was talking about IIS Authentication and the error log looks greek to me ;o)
The last thing you could try out is to try changing the filename form invoice.xls to something else in your code. Also, try creating a new page, copy paste the same working code and try accessing it from the clients.
Also, try retrieving the top 10 records instead of the whole bunch.
Cheers!!
I was talking about IIS Authentication and the error log looks greek to me ;o)
The last thing you could try out is to try changing the filename form invoice.xls to something else in your code. Also, try creating a new page, copy paste the same working code and try accessing it from the clients.
Also, try retrieving the top 10 records instead of the whole bunch.
Cheers!!
ASKER
Ok, I took out my recordset and tried hard coded values again as I did earlier. Only this time it worked great. Now what is it about my recordset?
Without Recordset
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=testi ng.xls"
Response.ContentType = "application/vnd.ms-excel"
' ** DISABLE CACHING **
Response.Expires=-1
Response.AddHeader "Pragma", "no-cache"
Response.CacheControl="no- cache"
Response.CacheControl = "Private"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso ft-com:off ice:spread sheet"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:x="urn:schemas-micro soft-com:o ffice:exce l"
xmlns:ss="urn:schemas-micr osoft-com: office:spr eadsheet"
>
<DocumentProperties xmlns="urn:schemas-microso ft-com:off ice:office ">
<Author>ITDept</Author>
<LastAuthor>ITDept</LastAu thor>
<Created></Created>
<Company></Company>
<Version>10.2614.6626</Ver sion>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso ft-com:off ice:office ">
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C D1\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso ft-com:off ice:excel" >
<WindowHeight>6135</Window Height>
<WindowWidth>8445</WindowW idth>
<WindowTopX>240</WindowTop X>
<WindowTopY>120</WindowTop Y>
<ProtectStructure>False</P rotectStru cture>
<ProtectWindows>False</Pro tectWindow s>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<Worksheet ss:Name="testing">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="4" x:FullColumns="1" x:FullRows="1" ID="Table<%=count%>">
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Resolutio n</Data></ Cell>
<Cell><Data ss:Type="String">Email To</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">2</Data>< /Cell>
<Cell><Data ss:Type="String">test2</Da ta></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso ft-com:off ice:excel" >
<% if count = 1 then %>
<Selected />
<% end if %>
</WorksheetOptions>
</Worksheet>
</Workbook>
with recordset
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=testi ng.xls"
Response.ContentType = "application/vnd.ms-excel"
' ** DISABLE CACHING **
Response.Expires=-1
Response.AddHeader "Pragma", "no-cache"
Response.CacheControl="no- cache"
Response.CacheControl = "Private"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso ft-com:off ice:spread sheet"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:x="urn:schemas-micro soft-com:o ffice:exce l"
xmlns:ss="urn:schemas-micr osoft-com: office:spr eadsheet"
>
<DocumentProperties xmlns="urn:schemas-microso ft-com:off ice:office ">
<Author>ITDept</Author>
<LastAuthor>ITDept</LastAu thor>
<Created></Created>
<Company></Company>
<Version>10.2614.6626</Ver sion>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso ft-com:off ice:office ">
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C D1\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso ft-com:off ice:excel" >
<WindowHeight>6135</Window Height>
<WindowWidth>8445</WindowW idth>
<WindowTopX>240</WindowTop X>
<WindowTopY>120</WindowTop Y>
<ProtectStructure>False</P rotectStru cture>
<ProtectWindows>False</Pro tectWindow s>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, Query, strSQL, count
Set oCon = Server.CreateObject("ADODB .Connectio n")
oCon.Open "Provider=sqloledb;Data Source=somesource;Initial Catalog=somecatalog;User Id=sa;Password=somepasswor d;"
Set Query = Server.CreateObject("ADODB .Recordset ")
strSQL = "SELECT TOP 100 * FROM mytable"
count = 0
Set Query = oCon.Execute(strSQL)
Do While Not Query.EOF
count = count + 1
%>
<Worksheet ss:Name="testing">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="4" x:FullColumns="1" x:FullRows="1" ID="Table<%=count%>">
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Resolutio n</Data></ Cell>
<Cell><Data ss:Type="String">Email</Da ta></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number"><%=Query( "Resolutio n")%></Dat a></Cell>
<Cell><Data ss:Type="String"><%=Query( "Email")%> </Data></C ell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso ft-com:off ice:excel" >
<% if count = 1 then %>
<Selected />
<% end if %>
</WorksheetOptions>
</Worksheet>
<%
Query.MoveNext
loop
Query.Close
%>
</Workbook>
Note: my connection string have valid values below, I just filled them in with fake values for privacy purposes
oCon.Open "Provider=sqloledb;Data Source=somesource;Initial Catalog=somecatalog;User Id=sa;Password=somepasswor d;"
Without Recordset
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=testi
Response.ContentType = "application/vnd.ms-excel"
' ** DISABLE CACHING **
Response.Expires=-1
Response.AddHeader "Pragma", "no-cache"
Response.CacheControl="no-
Response.CacheControl = "Private"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
>
<DocumentProperties xmlns="urn:schemas-microso
<Author>ITDept</Author>
<LastAuthor>ITDept</LastAu
<Created></Created>
<Company></Company>
<Version>10.2614.6626</Ver
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso
<WindowHeight>6135</Window
<WindowWidth>8445</WindowW
<WindowTopX>240</WindowTop
<WindowTopY>120</WindowTop
<ProtectStructure>False</P
<ProtectWindows>False</Pro
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<Worksheet ss:Name="testing">
<Table ss:ExpandedColumnCount="2"
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Resolutio
<Cell><Data ss:Type="String">Email To</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">2</Data><
<Cell><Data ss:Type="String">test2</Da
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso
<% if count = 1 then %>
<Selected />
<% end if %>
</WorksheetOptions>
</Worksheet>
</Workbook>
with recordset
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=testi
Response.ContentType = "application/vnd.ms-excel"
' ** DISABLE CACHING **
Response.Expires=-1
Response.AddHeader "Pragma", "no-cache"
Response.CacheControl="no-
Response.CacheControl = "Private"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
>
<DocumentProperties xmlns="urn:schemas-microso
<Author>ITDept</Author>
<LastAuthor>ITDept</LastAu
<Created></Created>
<Company></Company>
<Version>10.2614.6626</Ver
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso
<WindowHeight>6135</Window
<WindowWidth>8445</WindowW
<WindowTopX>240</WindowTop
<WindowTopY>120</WindowTop
<ProtectStructure>False</P
<ProtectWindows>False</Pro
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, Query, strSQL, count
Set oCon = Server.CreateObject("ADODB
oCon.Open "Provider=sqloledb;Data Source=somesource;Initial Catalog=somecatalog;User Id=sa;Password=somepasswor
Set Query = Server.CreateObject("ADODB
strSQL = "SELECT TOP 100 * FROM mytable"
count = 0
Set Query = oCon.Execute(strSQL)
Do While Not Query.EOF
count = count + 1
%>
<Worksheet ss:Name="testing">
<Table ss:ExpandedColumnCount="2"
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Resolutio
<Cell><Data ss:Type="String">Email</Da
</Row>
<Row>
<Cell><Data ss:Type="Number"><%=Query(
<Cell><Data ss:Type="String"><%=Query(
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso
<% if count = 1 then %>
<Selected />
<% end if %>
</WorksheetOptions>
</Worksheet>
<%
Query.MoveNext
loop
Query.Close
%>
</Workbook>
Note: my connection string have valid values below, I just filled them in with fake values for privacy purposes
oCon.Open "Provider=sqloledb;Data Source=somesource;Initial Catalog=somecatalog;User Id=sa;Password=somepasswor
What type of data does your Resolution column contain?. Maybe you have data with singlequotes / double quotes / commas... or non XML supported characters. Try using email in both the fields.. or try hard coding the value for now in one column.
Cheers!!
Cheers!!
ASKER
Resolution = int
I tried using email in both..no luck. I also tried to create a local DSN to that source then change my connection string to reference the DSN name on my PC but the connection would not work with the DSN I created. Even though the DSN shows successfull after I tested it duing creation.
I tried using email in both..no luck. I also tried to create a local DSN to that source then change my connection string to reference the DSN name on my PC but the connection would not work with the DSN I created. Even though the DSN shows successfull after I tested it duing creation.
ASKER
yes, I said hard coding works if I were to replace the <%=Query("Email_To")%> with a hard coded string ...it is just when I use a recordset
>>I tried using email in both..no luck. I also tried to create a local DSN to that source then change my connection string to reference the DSN name on my PC but the connection would not work with the DSN I created. Even though the DSN shows successfull after I tested it duing creation.
Wouldnt work because your code resides on the server and the DSN should thus reside on the server.
>>yes, I said hard coding works if I were to replace the <%=Query("Email_To")%> with a hard coded string ...it is just when I use a recordset
I said try hardcoding either of the two values and see the result.. Not both.
Also, for the number column, use something like
<Data ss:Type="Number"><%=(oRS(" Freight")) %></Data>
Cheers!!
Wouldnt work because your code resides on the server and the DSN should thus reside on the server.
>>yes, I said hard coding works if I were to replace the <%=Query("Email_To")%> with a hard coded string ...it is just when I use a recordset
I said try hardcoding either of the two values and see the result.. Not both.
Also, for the number column, use something like
<Data ss:Type="Number"><%=(oRS("
Cheers!!
ASKER
I tried that, using one hard coded and one recordset value....didn't work. There has got to be something here that is pretty obvious, there just has to be. Because like I said, if I don't encorporate my recordset with this whole thing and hard code all values, it works which is very frustrating...we're almost there but what the hell could it be?
Are you using a recorset from your server or just a local database on your C drive that is setup via Enterprise Manager locally? that is a big question I have since you haven't stated that yet.
Are you using a recorset from your server or just a local database on your C drive that is setup via Enterprise Manager locally? that is a big question I have since you haven't stated that yet.
ASKER
My latest code
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=testi ng.xls"
Response.ContentType = "application/vnd.ms-excel"
' ** DISABLE CACHING **
Response.Expires=-1
Response.AddHeader "Pragma", "no-cache"
Response.CacheControl="no- cache"
Response.CacheControl = "Private"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso ft-com:off ice:spread sheet"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:x="urn:schemas-micro soft-com:o ffice:exce l"
xmlns:ss="urn:schemas-micr osoft-com: office:spr eadsheet"
>
<DocumentProperties xmlns="urn:schemas-microso ft-com:off ice:office ">
<Author>ITDept</Author>
<LastAuthor>ITDept</LastAu thor>
<Created></Created>
<Company></Company>
<Version>10.2614.6626</Ver sion>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso ft-com:off ice:office ">
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C D1\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso ft-com:off ice:excel" >
<WindowHeight>6135</Window Height>
<WindowWidth>8445</WindowW idth>
<WindowTopX>240</WindowTop X>
<WindowTopY>120</WindowTop Y>
<ProtectStructure>False</P rotectStru cture>
<ProtectWindows>False</Pro tectWindow s>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, Query, strSQL, count
Set oCon = Server.CreateObject("ADODB .Connectio n")
oCon.Open "Provider=sqloledb;Data Source=somesource;Initial Catalog=somecatalog;User Id=sa;Password=somepasswor d;"
Set Query = Server.CreateObject("ADODB .Recordset ")
strSQL = "SELECT TOP 100 * FROM mytable"
count = 0
Set Query = oCon.Execute(strSQL)
Do While Not Query.EOF
count = count + 1
%>
<Worksheet ss:Name="testing">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="4" x:FullColumns="1" x:FullRows="1" ID="Table<%=count%>">
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Status</D ata></Cell >
</Row>
<Row>
<Cell><Data ss:Type="String"><%=Query( "status_na me")%></Da ta></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso ft-com:off ice:excel" >
<% if count = 1 then %>
<Selected />
<% end if %>
</WorksheetOptions>
</Worksheet>
<%
Query.MoveNext
loop
Query.Close
%>
</Workbook>
<%@Language="VBScript"%>
<%
Response.AddHeader "Content-Disposition", "attachment;filename=testi
Response.ContentType = "application/vnd.ms-excel"
' ** DISABLE CACHING **
Response.Expires=-1
Response.AddHeader "Pragma", "no-cache"
Response.CacheControl="no-
Response.CacheControl = "Private"
Function GetIsoDate()
Dim datNow
datNow = Now
GetISODate = CStr(Year(datNow)) & "-" & PadItem(Month(datNow)) & "-" & PadItem(Day(datNow)) & "T" & _
PadItem(Hour(datNow)) & ":" & PadItem(Minute(datNow)) & ":" & PadItem(Second(datNow)) & "Z"
End Function
Function PadItem(ByVal value)
value = CStr(value)
If Len(value) = 1 Then
value = "0" & value
End If
PadItem = value
End Function
%>
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
>
<DocumentProperties xmlns="urn:schemas-microso
<Author>ITDept</Author>
<LastAuthor>ITDept</LastAu
<Created></Created>
<Company></Company>
<Version>10.2614.6626</Ver
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microso
<DownloadComponents/>
<LocationOfComponents HRef="file:///\\OfficeXP\C
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microso
<WindowHeight>6135</Window
<WindowWidth>8445</WindowW
<WindowTopX>240</WindowTop
<WindowTopY>120</WindowTop
<ProtectStructure>False</P
<ProtectWindows>False</Pro
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
</Styles>
<%
Dim oCon, Query, strSQL, count
Set oCon = Server.CreateObject("ADODB
oCon.Open "Provider=sqloledb;Data Source=somesource;Initial Catalog=somecatalog;User Id=sa;Password=somepasswor
Set Query = Server.CreateObject("ADODB
strSQL = "SELECT TOP 100 * FROM mytable"
count = 0
Set Query = oCon.Execute(strSQL)
Do While Not Query.EOF
count = count + 1
%>
<Worksheet ss:Name="testing">
<Table ss:ExpandedColumnCount="2"
<Column ss:Width="150" />
<Column ss:Width="200" />
<Row>
<Cell><Data ss:Type="String">Status</D
</Row>
<Row>
<Cell><Data ss:Type="String"><%=Query(
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microso
<% if count = 1 then %>
<Selected />
<% end if %>
</WorksheetOptions>
</Worksheet>
<%
Query.MoveNext
loop
Query.Close
%>
</Workbook>
ASKER
ap_sajith
you won't believe this. I posted this problem in the XML forum and the response was:
<Worksheet ss:Name="test">
must be
<Worksheet ss:Name="test<%=count%>">
IT WORKS! but I don't see why I had to do this...I'll find out and post here.
you won't believe this. I posted this problem in the XML forum and the response was:
<Worksheet ss:Name="test">
must be
<Worksheet ss:Name="test<%=count%>">
IT WORKS! but I don't see why I had to do this...I'll find out and post here.
ASKER
<ss:Style ss:ID="A">
<ss:Font ss:Color="Red"/>
</ss:Style>
is this CSS? or XML style sheets? I wonder how to get the cell background color to be different
<ss:Font ss:Color="Red"/>
</ss:Style>
is this CSS? or XML style sheets? I wonder how to get the cell background color to be different
Shall i continue in the new thread?.
>><Worksheet ss:Name="test">
must be
<Worksheet ss:Name="test<%=count%>">
I had noticed that and had mentioned that in one of my earlier comments.
>>is this CSS? or XML style sheets? I wonder how to get the cell background color to be different
I am not quite sure. .But i dont think it would be too difficult to figure out.
Thanks for the points.
Cheers!!
>><Worksheet ss:Name="test">
must be
<Worksheet ss:Name="test<%=count%>">
I had noticed that and had mentioned that in one of my earlier comments.
>>is this CSS? or XML style sheets? I wonder how to get the cell background color to be different
I am not quite sure. .But i dont think it would be too difficult to figure out.
Thanks for the points.
Cheers!!
ASKER
I have a new thread out on a new problem with this when trying to move the recordset looping to just write to one worksheet....thanks a lot.
Did you delete the new thread?. I was working on it.
Cheers!!
Cheers!!
ASKER
sorry, yes, I figured it out
ASKER