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

  • Home
  • SEARCH
  • 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 8233409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:07:18+00:00 2026-06-07T18:07:18+00:00

When I export my data into excel, it loads up the columns but doesn’t

  • 0

When I export my data into excel, it loads up the columns but doesn’t expand the columns. It shows the data without having to double click on the line to expand the columns. Can I write some code which will automatically auto-adjust the columns so that the cells can show the entire data? I’m using asp.net and c#.

The first picture is what it currently looks like & the second shows what I want it to look like.

What it looks like

What I want it to look like

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.Buffer = true;

    DataSet dataSet = new DataSet();

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ISALog1ConnectionString"].ToString());
    SqlCommand cmd = new SqlCommand("exec ProxyReport", conn);
    cmd.CommandTimeout = 200;
    SqlDataAdapter ad = new SqlDataAdapter(cmd);
    ad.Fill(dataSet);

    GridView1.DataSource = dataSet.Tables[0];
    GridView1.DataBind();
    GridView2.DataSource = dataSet.Tables[1];
    GridView2.DataBind();
    GridView3.DataSource = dataSet.Tables[2];
    GridView3.DataBind();

    dataSet.Tables[0].TableName = "1";
    dataSet.Tables[1].TableName = "2";
    dataSet.Tables[2].TableName = "3";

    int count = 3;

    ExcelPackage pack = new ExcelPackage();


    for (int i = 1; i <= count; i++)
    {
        DataTable table = dataSet.Tables[i.ToString()];
        ExcelWorksheet ws = pack.Workbook.Worksheets.Add("Top" + i);
        ws.Cells["A1"].LoadFromDataTable(table, true);
    }  

            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.AddHeader("content-disposition", "attachment;  filename=ExcelExport.xlsx");
            Response.BinaryWrite(pack.GetAsByteArray());
            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-06-07T18:07:22+00:00Added an answer on June 7, 2026 at 6:07 pm
    Excel.Range range;
    
    range = ws.get_Range("A1", "1");
    range.AutoFit();
    

    MSDN

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to export data to excel from Delphi without having to own a
I'm trying to export data from a web app into excel, but there is
I want to export the data from a DaraGrid into an Excel file. Having
My company receives data from an external company via Excel. We export this into
I am attempting to export mysql data into excel. I have tried the phpexcel
I am using a PHP script to export data from MySQL into Excel. The
I have some PHP script for export MYSQL table into Excel format, but I
I'm trying to export data from an Excel spreadsheet into a fairly complex relational
I'm trying to export data from R into one Excel file (into different sheets):
How can i export my data from SQL server 2008 into Excel 2010 or

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.