Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6132913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:09:40+00:00 2026-05-23T17:09:40+00:00

Overview: Using C#, I’m outputting a LINQ to SQL table of data into a

  • 0

Overview: Using C#, I’m outputting a LINQ to SQL table of data into a WebControls.GridView and then outputting it to an Excel file served from a webpage. How do I modify a field in the GridView?

Problem: Excel is truncating and/or converting a string that is numeric to scientific notation.

198886545467896 turns into 1.98887E+14

In order to retain this field as a string, I need to wrap the field into a string formula as follows so that Excel will display it as intended.

=”198886545467896″

Question: How do I wrap the field data in a specific GridView column with =”[number]”?

Here is my relevant C#:

public void DownloadExcelReport(int id)
    {
        // See: http://www.codeshelve.com/code/details/54/export-to-excel-in-asp-net-mvc
        // Or: http://www.billsternberger.net/asp-net-mvc/export-to-excel-or-csv-from-asp-net-mvc-with-c/
        // Or: http://blog.wiredworx.co.uk/website-and-seo/c-tutorials-and-tips-visual-studio/exporting-to-an-excel-file-from-asp-net-mvc/
        // same solution - discussed differently            

        IEnumerable<Customer> customers = Db.Customers(id);

        // Create a grid and bind the customer data to it.
        var grid = new System.Web.UI.WebControls.GridView();
        grid.DataSource = customers;
        grid.DataBind();

        // TODO: I need to wrap the data in column 2 with =" "
        // UPDATE: INSERT the code from the accepted answer below right here

        // Prep the http response to return an excel mime type file
        Response.ClearContent();
        Response.AddHeader("content-disposition", "attachment; filename=Report.xls");
        Response.ContentType = "application/excel";

        // Output the grid via the html writer to the response
        StringWriter sw = new StringWriter();
        var htw = new System.Web.UI.HtmlTextWriter(sw);
        grid.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }

Update: in retrospect, this could have been written much more simply, to isolate the specific issue: GridView is clunky to navigate. However, it’s nice to have the whole solution in how to output from a Linq to Sql table all the way to an Excel file for later reference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:09:41+00:00Added an answer on May 23, 2026 at 5:09 pm

    Something like this?

    System.Web.UI.WebControls.GridView() test = new System.Web.UI.WebControls.GridView();
    for (int i = 0; i < grid.Rows.Count; i++)
    {
        test.Rows[i].Cells[<yer column index>].Text = "=/"" + test.Rows[i].Cells[<yer column index>].Text + "/"";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick overview Trying to insert a Business Object using ObjectDataSource (on a GridView) Get
I'm looking for an overview of algorithms, you need every now and then. If
Problem overview: When using Eclipse Ganymede with the Web Tools Platform the project gets
Overview I am using CompositeWPF to create an app using C#. This really should
Overview I am trying to get a photo feed on to my site using
In Eclipse we are using Mylyn to have an overview of our Trac Tickets.
I am using this library to hold information about tree structure: http://www.datasoftsolutions.net/tree_container_library/overview.php Here is
I am using jQuery star rating control found at http://www.fyneworks.com/jquery/star-rating/#tab-Overview . I am using
As a quick overview: I'm trying to make a game of pool using Box2D
I'm using the Drupal views module to create an overview of nodes. In the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.