SunQuest
 
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 25th, 2005, 01:41 PM
fishbone34 fishbone34 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 fishbone34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 17 sec
Reputation Power: 0
Exporting to Excel

Hello, I have a page that pulls Data and places it in to a Table to display.

I would like to have a button that will EXPORT all the data in the table to an Excel file OR
.CVS.

How could this be accolimpished?

This is what I currently Have:

Notice I have a "Print" Button. I would like to have a "Export" button below it.

Code:
<% 
login=Request.Cookies("login") 
 if login <> "2" THEN
 Response.Redirect("../t1/database/perfmgmt/newsite/noaccess.html")
 end if
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 6">
<title>Create Log Entry</title>
<STYLE TYPE = "text/css">
P.basic {color: black}
SPAN {font:10pt arial; color: black}
</STYLE>
<script language="JavaScript">
<!--
function jsAlert(thecomments) 
	{
		 alert(thecomments);
	}
// -->
</script>
  <center>
<script language="JavaScript">
<!-- Begin
if (window.print) {
document.write('<form> '
+ '<input type=button name=print value="Print" '
+ 'onClick="javascript:window.print()"> </form>');
}
// End -->
</script>
 </head>
 <body bgcolor="#ffffff">
<%
themonth = request.form("month")
theYear = request.form("theYear")
'Get all entries in the database for the Agent for the entire month
startDate = theMonth&"/01/"&theYear
endDate = theMonth&"/31/"&theYear  'all dates must be less than 31, even if there aren't 31 days in every month! :-p
'Get information from DB & Connect to database
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=SQLOLEDB;Data Source=xx.xx.xx.xxx;database=xxxxxxx;uid=xx;pwd=xx  ;"
query1 = "SELECT Agent,(count(*)) "
query1 = query1 & "FROM TICKETDOC where DATED >= '"&startDate&"' and DATED <= '"&endDate&"' GROUP BY AGENT"
set objRS=Conn.execute(query1)
if objRS.EOF THEN
%></div>
  <center>
<table width="600"  border="0" cellspacing="2" cellpadding="2" bgcolor="#dcdcdc">
<tr><td><div align="center">
<font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="5" color="#a98b5e">
No Records were Found that Matched This Criteria </font></div>
</td></tr></table><HR><%
else
%>
<div align="center">
<font size="3" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>TICKET DOCUMENTATIONS FOR: <%response.write(themonth)%><%response.write(theyear)%></b></font><BR><BR> 
<center>
<table width="500" border = "0" cellspacing = "0" cellpadding = "2">
<tr><td width = "20%"><SPAN><b>AGENT</b></td><td width = "20%"><SPAN><b>TICKET COUNT</b></td></tr></table><%
'Populate Table Array from DB
tablearray = objRS.Getrows
objRS.Close
Conn.close  %>
<table width="500" border = "0" cellspacing = "0" cellpadding = "2">
<%
'Display Results
for i = 0 to UBound(tablearray,2)
response.write("<tr>")
  for j = 0 to UBound(tablearray,1)   
  %><td align="left" valign="top" width = "20%"><%
   if j= 13 THEN
	 %><%=tablearray(j,i)%></SPAN></a>
 <%	
   else %><SPAN><%
  response.write(tablearray(j,i) & "	") 
 end if
  NEXT  
  response.write("</tr>")
  NEXT
%></table><%
end if
%>
<BR><BR><BR><BR><center>
<p><img src="allbrands.jpg" alt="" height="63" width="432" border="0"></p>
<table width="90%" border="0" cellspacing="0" cellpadding="0" bgcolor="#805d5d">
<tr>
<td>
<div align="center">
<font size="1" color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Copyright © 2003 InterContinental Hotels Group. All Rights Reserved.</font><font size="1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> </font></div>
</td>
</tr>
</table>
</div>
 </body>
</html>



THANKS FOR ANY HELP!


Chris

chris@thesouthside.net

Reply With Quote
  #2  
Old January 25th, 2005, 03:37 PM
shatcher shatcher is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 shatcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 7 sec
Reputation Power: 0
Hello Chris,
I have an Excel Export example written in PHP. You can use
the concepts with the language of your choice.

I created a PHP file called "ms_export.php" that contains the following code:

<?php
# This line will stream the file to the user rather than to the screen
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");

echo $export_data;
?>

Then I in my HTML code, I add the following:

<?php
print "
<form name=export_form ENCTYPE=multipart/form-data ACTION=ms_export.php METHOD=POST>
<input type=hidden name=export_data value=\"$export_data \">
<input type=hidden name=filename value=\"$filename\">
</form>
<input type=button value='Excel Export' onClick='document.export_form.submit();'>
";
?>

