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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:42:02+00:00 2026-05-13T11:42:02+00:00

I am losing the leading zeros when I copy values from a datatable to

  • 0

I am losing the leading zeros when I copy values from a datatable to an Excel sheet. That’s because probably Excel treats the values as a number instead of text.

I am copying the values like so:

myWorksheet.Cells[i + 2, j] = dtCustomers.Rows[i][j - 1].ToString();

How do I format a whole column or each cell as Text?

A related question, how to cast myWorksheet.Cells[i + 2, j] to show a style property in Intellisense?

  • 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-13T11:42:03+00:00Added an answer on May 13, 2026 at 11:42 am

    Below is some code to format columns A and C as text in SpreadsheetGear for .NET which has an API which is similar to Excel – except for the fact that SpreadsheetGear is frequently more strongly typed. It should not be too hard to figure out how to convert this to work with Excel / COM:

    IWorkbook workbook = Factory.GetWorkbook();
    IRange cells = workbook.Worksheets[0].Cells;
    // Format column A as text.
    cells["A:A"].NumberFormat = "@";
    // Set A2 to text with a leading '0'.
    cells["A2"].Value = "01234567890123456789";
    // Format column C as text (SpreadsheetGear uses 0 based indexes - Excel uses 1 based indexes).
    cells[0, 2].EntireColumn.NumberFormat = "@";
    // Set C3 to text with a leading '0'.
    cells[2, 2].Value = "01234567890123456789";
    workbook.SaveAs(@"c:\tmp\TextFormat.xlsx", FileFormat.OpenXMLWorkbook);
    

    Disclaimer: I own SpreadsheetGear LLC

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

Sidebar

Related Questions

I am attempting to store a variable length number that can have leading zeros
I just found out that my program is losing 5% execution speed when it
I seem to be losing a lot of precision with floats. For example I
I want to stop losing precious time when dealing with Linux/Unix's shell. If I
I need to resize jpg images with Python without losing the original image's EXIF
Is there any way to convert a bmp image to jpg/png without losing the
I am ASP.NET developer from last 5 years and still loving it. There are
OK, I'm losing my mind over this. I did read here at SO and
I'm running into a problem that I can't seem to solve. The code works
I have a large 1D dynamic array in my program that represents a FITS

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.