Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to create a Excel sheet in a button click event using C#
Posted
Updated 3-Dec-13 17:39pm
v3
Comments
BillWoodruff 3-Dec-13 23:25pm    
Search MSDN.

Hope this links might helps you http://stackoverflow.com/questions/16705651/how-to-create-a-new-worksheet-in-excel-file-c[^]

or this link too Using C# to Create an Excel Document[^]

If this does n't works let us know, we are here to help you.

Thanks
Ganesh
 
Share this answer
 
Add this Namespaces

Imports System.Configuration
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
Imports System.IO

Write this Code where you want

VB
Dim Path As String = Server.MapPath("SendRequest\" + Filename)
        Dim FileInfor As New FileInfo(Path)
        Dim stringWriter As New StringWriter()
        Dim htmlWrite As New HtmlTextWriter(stringWriter)
        Dim directory__1 As String = Path.Substring(0, Path.LastIndexOf("\"))
        If Not Directory.Exists(directory__1) Then
            Directory.CreateDirectory(directory__1)
        End If
        Dim vw As New System.IO.StreamWriter(Path, True)
        stringWriter.ToString().Normalize()
        vw.Write(stringWriter.ToString())
        vw.Flush()
        vw.Close()
        WriteAttachment(FileInfor.Name, "application/vnd.ms-excel", stringWriter.ToString())


Add this Function also

VB
Public Shared Sub WriteAttachment(ByVal FileName As String, ByVal FileType As String, ByVal content As String)
        Dim Response As HttpResponse = System.Web.HttpContext.Current.Response
        Response.ClearHeaders()
        Response.AppendHeader("Content-Disposition", "attachment; filename=" & FileName)
        Response.ContentType = FileType
        Response.Write(content)
        Response.[End]()
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900