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 6159357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:07:06+00:00 2026-05-23T21:07:06+00:00

I am exporting gridview data to excel but that excel file add the some

  • 0

I am exporting gridview data to excel but that excel file add the some lable text and textbox values and format also taken , pls give how to design the excel code in asp.net. I am writing like this

  • All gridview data taken dataset ds
    -pls give me textbox values and some label or normal text designed code in excel

    GridView GridView1 = new GridView();
    GridView1.AllowPaging = false;
    GridView1.DataSource = ds;
    GridView1.DataBind();

        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition",
        "attachment;filename=DataTable.xls");
        Response.Charset = string.Empty;
        Response.ContentType = "application/vnd.ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
    
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
        ////Apply text style to each Row
                GridView1.Rows[i].Cells[4].Attributes.Add("class", "textmode");
        }
        GridView1.RenderControl(hw);
    
        //style to format numbers to string
        string style = @"<style> .textmode { mso-number-format:'\#,\#\#0\.00';}
        .textmode1(mso-number-format:'\@';}
        .SSNmode{mso-number-format:'000-00-000';} </style>";
    
    
        Response.Write(style);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End(); 
    
  • 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-23T21:07:07+00:00Added an answer on May 23, 2026 at 9:07 pm

    Take a look at this awesome tool: http://www.carlosag.net/Tools/ExcelXmlWriter/

    Futhermore, the author also created a code generator, which generates .net code from a provided excel sheet(formatting, layout and so on)
    http://www.carlosag.net/Tools/ExcelXmlWriter/Generator.aspx

    Here’s some code that generates an excel file from a datatable (converted vb code, as pr. request by poster)

            CarlosAg.ExcelXmlWriter.Workbook book = new CarlosAg.ExcelXmlWriter.Workbook();
            book.ExcelWorkbook.ProtectWindows = false;
    
            book.ExcelWorkbook.ProtectStructure = false;
    
            var styles = book.Styles;
            WorksheetStyle defaultStyle = styles.Add("Default");
            var defStyles = defaultStyle;
            defStyles.Name = "Normal";
            defStyles.Font.FontName = "Calibri";
            defStyles.Font.Size = 11;
            defStyles.Font.Color = "#000000";
            defStyles.Alignment.Vertical = StyleVerticalAlignment.Bottom;
    
            Worksheet sheet = book.Worksheets.Add("Sheet1");
            sheet.Table.DefaultRowHeight = 15f;
            sheet.Table.FullColumns = 1;
            sheet.Table.FullRows = 1;
            DataTable dt = new DataTable();  //=  your datatable
    
            //Header
            WorksheetRow HeaderRow = sheet.Table.Rows.Add();
            foreach (DataColumn col in dt.Columns)
            {
                HeaderRow.Cells.Add(col.ColumnName.ToString());
    
            }
            //Body
            foreach (DataRow dr in dt.Rows)
            {
                WorksheetRow row = sheet.Table.Rows.Add();
                foreach (DataColumn cols in dt.Columns)
                {
                      row.Cells.Add(dr[cols.ColumnName.ToString()].ToString());
                }
            }
    
            sheet.Options.Selected = true;
            sheet.Options.ProtectObjects = false;
            sheet.Options.ProtectScenarios = false;
    
            book.Save("path to file");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview that I am exporting to an excel file. When I
Exporting some data from mysql to a csv file using FasterCSV. I'd like the
Summary: exporting pixel data from NSOpenGLView to some file formats gives incorrect colours I
When exporting some data from MS SQL Server using Python, I found out that
Iam exporting a DataTable to an Excel-file using office interop. The problem is, that
In ASP.NET, I am exporting some data to Excel by simply binding a DataSet
In my application i'm exporting gridview data to excel and storing it to a
We're exporting some data from a website app into an Excel spreadsheet, however, when
in my application im exporting gridview data to excel sheet now i want save
I'm exporting a gridview to an excel file and it opens just fine. Only

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.