![]() |
| ||
| Excel macros with asp.net 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 |
| All times are GMT -4. The time now is 3:03 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC