473,404 Members | 2,179 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,404 software developers and data experts.

ASP.Net Dynamic Excel Creation from SQL Datasource

I have a reguirement to enable the creation of excel workbooks from sql stored procedure. To do this I want to create a vb class to generate and save the excel files. Then and ASP.net page will enable opening the excel file via the browser or enable the user to download the file.

The class should be able to be called from a vareity of pages within the web app and have the ability to handle 8 to 10 separate stored procedures that will return various data sets.
Feb 15 '12 #1
2 2214
PsychoCoder
465 Expert Mod 256MB
Why not start by showing us what you've tried thus far and we will do our best to help
Feb 15 '12 #2
@Brian Sivel
Thanks for the reply. I stated creating my vb class but I'm stuck on how to dimension an excel application and pass the dataset results to it....

Expand|Select|Wrap|Line Numbers
  1. Imports Microsoft.VisualBasic
  2. Imports System.Data
  3. Imports System.Data.SqlClient
  4.  
  5. Public Class ExcelWriter
  6.     Public Sub MakeMyExcelFile(ByVal sp As String, ByVal fn As String, ByVal dt1 As Date, ByVal dt2 As Date)
  7.  
  8.  
  9.         Dim cnxnstr As String = ""
  10.         cnxnstr = ConfigurationManager.ConnectionStrings("PRTrackerDEVConnectionString").ToString
  11.         Using cnxn As New Data.SqlClient.SqlConnection(cnxnstr)
  12.  
  13.             Dim cmd As New Data.SqlClient.SqlCommand("bss_set_userid_locks", cnxn)
  14.             cmd.CommandType = Data.CommandType.StoredProcedure
  15.             cnxn.Open() : cmd.Connection = cnxn
  16.  
  17.             'Dimension all the parameters the stored procedure requires...
  18.             Dim pLoginDT1 As New Data.SqlClient.SqlParameter
  19.             Dim pLoginDT2 As New Data.SqlClient.SqlParameter
  20.  
  21.             'Configure each parameter...
  22.             With pLoginDT1
  23.                 .ParameterName = "@logindt1" : .DbType = Data.DbType.DateTime
  24.                 .Direction = Data.ParameterDirection.Input
  25.                 .Value = dt1
  26.                 cmd.Parameters.Add(pLoginDT1)
  27.             End With
  28.  
  29.             With pLoginDT2
  30.                 .ParameterName = "@logindt2" : .DbType = Data.DbType.DateTime
  31.                 .Direction = Data.ParameterDirection.Input
  32.                 .Value = dt2
  33.                 cmd.Parameters.Add(pLoginDT2)
  34.             End With
  35.  
  36.  
  37.             ' Create data adapter
  38.  
  39.             Dim da As New SqlDataAdapter(cmd)
  40.  
  41.             ' Fill dataset from adapter
  42.  
  43.             Dim ds As New System.Data.DataSet
  44.  
  45.             da.Fill(ds)
  46.  
  47.         End Using
  48.  
  49.  
  50.         Dim xlApp As 
  51.         Dim xlWorkBook As Excel.Workbook
  52.         Dim xlWorkSheet As Excel.Worksheet
  53.         Dim misValue As Object = System.Reflection.Missing.Value
  54.  
  55.         xlApp = New Excel.ApplicationClass
  56.         xlWorkBook = xlApp.Workbooks.Add(misValue)
  57.         xlWorkSheet = xlWorkBook.Sheets("sheet1")
  58.  
  59.  
  60.     End Sub
  61.  
  62. End Class
Feb 15 '12 #3

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

Similar topics

8
by: Krzys! | last post by:
I'd like to create a table dynamicly. List of column in this table should be taken from select: "select distinct fiel from table " How to do it ? tnx in advance for help K.
5
by: Tompa | last post by:
Hi, I would like to create images on the fly as a response to an http request. I can do this with PIL like this (file create_gif.py): from PIL import Image, ImageDraw print 'Status: 200 OK'...
1
by: andrew queisser | last post by:
I've been trying to dynamically create a class DevT that's derived from a generic base GenBase<T>. It doesn't seem to work. I'm attaching a code sample below that illustrates the problem. ...
2
by: charliewest | last post by:
I need to create textboxes in real-time, the actual number of which is determine by a result from a database query. I have been able to create the controls, and then add them to the ASPX page....
8
by: william_dean | last post by:
Hello, I've done some searching around the post, and I have found quite a bit of information related to the setAttribute and it's related uses. My problem lies in the usage of colspanning in dynamic...
0
by: gokulrajad | last post by:
Hi there, Iam trying to create a datagrid dynamically in asp .net (C#). It contains a leftmost column with the check box and few data columns and the last column is a hyperlink column. Please find...
1
by: None | last post by:
Dynamic array creation Hi all... here's a good one for you... I have a situation where I have some bean, and I need to populate an array field in it... here's the problem... I do not know the...
5
by: matt | last post by:
hello, i am on an interesting project. in this project, i have to create dynamic data-entry forms for offline-users to fill out, save locally, and eventually postback to our app (when back...
1
by: mitramay | last post by:
I am creating a dynamic datagrid. The controls in some of the template columns will have to be generated based on the data contained in them (i.e. the data for that respective DataField column)....
3
by: arunank | last post by:
Hi, The following code for dynamic table creation is not working. Can anyone please help me. The dynamically created rows and columns are not getting populated. CODE: ========= <html>
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.