| | |
Excel macros with asp.net
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2007
Posts: 14
Reputation:
Solved Threads: 0
I know the way to retrieve data from an excel file by code
Imports Microsoft.Office
Imports System.Data.OleDb
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Partial Class _Default
Inherits System.Web.UI.Page
Dim conn As New OleDbConnection
Dim comm As New OleDbCommand
Dim DReader As OleDbDataReader
Dim str As String = ""
Dim str1 As String = "Ans(e)"
Private Function createconnstring(ByVal str As String) As String
Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + str + ";Extended Properties=""Excel 8.0;HDR=YES;"""
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
conn.ConnectionString = createconnstring("C:\Documents and Settings\Administrator\Desktop\example1.xlsm")
comm.Connection = conn
comm.CommandText = "select * from [test$] where Qno = 1 "
conn.Open()
DReader = comm.ExecuteReader()
Do While DReader.Read
str = str + vbCrLf + DReader(3).ToString() + vbCrLf + DReader("Ans (b)").ToString()
Loop
Response.Write(str.ToString())
DReader.Close()
conn.Close()
Catch ex As Exception
MsgBox("error.")
conn.Close()
End Try
End Sub
End Class
but this show error if i use an excel with macro enabled file that is .xlsm file how to make this code compatible for that file too
Imports Microsoft.Office
Imports System.Data.OleDb
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Partial Class _Default
Inherits System.Web.UI.Page
Dim conn As New OleDbConnection
Dim comm As New OleDbCommand
Dim DReader As OleDbDataReader
Dim str As String = ""
Dim str1 As String = "Ans(e)"
Private Function createconnstring(ByVal str As String) As String
Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + str + ";Extended Properties=""Excel 8.0;HDR=YES;"""
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
conn.ConnectionString = createconnstring("C:\Documents and Settings\Administrator\Desktop\example1.xlsm")
comm.Connection = conn
comm.CommandText = "select * from [test$] where Qno = 1 "
conn.Open()
DReader = comm.ExecuteReader()
Do While DReader.Read
str = str + vbCrLf + DReader(3).ToString() + vbCrLf + DReader("Ans (b)").ToString()
Loop
Response.Write(str.ToString())
DReader.Close()
conn.Close()
Catch ex As Exception
MsgBox("error.")
conn.Close()
End Try
End Sub
End Class
but this show error if i use an excel with macro enabled file that is .xlsm file how to make this code compatible for that file too
![]() |
Similar Threads
- Freelance Developer ASP.NET / VB.NET / C# / VB / ASP & Crystal Reports (Web Development Job Offers)
- Need help on export asp.net table to excel (ASP.NET)
- Batch file in ASP.Net to convert Excel files into higher version (ASP.NET)
- "No Servers are available" Error with ASP.NET Webpage (Networking Hardware Configuration)
- ASP.NET Freelance Programmer / Developer (IT Professionals' Lounge)
- ASP.NET to Power Point (ASP.NET)
- Question for ASP.NET/Mozilla Users...or anyone... (ASP.NET)
- .NET Speech SDK for ASP.NET (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Data Base format in dotnet
- Next Thread: how letting the user open a file without showing message of (Open,Save,cancel)
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv gridview gudi iis javascript list listbox login menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





