View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
zhaounknown zhaounknown is offline
external usenet poster
 
Posts: 1
Default How to set the format of cells after importing into Excel

I got the answer.
Set the Value2 property by a 2D array of objects, instead of a 2D array of
strings.


"Alok" wrote:

Like this
Worksheet.Range("A1:A20").NumberFormat = "0.00"

However, if setting the format in Excel itself is not having an effect on
the data you have imported into excel then the above approach will not work.
One method to fix the problem when numbers are not treated as numbers is to
programmatically do the equivalent of Copy and PasteSpecial and using the add
option to add 0(zeor). However since your range - the range you import -
consists of both numbers, text etc, I am not sure what effect this will have
unless you can identify the ranges that are specifically numbers and apply
the above method only on them.

Alok


"zhaounknown" wrote:

I have an 2D array of data, and import into Excel by using
Range.Values2=2DArray (C#).

The problem is:

some data are number, some data are datetime, some data are text, but all
the data in the resulting excel file is treated to be text. That is, data
seems to be number in a cell, but it is not actually.

Furthermore, it can't be reformted by using Excel's menu: Format Cells,
unless you reenter the data manually. The data will be taken as number.

My question is, how can I programmingly set the format of a range. (Not of a
cell).

Thanks.