Results 1 to 9 of 9

Thread: [RESOLVED] Export To Excel

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    243

    Resolved [RESOLVED] Export To Excel

    Hi, I'm exporting data to Excel. I've to put some headings, some data from datatable and again some footer text. For that I'm using following Code. It works fine locally but when I publish it it gives error while saving excel file as I'm hosting it on shared server. Can someone Help?

    Code:
    '--SOME HEADERS
    
    Dim HtmlStream As String
                HtmlStream = "<html><body><br/><div style='padding:15px;font-family:Tahoma;font-size:11px;'>"
                HtmlStream += "<table cellpadding='0' cellspacing='0' border='1' style='line-height:20px; border:solid 1px;font-size:11px;' width='100%'><tr><td colspan='8' style='height:20px;'></td></tr> <tr><Td colspan='8'>"
                HtmlStream += "<div style='padding-left:20px;'><b>MULTIPLE TRANSACTIONS REQUEST FORM</b><br /><b>Date -" + DateTime.Now + "</b><br /><b>Name of Applicant -  ABC CO. LTD.NEFT</b><br />"
    
    '--CODE FROM DATATABLE
    
    For i = 0 To mSeta.Rows.Count - 1
                    If Len(Trim(mSeta.Rows(i)(3))) > 0 Then
                        If mSeta.Rows(i)(8) > 500 Then
                            HtmlStream += "<tr style='line-height:30px;'><td style='width:10px;' align='right'>" + Convert.ToString(sNo) + "</td>"
                            HtmlStream += "<td align='right'>" + Convert.ToString(mSeta.Rows(i)(8)) + "</td><td align='left'>804-0-507995-6</td>"
                            HtmlStream += "<td align='left'>" + mSeta.Rows(i)(6) + "</td>"
                            HtmlStream += "<td align='left'>" + mSeta.Rows(i)(3) + "," + mSeta.Rows(i)(4) + "</td>"
                            HtmlStream += "<td align='left'>" + mSeta.Rows(i)(5) + "</td>"
                            HtmlStream += "<td align='left'>" + mSeta.Rows(i)(1) + "</td><td align='left'>INCENTIVE</td></tr>"
                            MyTotal = MyTotal + mSeta.Rows(i)(8)
                            sNo = sNo + 1
                        End If
                    End If
                Next
    
     
    
    '--SOME FOOTER
    
     
    
    HtmlStream += "<tr style='line-height:20px;'><td colspan='8' style='padding-left:50px;'>Total Amount to be transferred. <b>" + Convert.ToString(MyTotal) + "</b><br />"
                HtmlStream += "Total Number Of Items <b>" + Convert.ToString(sNo - 1) + "</b><br /><br />"
    
    '--NOW SAVING
    
    Dim file As New System.IO.StreamWriter("Commission.xls")
    file.WriteLine(HtmlStream) ';// now writing the stream to the file   
    file.Close() ';// closing the streamwriter
    '// Provide the actual path if not using this default path   
    Process.Start("Commission.xls") ';// Opening the excel sheet
    It gives error while saving

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Export To Excel

    With this line Process.Start("Commission.xls") you are trying to start a process on the web server. This works fine locally as your development machine IS the webserver.

    What are you trying to achieve with this? Even if you had permissions and the server had Excel installed on it the .xls file would open on a server in a datacentre somewhere that no-one may ever see.

    Are you really wanting to save the excel file on the server or are you wanting to add it to the response stream to deliver it to the end user?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    243

    Re: Export To Excel

    Quote Originally Posted by Fishcake View Post
    With this line Process.Start("Commission.xls") you are trying to start a process on the web server. This works fine locally as your development machine IS the webserver.

    What are you trying to achieve with this? Even if you had permissions and the server had Excel installed on it the .xls file would open on a server in a datacentre somewhere that no-one may ever see.

    Are you really wanting to save the excel file on the server or are you wanting to add it to the response stream to deliver it to the end user?
    No I don't want to save it on server. I just wish to save it on client's machine or it should ask where to save. What should I write for that.?

  4. #4

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    243

    Re: Export To Excel

    Will reply you shortly. Thanx

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    243

    Re: Export To Excel

    I'm trying this

    Try
    Dim strFileName As String = "Commission.xls"
    Response.Clear()
    Response.Charset = ""
    Response.ContentType = "application/vnd.ms-excel"
    Response.AddHeader("Content-Disposition", "attachment;filename=" & strFileName)
    Response.AddHeader("Pragma", "no-cache")
    Response.Write(HtmlStream.ToString)
    Response.End()
    Catch ex As Exception

    End Try

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Export To Excel

    Hello ravininave,

    Did this work for you? Or are you still having issues?

    If you are having issues, can you let us know what they are?

    Gary

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    243

    Re: Export To Excel

    Oh Gep 13, Sorry for not replying. Yes it's working very well now.Thanks Again.

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Export To Excel

    Quote Originally Posted by ravininave View Post
    Oh Gep 13, Sorry for not replying. Yes it's working very well now.Thanks Again.
    Glad to hear it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width