Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Export multiple excel sheets to user machine

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59679
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Export multiple excel sheets to user machine
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Export multiple excel sheets to user machine - 4/30/2008 7:31:11 AM   
  isaws

 

Posts: 2
Score: 0
Joined: 4/30/2008
Status: offline
Hi All, I am in a need to write a VB script which should accomplish the following task

1. Put record set data in multiple excel sheets.
2. Whenever user click the export button, display Save as dialog box to save the multiple excel sheets data on a excel workbook on user local machine.
3. I do not want to store the excel sheet on server.

I have a script which does this, but for a single sheet. I can modify this script to read the data from a record set but it just works for single sheet.  Please help for multiple sheets.

<%@ LANGUAGE="VBSCRIPT" %>
<%  
Option Explicit
' -- Display's data and sends it as Excel Spreadsheet if required
Randomize Timer
Select Case Request("e")
Case ""
 DisplayData
Case Else
             SendExcelData
End Select
Response.End

Sub DisplayData() 
Dim i
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>ASP Pro 10 Minute Solution Sample</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<P><FONT FACE="Tahoma, Verdana, Arial, Helvetica, Sans Serif" SIZE="2">
Welcome:<BR>
</FONT><FONT FACE="Tahoma, Verdana, Arial, Helvetica, Sans Serif" SIZE="2" COLOR="#0000FF">Got Data? Send it to your users as an Excel Spreadsheet from your ASP Page</FONT><BR><BR>

<table BORDER="1" CELLSPACING="0" WIDTH="100%">
<tr>
  <td COLSPAN="11" BGCOLOR="lightgrey"><font SIZE="2" FACE="Arial,Helvetica">Activity Report</font></td>
</tr>
<tr>
  <th><font SIZE="1" FACE="Arial"><b>Activity #</b></font></th>
  <td><font SIZE="1" FACE="Arial"><b>Project #</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>Priority</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>Title</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>Status</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>Requested By</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>Date Needed</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>Plan End Date</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>Release</b></font></td>
  <td ALIGN="left"><font SIZE="1" FACE="Arial"><b>Est. Effort Hrs</b></font></td>
  <td ALIGN="left"><font SIZE="1" FACE="Arial"><b>Act. Effort Hrs</b></font></td>
</tr>
<%  For i = 1 to 10   %>
<tr>
  <td><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td ALIGN="CENTER"><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td ALIGN="CENTER"><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td ALIGN="CENTER"><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td ALIGN="CENTER"><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td ALIGN="RIGHT"><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td ALIGN="RIGHT"><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
</tr>
<% Next %>
<tr>
  <td BGCOLOR="GRAY"><font SIZE="1" COLOR="BLACK" FACE="Arial">Total</font></td>
  <td><font SIZE="1" FACE="Arial"><b>&nbsp;&nbsp;&nbsp;</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>&nbsp;&nbsp;&nbsp;</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>&nbsp;&nbsp;&nbsp;</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>&nbsp;&nbsp;&nbsp;</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>&nbsp;&nbsp;&nbsp;</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>&nbsp;&nbsp;&nbsp;</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>&nbsp;&nbsp;&nbsp;</b></font></td>
  <td><font SIZE="1" FACE="Arial"><b>&nbsp;&nbsp;&nbsp;</b></font></td>
  <td ALIGN="RIGHT"><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
  <td ALIGN="RIGHT"><font SIZE="1" FACE="Arial"><%= GetRandomValue(0) %></font></td>
</tr>
</table>
<%
%>
<P><FONT FACE="Tahoma, Verdana, Arial, Helvetica, Sans Serif" SIZE="2">
<A HREF="<%= Request.ServerVariables("SCRIPT_NAME") %>?e=1">Download this data as an Excel Spreadsheet</A><BR>
</BODY>
</HTML>
<%
End Sub
Sub SendExcelData()
Dim i, j
' -- will send directly as excel
      response.clear()
    'Response.AppendHeader "Content-Disposition","attachment; filename=", "Title"
response.ContentType="application/ms-excel"
'        Response.OutputStream.Write arrFileData, 0, arrFileData.Length
Response.AddHeader "Content-Disposition", "filename=mydata.xls;"
response.write "Activity #,"
  response.write "Project #,"
  response.write "Priority,"
  response.write "Title,"
  response.write "Status,"
  response.write "Requested By,"
  response.write "Date Needed,"
  response.write "Plan End Date,"
  response.write "Release,"
  response.write "Est. Effort Hrs,"
  response.write "Act. Effort Hrs,"
response.write vbNewLine

For i = 1 to 10
For j = 1 to 11
 Response.Write GetRandomValue(0) & ","
Next
response.write vbNewLine
Next

Response.write "Total,,,,,,,,,"
Response.Write GetRandomValue(0) & ","
Response.Write GetRandomValue(0) & ","
response.write vbNewLine

End sub

' -- returns a random number
Function GetRandomValue(byval iType)
Select Case iType
Case 0  ' Integer Number
 ' -- return an int between 1 and 30000
 ' Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
 GetRandomValue = Int((30000-1+1)* Rnd+ 1)
End Select
End Function
%>
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Export multiple excel sheets to user machine Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts