Click here to Skip to main content
15,886,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All...
am using asp.net-2 i want to open a excel file in the web browser when Print Button Click hear my code....
it couldnt open in setup file when i configure in localhost


VB
Protected Sub btn_print_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_print.Click
        Dim a As String = ""
        Dim dsExport As New DataSet()
        Dim tw As New System.IO.StringWriter()
        Dim hw As New System.Web.UI.HtmlTextWriter(tw)
        Dim dgGrid As New DataGrid()
        Dim xlWorkBook As Excel.Workbook
        Dim xlApp As Excel.Application = New Excel.Application
        'Dim xls As Excel.Worksheet
        xlWorkBook = New Excel.Application().Workbooks.Add(True)
        xlWorkBook.Application.Visible = False

        Dim xls As Excel.Worksheet = CType(xlWorkBook.Worksheets(1), Excel.Worksheet)
        xls = xlWorkBook.ActiveSheet

 xls.Cells(3, 1) = ("Materials Received Note")
        xls.Range("A3").Resize(1, 9).Cells.HorizontalAlignment = 3
        xls.Range("A3").Resize(1, 9).Cells.MergeCells = True
        xls.Cells(3, 1).font.size = 18
        xls.Cells(3, 1).font.Bold = False
         :
         :
         :


    xls.Range("G17", "G39").Columns.AutoFit()
        xls.Range("A17", "A39").Columns.AutoFit()
        xls.Range("D11", "D15").Columns.AutoFit()
        xls.Range("A11", "B15").Columns.AutoFit()
        xls.Range("I11", "I15").Columns.AutoFit()
Posted
Updated 9-Mar-12 3:05am
v2

1 solution

The easiest way to do it is to Response.Redirect(urlOfExcelFileOnServer). That will serve the xl file to the client.
 
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