943,985 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 3249
  • ASP.NET RSS
Aug 12th, 2007
0

Excel macros with asp.net

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
virus220 is offline Offline
14 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Data Base format in dotnet
Next Thread in ASP.NET Forum Timeline: how letting the user open a file without showing message of (Open,Save,cancel)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC