473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

RE: Adding filters to excel report

Hi folks,

I am a newbie to this functionality of creating excel report using VB/VB Script.
I have been given a code and asked to add filters to the excel sheet that is created using the below code.

Can somebody help me out in resloving the issue??


<%
Option Explicit
%>
<!--#include file="connection.asp"-->//DB connection string
<%
Dim sqlstr
Dim oConn,sql,rs,HeaderTitle,dDateNow,sDateString,sFil eName

Const PAGE_TITLE = "Contract Database Reporting"

'download to excel
'setup filename
dDateNow = Now
sDateString = CStr(Month(dDateNow)) & CStr(Day(dDateNow)) & CStr(Year(dDateNow)) & CStr(Hour(dDateNow)) & CStr(Minute(dDateNow))

sqlstr = Trim(Request.Form("SQL"))

sFileName = "ContractDB_datadump_" & sDateString & ".xls"

sql = sqlstr
'db oConnection and query

if Request.QueryString("Pref") = "Yes" then
sql = "SELECT Datecreated,Ref_Num,Record_Status,Agr_Model,Suppli erRating,SupType,Company_Name,Com_Group,Com_Code,P referredGeography,PreferredCountries,Proc_Email,St art_Date,End_Date FROM Sample WHERE Record_Status = 'Active' AND SupplierRating LIKE 'Preferred%' Order by Company_Name Asc"
end if

Set rs = Server.CreateObject("ADODB.Recordset")
Set rs = oConn.Execute(sql)

'call rs to excel function
Call DisplayRSInExcel(rs,"#CC0033","#FFFFFF",sFileName)
'cleanup
rs.Close
Set rs = Nothing
oConn.Close
Set oConn = Nothing

'-------------routines used in this page --------------------------------------------------------
'function display RS in excel format in browser
Sub DisplayRSInExcel(oRs,sHeaderBGColor,sHeaderFontCol or,sFilename)
Dim m, i 'number of fields, loop variable
Dim s1, s2 'work strings
Dim sCellValue
Dim sCellBGColor
Dim objExcel
Dim objMailName
'Dim sFieldVal
Dim s_RetVal

'excel header info
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=" & sFilename

If oRs.EOF Then
Response.Write "No records match your request" & vbcrlf
Else
if Request.QueryString("Pref") = "Yes" then

'create table & header cells (and border if desired)
Response.Write "<table cellpadding=""0"" cellspacing=""0"" border=""1"">" & vbcrlf & "<tr>" & vbcrlf

'create header
m = oRs.Fields.Count - 1
For i = 0 To 13

s1 = oRs.Fields(i).Name & ""
s2 = replace(s1, "_", " ")
Response.Write "<td align=""left"" valign=""top"" bgcolor=""" & sHeaderBGColor & """><b><font color=""" & sHeaderFontColor & """>" & s2 & "</font></b></td>"
Next
Response.Write "</tr>" & vbcrlf & vbcrlf

'create detail records
Do While Not oRs.EOF
Response.Write "<tr>"
For i = 0 To 13
sCellValue = oRs.Fields(i).Value

If IsNull(sCellValue) Then sCellValue = ""
sCellBGColor = ""
Next
Response.Write "</tr>" & vbcrlf
oRs.MoveNext
Loop
Response.Write "</table>" & vbcrlf

Else

'create table & header cells (and border if desired)
Response.Write "<table cellpadding=""0"" cellspacing=""0"" border=""1"">" & vbcrlf & "<tr>" & vbcrlf

'create header
m = oRs.Fields.Count - 1

For i = 0 To 26

s1 = oRs.Fields(i).Name & ""

If s1 = "ReqState" Then
Else
s2 = replace(s1, "_", " ")
Response.Write "<td align=""left"" valign=""top"" bgcolor=""" & sHeaderBGColor & """><b><font color=""" & sHeaderFontColor & """>" & s2 & "</font></b></td>"
End If
Next
Response.Write "</tr>" & vbcrlf & vbcrlf

'create detail records
Do While Not oRs.EOF
Response.Write "<tr>"
For i = 0 To 26
sCellValue = oRs.Fields(i).Value

If oRs.Fields(i).Name = "ReqState" Then
Else

If IsNull(sCellValue) Then sCellValue = ""
sCellBGColor = ""

Response.Write "<td " & sCellBGColor & ">" & sCellValue & "</td>"

End If
Next
Response.Write "</tr>" & vbcrlf
oRs.MoveNext
Loop
Response.Write "</table>" & vbcrlf

End If

End If

End Sub
%>
Thanks in advance.

Regards,
Chandhseke
Dec 22 '09 #1
1 2322
P.S I want to add filters to the excel sheet that gets generated using the above code. Please help
Dec 22 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Spacy | last post by:
Am creating a HTML Report in asp.net. To save this report to excel on client-side, i write this code: Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition",...
1
by: Steven Stewart | last post by:
I have a user who has been using Excel for a while to keep statistics and print reports. She finds using it cumbersome because of long formulas and a lot of copying and pasting. I have designed...
5
by: MGFoster | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I've converted an ACC97 .mdb file to an ACC2K2 .adp. A report that worked in ACC97 doesn't work in ACC2K2. Report setup: ACC97 ...
1
by: jim4u | last post by:
Hi gurus, I have an automation add-in created using C# for Excel, in which I am exposing a number of functions. Is there any way I can add help-text the way excel does for other categories like...
6
by: smcdonald | last post by:
I have a report that opens up using a pretty complex query. I then pop up a form with combo boxes so the user can apply a filter to the existing report and then refresh the report. I need to export...
4
by: somanyusernamesaretakenal | last post by:
What I am trying to achieve: Basically I have generated a report in access. This report needs to be updated using excel. (Updating the new data, not changing existing data) What I did was I...
5
by: favor08 | last post by:
have a mainform called PendingsMain and a subform called PendingsSub. You can filter the subform by different filters and this works fine. i want to create a report that will print out the...
5
by: nkechifesie | last post by:
Hi, I have written a VBA program that runs on Excel and puts data on the excel sheet. This runs everyday. I want to be adding the dates to the files, this date is gotten from the excel sheet that...
1
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.