Solved

Opening an Excel TEMPLATE that is Stored as a BLOB in SQL Server

Posted on 2003-10-21
13
171 Views
Last Modified: 2010-05-01
I have a table that stores EXCEL templates.  :

Here is what I have:

set cn=SERVER.CreateObject("ADODB.CONNECTION")
cn.ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;" & _
    "Initial Catalog=dbAS_FAC_CENSUS;Data Source=ASDEV" & _
    ";User Id=" & Request.Form("txtUserID") & _
    ";Password=" & Request.Form("txtPwd")
cn.Open
set rs=server.CreateObject("ADODB.RECORDSET")
set rs.ActiveConnection=cn
rs.Open("SELECT * FROM vwMART_REPORTS WHERE strUserID='" & Request.Form("txtUserID") & "'")

THE rs("Report") field has the actual Template.  How do I open the contents of that field in Excel?
0
Comment
Question by:clangl
  • 8
  • 5
13 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9593181
you have to create a temporary local file and open it.
0
 

Author Comment

by:clangl
ID: 9593965
But how do I get it from the table to a local file?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9594073
OK. You need to use ADDB.stream object (more on this later)
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9594091
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 250 total points
ID: 9594101
0
 

Author Comment

by:clangl
ID: 9594180
with the ADo stream method....
What my goal is, is to have them click on this link on a web browser that points to that Field in the table and then have excel open right up......
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9598881
But that's a complete diferent scenario!!!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9598901
You need to create/extract the file at server side after user does the click and navigate to resulting xls file. It should be opened in web browser window.
0
 

Author Comment

by:clangl
ID: 9608892
This will work but I need to be able to do this with out saving it to a file.  I will post another question.  Thank you for your help.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9609096
Hummm, i think you can't but i maybe wrong.
Thanks for "A" grade.
0
 

Author Comment

by:clangl
ID: 9614325
I ended up not using a stream.
Just in case you ever need something similiar here is what I ended up doing:

<%
Response.buffer = TRUE
'on error resume next
dim strReport
strReport=left(Request.Form.Item,instr(1,Request.Form.Item,"=")-1)
'Response.Write strReport

dim cn, cmd,rs
set cn=SERVER.CreateObject("ADODB.CONNECTION")
set rs=server.CreateObject("ADODB.Recordset")
cn.ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;" & _
    "Initial Catalog=dbAS_FAC_CENSUS;Data Source=ASDEV" & _
    ";User Id=" &  Session("User") & _
    ";Password=" & Session("Pwd")
cn.Open
set cmd=server.CreateObject("ADODB.Command")
set cmd.ActiveConnection=cn
cmd.CommandType=4
cmd.CommandText="sp_MART_GetReport"
set rs=cmd.Execute(,strReport)
set fld=rs.Fields(0)
cBytes = fld.ActualSize
Response.Clear
'Response.ContentType = "application/vnd-ms-excel"
      Response.ContentType = rs.Fields(1).Value
      Response.AddHeader "Content-Disposition", "filename=a.xlt;"
      Response.BinaryWrite (fld.GetChunk(cBytes))
rs.Close
set fld=nothing
set rs=nothing
set cmd=nothing
cn.Close
set cn=nothing

%>
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9614344
excellent!!, that's for sure far ago from my knowledge. excellent work again.
(I really think you accepted my comment too soon :)
0
 

Author Comment

by:clangl
ID: 9614401
I ended up using your answer to back in all the Templates to the SQL Database.  
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question