Setting Cell/Column DataType

Topics: Developer Forum, User Forum
Jul 27, 2009 at 3:13 PM


I need to set the DataType for a cell (or column) to "Text" so that i can place numerical data with leading '0's into the cell/column.  I downloaded the latest source and see that support exists for other data types but not "Text".  Is there a technique i can use to work around this issue?


Oct 9, 2009 at 6:57 PM

Hi Jeff, any luck with this yet? I'm having the same problem






Oct 9, 2009 at 7:15 PM

No.  I had to switch to the COM interface for Excel.

From: aforozco []
Sent: Friday, October 09, 2009 12:58 PM
To: Richard, Jeff
Subject: Re: Setting Cell/Column DataType [ExcelPackage:63636]

From: aforozco

Hi Jeff, any luck with this yet? I'm having the same problem



Read the full discussion online.

To add a post to this discussion, reply to this email (

To start a new discussion for this project, email

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at

Nov 27, 2009 at 3:15 PM

Hey...if all you're interested in is setting the Number Format, check out my solution in this thread:


Dec 4, 2009 at 4:57 PM

you can trick the 'Value' propery setter in the ExcelCell.cs file. it tests the given value to see if its a number or text. By doing that it ignores the leading zeros.

find the following line in the ExcelCell.cs:

if (IsNumericValue(value))

and replace with:

bool hasLeadingZeros = false;

if (!string.IsNullOrEmpty(value))
    hasLeadingZeros = value.StartsWith("0");

if (!hasLeadingZeros && IsNumericValue(value))

by doing that, it will treat all values starting with zero as text.


hope it helps

Oct 26, 2011 at 4:12 PM

Hello, I needed show numerics values like text then  I added a string empty (" ") at the end of my value.

i.e: xlPackage.Workbook.Worksheets[1].Cell(contRow, contCol).Value = "08 ";

Also, the cell (contRow, contCol) was formatted like Text.

And this work for me.

I hope this is useful for you.

Jan 16, 2012 at 3:47 PM

I am in same problem, please to set the CELL FORMAT?