Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2007, 03:04 AM
Registered User
 
Join Date: Aug 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel macro with asp.net

I know the way to retrieve data from an excel sheet by the 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
Thread Thread Starter Forum Replies Last Post
Macro in Excel mateenmohd Excel VBA 3 June 16th, 2008 07:34 PM
Macro excel mathb79 Excel VBA 3 August 13th, 2005 06:55 PM
Excel 2000 vs Excel 2002 Macro Issue williadn Excel VBA 1 July 14th, 2005 09:09 AM
How to call an existing excel macro from ASP.NET swadhinm ASP.NET 1.x and 2.0 Application Design 0 June 8th, 2005 03:58 AM
Excel 4.0 macro sezak99 Excel VBA 1 September 21st, 2003 11:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.