Simply fill in the $filename variable with a filename and ".xls" extension. Then fill the $export_data variable
with anything you want to send to Excel using tabs \t as separators. Excel will read it directly in.

BTW, if you change the filename extension to ".doc" it will feed your data to MS Word.

Stephen

Reply With Quote
  #3  
Old January 25th, 2005, 08:56 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey! I can tell you how to export to excel from ASP....don't know if that's what you need. Anyway, here is the code to place in page...say generateExcel.asp before any response.write!!:

parameter = "attachment; filename=dumpFile - " & <Descripcion you want> & ".xls;"
Response.buffer = true
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", parameter


Every response.write you make (as a table) is printed to an excel file, which you will be asked to save to disk.

<HTML>
..
..
<form action="generateExcel.asp" method="POST">
Enter the name for the file:&nbsp;<input type="text" name="fileName">
<A href="#" onClick="document.submit();"> Click here to download the Excel File </A>
</form>
..
..
</HTML>

I've allways liked to use links instead of buttons to submit....the look better to me!

Hope it works...

Anibal.

Reply With Quote
  #4  
Old January 26th, 2005, 01:24 PM
fishbone34 fishbone34 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 5 fishbone34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 17 sec
Reputation Power: 0
Red face Thanks but.....

Anibal, Thanks for both your help and Shatcher's Help.

I do need it in ASP code rather than PHP.

I need a little push in the right direction. I'm trying to Follow your directions
but I'm running into problems.

I created the generateExcel.asp page and put it in the same
directory as the main file. Here it is:
Code:
<% 
parameter = "attachment; filename=dumpFile - " & <Description you want> & ".xls;"
Response.buffer = true 
Response.ContentType = "application/vnd.ms-excel" 
Response.AddHeader "Content-Disposition", parameter
%>


I Need help Modifing my other ASP page that has the tables to
reference "generateExcel.asp". I'm a little new to this!

Code:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 6">
<title>Service Observation Summary</title>
<STYLE TYPE = "text/css">
P.basic {color: black}
SPAN {font:10pt arial; color: black}
</STYLE>
<script language="JavaScript">
<!--
function jsAlert(thecomments) 
	{
		 alert(thecomments);
	}
// -->
</script>
<center>
<script language="JavaScript">
<!-- Begin
if (window.print) {
document.write('<form> '
+ '<input type=button name=print value="Print" '
+ 'onClick="javascript:window.print()"> </form>');
}
// End -->
</script>
</head>
<body bgcolor="#ffffff">
 
<%
themonth = request.form("month")
theYear = request.form("theYear")
'Get all entries in the database for the Agent for the entire month
startDate = theMonth&"/01/"&theYear
endDate = theMonth&"/31/"&theYear 
'all dates must be less than 31, even if there aren't 31 days in every month!
 
'Get information from DB and let user know if there is more than 1 service observe for a date
'Connect to database to upload all form data.
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=SQLOLEDB;Data Source=XX.XX.XXX.XXX;database=XXXXX;uid=XXX;pwd=XX  XXX;"
query1 = "SELECT Agent,Phone_Id "
query1 = query1 & "FROM TICKETDOC where DATED >= '"&startDate&"' and DATED <= '"&endDate&"' order BY AGENT"
set objRS=Conn.execute(query1)
 
%>
<b><font size="2" color="#ee0000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Service Observation Summary</font></b>
<table width="700" border=0 cellspacing=2 cellpadding=2 color="000000">
<tr align="left" valign="top">
<td bgcolor = "DDDDDD" align="center" valign="top" width="90"><b><font size="2" color="#ee0000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Agent </font></b></td>
<td bgcolor = "DDDDDD" align="center" valign="top" width="95"><b><font size="2" color="#ee0000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Count</font></b></td>
</tr>
<%
Do Until objRS.EOF
response.write ("<tr>")%><td bgcolor = "DDDDDD" align="center" valign="top"><font size="2" color="#000000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><%
response.write (objRS.Fields("AGENT") & "</td>")
%><td bgcolor = "DDDDDD" align="center" valign="top"><font size="2" color="#000000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><%
response.write (objRS.Fields("Phone_Id") & "</td>")
response.write ("</tr>")
objRS.movenext
loop 
%>
<BR><center>
<table width="90%" border="0" cellspacing="0" cellpadding="0" bgcolor="#805d5d">
<tr>
<td>
<div align="center">
<font size="1" color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Copyright © 2003 InterContinental Hotels Group. All Rights Reserved.</font><font size="1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> </font></div>
</td>
</tr>
</table>
</div>
</body>
</html>

Reply With Quote
  #5  
Old January 31st, 2005, 05:36 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey! It's quite easy..just place the code I gave you before you print anything in the page you have. For example, place the code after the <body> tag...Just copy it! it should work. I'm not sure, since, i don't programm the conections anymore (we have a file that does the connection ) but, I think you missed a recordSet Object. You are supposed to have a recordset object to recive the oConn execution (once again....not sure about it). If it works like it is...great.

Anibal.

PS: Here's how you add it!

<html>
<head>
<title>Service Observation Summary</title>
<STYLE TYPE = "text/css">
P.basic {color: black}
SPAN {font:10pt arial; color: black}
</STYLE>
<script language="JavaScript">
<!--
function jsAlert(thecomments)
{
alert(thecomments);
}
// -->
</script>
<center>
<script language="JavaScript">
<!-- Begin
if (window.print) {
document.write('<form> '
+ '<input type=button name=print value="Print" '
+ 'onClick="javascript:window.print()"> </form>');
}
// End -->
</script>
</head>
<body bgcolor="#ffffff">

<%
parameter = "attachment; filename=dumpFile - " & <Description you want> & ".xls;"
Response.buffer = true
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", parameter

themonth = request.form("month")
theYear = request.form("theYear")
'Get all entries in the database for the Agent for the entire month
startDate = theMonth&"/01/"&theYear
endDate = theMonth&"/31/"&theYear
'all dates must be less than 31, even if there aren't 31 days in every month!

'Get information from DB and let user know if there is more than 1 service observe for a date
'Connect to database to upload all form data.
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=SQLOLEDB;Data Source=XX.XX.XXX.XXX;database=XXXXX;uid=XXX;pwd=XX XXX;"
query1 = "SELECT Agent,Phone_Id "
query1 = query1 & "FROM TICKETDOC where DATED >= '"&startDate&"' and DATED <= '"&endDate&"' order BY AGENT"
set objRS=Conn.execute(query1)

%>
<b><font size="2" color="#ee0000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Service Observation Summary</font></b>
<table width="700" border=0 cellspacing=2 cellpadding=2 color="000000">
<tr align="left" valign="top">
<td bgcolor = "DDDDDD" align="center" valign="top" width="90"><b><font size="2" color="#ee0000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Agent </font></b></td>
<td bgcolor = "DDDDDD" align="center" valign="top" width="95"><b><font size="2" color="#ee0000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Count</font></b></td>
</tr>
<%
Do Until objRS.EOF
response.write ("<tr>")%><td bgcolor = "DDDDDD" align="center" valign="top"><font size="2" color="#000000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><%
response.write (objRS.Fields("AGENT") & "</td>")
%><td bgcolor = "DDDDDD" align="center" valign="top"><font size="2" color="#000000" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><%
response.write (objRS.Fields("Phone_Id") & "</td>")
response.write ("</tr>")
objRS.movenext
loop
%>
<BR><center>
<table width="90%" border="0" cellspacing="0" cellpadding="0" bgcolor="#805d5d">
<tr>
<td>
<div align="center">
<font size="1" color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Copyright © 2003 InterContinental Hotels Group. All Rights Reserved.</font><font size="1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> </font></div>
</td>
</tr>
</table>
</div>
</body>
</html>

Reply With Quote
  #6  
Old March 10th, 2005, 01:23 PM
false420 false420 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 24 false420 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 58 m 11 sec
Reputation Power: 0
ive tried your asp code for the same reason and got

Syntax error
/generateExcel.asp, line 2, column 49
parameter = "attachment; filename=dumpFile - " & <Description you want> & ".xls;"

when it goes to the generateExcel.asp file

Reply With Quote
  #7  
Old March 11th, 2005, 02:21 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey flase420! I'm not sure wheather this is an old thread or not..but here it goes!
Pleaaaase, tell me you didn't use that line exactly and literaly (I quote)...

Quote:
parameter = "attachment; filename=dumpFile - " & <Description you want> & ".xls;"



you did...didn't you ...here's an example of how to use it (just the line):

parameter = "attachment; filename=exportedFile.xls;"

That would generate a file called exportedFile.xls

Good Luck

Anibal.

Reply With Quote
  #8  
Old March 11th, 2005, 03:04 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
this isn't javascript anymore, is it?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Exporting to Excel


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway