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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:42:51+00:00 2026-05-25T18:42:51+00:00

We have an asp.net c# program that reads a sheet from an Excel file

  • 0

We have an asp.net c# program that reads a sheet from an Excel file and writes it out in a new sheet (also adding one column if data come from a Sql Server table).

Issue: in the new sheet the data is not formatted as we want. For example we want date without time and left-aligned, but they’re formatted with the time and right-aligned, etc.

How can we format an Excel cell?

This is our code:

newSheet = (Worksheet)sheets.Add(sheets[1], Type.Missing, Type.Missing, Type.Missing);
newSheet.Name = worksheetName;

for (int i = 0; i < headerList.Count; i++)
{
    newSheet.Cells[1, i + 1] = headerList[i];
    Range headerRange = newSheet.Cells[1, headerList.Count]; ;
    headerRange.Font.Bold = true;
}
for (int i = 0; i < listDrugOrder.Count; i++)
{
    DrugOrder drugorder = listDrugOrder[i];

    newSheet.Cells[i + 2, 1] = drugorder.RES_ID;
    newSheet.Cells[i + 2, 2] = drugorder.STATION;
    newSheet.Cells[i + 2, 3] = drugorder.DATE;
    newSheet.Cells[i + 2, 4] = drugorder.DRUG;
    newSheet.Cells[i + 2, 5] = drugorder.NDC;
    newSheet.Cells[i + 2, 6] = drugorder.UNITS_PER_DOSE;
    newSheet.Cells[i + 2, 7] = drugorder.FORM;
    newSheet.Cells[i + 2, 8] = drugorder.ROUTE;

    newSheet.Cells[i + 2, 10] = drugorder.FREQUENCY;
    newSheet.Cells[i + 2, 11] = drugorder.Heading_LAKE_ORDERS;
    newSheet.Cells[i + 2, 12] = drugorder.HOA;
    newSheet.Cells[i + 2, 13] = drugorder.INSTRUCTIONS;
    newSheet.Cells[i + 2, 14] = drugorder.DIAGNOSIS;
    newSheet.Cells[i + 2, 15] = drugorder.DIAGNOSIS_CODES;
    newSheet.Cells[i + 2, 16] = drugorder.MAR;
    newSheet.Cells[i + 2, 17] = drugorder.TAR;
    newSheet.Cells[i + 2, 18] = drugorder.DRUG_ALERT;
}

workbook.Save();
workbook.Close(null, null, null);
excelApp.Quit();
  • 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-25T18:42:52+00:00Added an answer on May 25, 2026 at 6:42 pm

    Just set the appropriate property on your cell (Range) objects.

    Set NumberFormat to control the cell number formatting, i.e.:

    newSheet.Cells[i, j].NumberFormat = "m/d/yyyy"
    

    Set HorizontalAlignment to control the alignment, i.e.:

    newSheet.Cells[i, j].HorizontalAlignment = ExcelAlignment.xlLeft; //or Excel.XlHAlign.xlHAlignLeft
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET program where i am downloading a file from web using
I have an ASP.NET web application which does the following: Reads an Excel file.
I have an ASP.NET web service that I can access via a windows program
I have an ASP.NET program that sends a confirmation email with the following code:
I have a ASP.NET program that works just fine but takes 10 seconds to
I have an ASP.NET program that is writing date to an SQLExpress Database date
Using C# ASP.NET I want to program a queue. I want to have X
I have asp.net form that contains fields. When I access this window, my javascript
We have an asp.net application that is able to create .air files. To do
I have an asp.net webpage that only contains a textbox and a button. 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.