hi Steve,
Thank you very much for the answer.
I have read the examples on the aspnetpro.com page and tried the first two
examples through ASP.Net.
for the second example whose heading is 'Simply Compatible: Tab Delimited
Format'.
The code executed successfully but it didnot generate any xl file.
In the code for response.addheader i gave the file name with path though it
did not generate xl file.
Response.AddHeader("Content-Disposition", "inline;filename=c:\testHKVG.xls")
The code for above is like this below:
'------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim scon As SqlConnection = New SqlConnection("server=10.109.30.102;
UID=vf99; Pwd=lamap; database=dev;") ' Trusted_Connection=No")
scon.Open()
Dim adapter As SqlDataAdapter
Dim dt As DataTable
Dim ds As DataSet
adapter = New SqlDataAdapter("select * from tb_vf_property", scon)
ds = New DataSet
adapter.Fill(ds, "dt")
dt = ds.Tables("dt")
''Dim dt1 As DataTable
''dt1 = dt
''dt1 = CType(Application.Item("dt"), dt)
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition",
"inline;filename=c:\testHKVG.xls")
Response.Write(ConvertDtToTDF(dt))
End Sub
'Converts a DataTable to Tab Delimited Format
Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer
'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next
Response.Write(vbCrLf)
'Output Data
For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next
End Function
''---------------------------------------------------------
for 1st example whose heading is 'Make Excel Do the Work',
i got the below error at the line: Dim oExcel As New Excel.Application() in
aspx form.
pls suggest me how to solve it.
Access is denied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access is denied.
ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or
Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user (typically
IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET write access to a file, right-click the file in Explorer,
choose "Properties" and select the Security tab. Click "Add" to add the
appropriate user or group. Highlight the ASP.NET account, and check the boxes
for the desired access.
Source Error:
Line 28: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Line 29:
Line 30: Dim oExcel As Excel.Application = New Excel.Application
Line 31:
Line 32: Dim oBooks As Excel.Workbooks, oBook As Excel.Workbook
Source File: E:\Inetpub\wwwroot\WebApplication1\WebForm3.aspx.v b Line: 30
Stack Trace:
[UnauthorizedAccessException: Access is denied.]
WebApplication1.WebForm3.Page_Load(Object sender, EventArgs e) in
E:\Inetpub\wwwroot\WebApplication1\WebForm3.aspx.v b:30
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
"Steve C. Orr [MVP, MCSD]" wrote:
[color=blue]
> It's not really a great idea to use Excel from ASP.NET. Excel just wasn't
> designed for such a task, and that's why you are experiencing flakey
> behavior.
> Here's some best practices on the subject of exporting to Excel from
> ASP.NET:
>
http://www.aspnetpro.com/NewsletterA...200309so_l.asp
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
>
http://Steve.Orr.net
>
>
> "hari krishna" <harikrishna@discussions.microsoft.com> wrote in message
> news:3557C02B-11E3-4EE7-8131-8924ACF49025@microsoft.com...[color=green]
> > hi,
> > I am generating excel reports through vb.Net. After creating
> > excel.application and the report is generated, each report leaves Excel in
> > memory. I can see them in task manager in Process tab (as EXCEL). So the
> > memory has been taken by excel objects and memory is being full. i want to
> > delete or kill this objects which are in memory. i wrote the code as
> > 'myexcel.quit()' , myexcel=nothing. but still it is in memory.
> > pls tell me how to do.
> > rgds,
> > Hari.[/color]
>
>
>[/color]