[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Grid view - Export to Excel without hyperlink

Posted on 2007-04-09
6
Medium Priority
?
2,804 Views
Last Modified: 2012-08-14
We are working on ASP.Net 2.0 and VB.Net.
We have gridview whichis bounded to the dataset. The first column of the grid view is hyperlinked. We would like to export the grid into excel. When we do the same, we getting the hyperlink in the excel as well. We would like to remove the hyperlink when exported to excel. Please let me know how to do this? Also any code sample will be of great help
0
Comment
Question by:harsha74
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:viveksg
ID: 18880410
You can use regular expressions just before exporting to eliminate hyperlinks.
I think you are using stringwriter for exporting. Try the below code.

Regex.Replace(oStringWriter.ToString(),@"(<a[^>]*>)|(</a>)"," ",RegexOptions.IgnoreCase)

If you still have any doubt, pls post that.
0
 

Author Comment

by:harsha74
ID: 18880724
We are still getting the hyperlink. Pl see the code we are using. Pl let me know what's the problem in the code.
Protected Sub ExcelImage_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ExcelImage.Click
       
        'Variable Declaration

        Dim sw As StringWriter = New StringWriter()
        Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
       
        Try
            Response.Clear()
            Response.ContentType = "application/vnd.excel"
            Response.Charset = ""
            Response.AddHeader("content-disposition", "attachment; FileName=MyFile.xls")
            'To bind the dataset to the datagrid, to export the same to excel

            grdSummaryReport.RenderControl(htw)
            Regex.Replace(sw.ToString(), "(<a[^>]*>)|(</a>)", " ", RegexOptions.IgnoreCase)
            Response.Write(sw.ToString())
            Response.End()
        Catch ex As Exception
            lblErrorMsg.Text = ex.Message
        Finally
                  End Try
    End Sub
0
 
LVL 3

Expert Comment

by:viveksg
ID: 18880801
Instead of
Regex.Replace(sw.ToString(), "(<a[^>]*>)|(</a>)", " ",  
                         RegexOptions.IgnoreCase)
Response.Write(sw.ToString())

use

Response.Write(Regex.Replace(sw.ToString(),@"(<a[^>]*>)|
                           (</a>)"," ",RegexOptions.IgnoreCase))
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Accepted Solution

by:
viveksg earned 2000 total points
ID: 18880805
or full code

Protected Sub ExcelImage_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ExcelImage.Click
       
        'Variable Declaration

        Dim sw As StringWriter = New StringWriter()
        Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
       
        Try
            Response.Clear()
            Response.ContentType = "application/vnd.excel"
            Response.Charset = ""
            Response.AddHeader("content-disposition", "attachment; FileName=MyFile.xls")
            'To bind the dataset to the datagrid, to export the same to excel

            grdSummaryReport.RenderControl(htw)
         
            Response.Write(Regex.Replace(sw.ToString(), "(<a[^>]*>)|(</a>)", " ", RegexOptions.IgnoreCase))

            Response.End()
        Catch ex As Exception
            lblErrorMsg.Text = ex.Message
        Finally
                  End Try
    End Sub
1
 

Expert Comment

by:babalooey
ID: 21156473
Works great - just what I was looking for.  Be sure to include the regular expressions namespace on the page. C#: using System.Text.RegularExpressions;
0
 
LVL 1

Expert Comment

by:icastel080801
ID: 21674438
Excellent solution.  Simple and functional.  Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question