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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:18:55+00:00 2026-05-27T06:18:55+00:00

I want to have this , but instead have this . Please note, when

  • 0

I want to have this enter image description here,
but instead have this enter image description here.
Please note, when I change VerticalAlign.Middle to VerticalAlign.Top it actually works as expected.
Please see below code that I am trying:

   // I assume that table table is already created and well-defined  
   // Create a new row

    TableRow tRow = new TableRow();

    tRow.HorizontalAlign = HorizontalAlign.Center;

    // add the row to the table

    table.Rows.Add(tRow);

    // Create a new cell

    TableCell tCell = new TableCell();

    tCell.VerticalAlign = VerticalAlign.Middle; // Want to get it in the middle of two merged rows

    tCell.RowSpan = 2;

    tCell.Text = "England";

    tCell.Font.Bold = true;

    tRow.Cells.Add(tCell);

    // Create new cell

    tCell = new TableCell();

    tCell.Text = "2010";

    tCell.Font.Bold = true;

    tRow.Cells.Add(tCell);

    // Create new row

    tRow = new TableRow();

    // add the row to the table

    table.Rows.Add(tRow);

    // Create new cell

    tCell = new TableCell();

    tCell.Text = "2011";

    tCell.Font.Bold = true;

    tRow.Cells.Add(tCell);

Update: Please see extra code below. I don’t have html code as such, but I looked at sw.ToString() and formatting looks right but still excel file does not seem to be rightly formatted. My browser is IE but I think it does not matter.
I tried tCell.CssClass = “className”; result is the same.

public static void Comparison_Report(string fileName)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName));
HttpContext.Current.Response.ContentType = "application/ms-excel";
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// Create a table to contain the grid
Table table = new Table();

///----- Original code goes here----

// render the table into the htmlwriter
table.RenderControl(htw);
// render the htmlwriter into the response  
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.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-27T06:18:55+00:00Added an answer on May 27, 2026 at 6:18 am

    Finally i’ve tested it by myself. It seems not to work in Excel if you use valign="middle" on your table-cell. You must use CSS.

    So instead of

    tCell.VerticalAlign = VerticalAlign.Middle
    

    do

    tCell.Style.Add("vertical-align", "middle")
    

    That will align the text correctly in excel. Excel itself uses css-classes if you export it from excel to html.

    But repeating my comment, i would recommend to generate a real excel file instead of creating html that might be openened and interpreted correctly.
    It’s very simple with EPPlus: Exporting data to excel

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

Sidebar

Related Questions

I want to do this in C#, but I don't know how: I have
this is what i want. but i have put only a specified date. SELECT
Of course most languages have library functions for this, but suppose I want to
I have this code: myVariable which I want to change into trace(myVariable: + myVariable);
Note, I have found the solution to my problem. Please see below. I'm converting
I have this HTML structure and want to convert it to an accordion. <div
I have this query statement and want to only get records that has a
I have this situation where I want to display a list of Administration objects
I have this html code that i want to edit with jQuery. Here is
I have this string: comment_1234 I want to extract the 1234 from the string.

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.