format a cell to text when the content is a number

  • Thread starter Hans - DiaGraphIT -
  • Start date
H

Hans - DiaGraphIT -

Hi!

I wounder if this is the right place to ask my question.

In one cases following codeline works just fine:

((worksheet)excel.Application.WorkSheet[1].)get_Range ("K1",
"K327").NumberFormat = "0000000000000000"

But I wounder how can I format the range to text formula, also when I know
that the content is only numbers.

I'm programming a windows application with c# and extract statistics-data
from my database into an excel document.

Any help appreciates

Best regards
Hans Årsjö
 
C

Cindy M.

Hi =?Utf-8?B?SGFucyAtIERpYUdyYXBoSVQgLQ==?=,
I wounder if this is the right place to ask my question.
Sort of in-between :) Since you're programming in C#, it's the right place
to get help with VBA/C# issues. But the excel.programming newsgroup is the
best place to ask how Excel really works "on the inside". Unfortunately, the
folks there aren't .NET-friendly, as a rule...

See if the following command works the way you need in the user interface. If
it does, record the actions in a macro to get the basic Excel object model
syntax:

1. Open or create a worksheet with a column of data representative of the
kind you're concerned about

2. Select that range

3. Data/Text to columns

4. Move directly to Step 3 and set the data type to "Text" (it has probably
defaulted to "General")

This will format the cells' content as text *at the data level*. IOW, even if
you access the Excel file as a database, the column will be marked as text.
There are ways to format numbers as text at the cell level (Format/Cell), but
this does NOT carry down to the data level, which can cause problems if you
use OLE DB or ODBC to access the data.
In one cases following codeline works just fine:

((worksheet)excel.Application.WorkSheet[1].)get_Range ("K1",
"K327").NumberFormat = "0000000000000000"

But I wounder how can I format the range to text formula, also when I know
that the content is only numbers.

I'm programming a windows application with c# and extract statistics-data
from my database into an excel document.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top