| | |
Excel macros with asp.net
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
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 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer c# c#gridviewcolumn checkbox class commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist development dgv dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formatdecimal forms formview gridview gudi homeedition iframe iis javascript jquery listbox menu microsoft mouse mssql multistepregistration nameisnotdeclared news objects opera panelmasterpagebuttoncontrols problem redirect registration relationaldatabases reportemail rotatepage schoolproject security serializesmo.table silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webdevelopment webprogramming webservice youareanotmemberofthedebuggerusers





