1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
Imports Aspose.Cells
Imports System.Data.OleDb
Imports System.IO
Public Class Designer
Inherits System.Web.UI.Page
Protected Sub btnProcess_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim path As String = MapPath(".")
path = path + "\Designer\SmartMarkerDesigner.xls"
'Create filestream object
Dim fs As FileStream = New FileStream(path, FileMode.Open, FileAccess.Read)
Dim data As Byte() = New Byte(fs.Length) {}
fs.Read(data, 0, data.Length)
fs.Close()
Response.ContentType = "application/vnd.ms-excel"
'Add header
Response.AddHeader("content-disposition", "attachment; filename=SmartMarkerDesigner.xls")
Response.BinaryWrite(data)
' End response to avoid unneeded HTML after XLS
Response.End()
End Sub
#Region " Private code to create data source "
Private Function CreateDataSource() As DataSet
Dim ds As DataSet = New DataSet()
Dim oleDbConnection1 As OleDbConnection = New OleDbConnection()
Dim path As String = MapPath(".")
path = path.Substring(0, path.LastIndexOf("\"))
oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\Database\Northwind.mdb"
Dim oleDbDataAdapter1 As OleDbDataAdapter = New OleDbDataAdapter()
oleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Order Details", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Discount", "Discount"), New System.Data.Common.DataColumnMapping("OrderID", "OrderID"), New System.Data.Common.DataColumnMapping("ProductID", "ProductID"), New System.Data.Common.DataColumnMapping("Quantity", "Quantity"), New System.Data.Common.DataColumnMapping("UnitPrice", "UnitPrice")})})
Dim oleDbSelectCommand1 As OleDbCommand = New OleDbCommand()
oleDbSelectCommand1.Connection = oleDbConnection1
oleDbDataAdapter1.SelectCommand = oleDbSelectCommand1
oleDbSelectCommand1.CommandText = "SELECT Discount, OrderID, ProductID, Quantity, UnitPrice FROM [Order Details]"
Dim oleDbDataAdapter2 As OleDbDataAdapter = New OleDbDataAdapter()
oleDbDataAdapter2.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Customers", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Address", "Address"), New System.Data.Common.DataColumnMapping("City", "City"), New System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"), New System.Data.Common.DataColumnMapping("ContactName", "ContactName"), New System.Data.Common.DataColumnMapping("ContactTitle", "ContactTitle"), New System.Data.Common.DataColumnMapping("Country", "Country"), New System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), New System.Data.Common.DataColumnMapping("Fax", "Fax"), New System.Data.Common.DataColumnMapping("Phone", "Phone"), New System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"), New System.Data.Common.DataColumnMapping("Region", "Region")})})
Dim oleDbSelectCommand2 As OleDbCommand = New OleDbCommand()
oleDbSelectCommand2.Connection = oleDbConnection1
oleDbDataAdapter2.SelectCommand = oleDbSelectCommand2
oleDbSelectCommand2.CommandText = "SELECT Address, City, CompanyName, ContactName, ContactTitle, Country, CustomerID, Fax, Phone, PostalCode, Region FROM Customers"
oleDbConnection1.Open()
oleDbDataAdapter1.Fill(ds)
oleDbDataAdapter2.Fill(ds)
oleDbConnection1.Close()
Return ds
End Function
#End Region
End Class
|