Setting Cell/Column DataType

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

Hello:

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?

Jeff.

Oct 9, 2009 at 5:57 PM

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

Cheers,

 

Andres

 

 

Oct 9, 2009 at 6:15 PM

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

From: aforozco [mailto:notifications@codeplex.com]
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

Cheers,

Andres

Read the full discussion online.

To add a post to this discussion, reply to this email (ExcelPackage@discussions.codeplex.com)

To start a new discussion for this project, email ExcelPackage@discussions.codeplex.com

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

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

Nov 27, 2009 at 2:15 PM

Hey...if all you're interested in is setting the Number Format, check out my solution in this thread: http://excelpackage.codeplex.com/Thread/View.aspx?ThreadId=50205

Clayton

Dec 4, 2009 at 3: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 3: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 2:47 PM

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