tags:

views:

1468

answers:

3

A colleague of mine has an XML document which she opens in Excel 2007, using "Get External Data / From XML Data Import".

Excel maps the XML to columns automatically. However, some elements store numerical data, which Excel refuses to treat as a number:

<SOME_NUMBER>68.12</SOME_NUMBER>

Instead, the cell shows the "number stored as text" error.

Currently no XML Schema is attached to the document, and I would want to avoid creating one, if possible. What other options are there?

P.S.: Trying different regional settings was unsuccessful. Data always seems to be viewed as text.

A: 

Well you can just select the cells, right click, format cells, Change the format type to "Number"

EDIT

Using this test XML File

<NODES>
<A>
   <B>1.23</B>
   <C>2.34</C>
   <D>3.45</D>
   <SOME_NUMBER>ASDF</SOME_NUMBER>
</A>
<A>
   <B>1.23</B>
   <C>2.34</C>
   <D>3.45</D>
   <SOME_NUMBER>4.56</SOME_NUMBER>
</A>
<A>
   <B>1.23</B>
   <C>2.34</C>
   <D>3.45</D>
   <SOME_NUMBER>4.56</SOME_NUMBER>
</A>
</NODES>

All columns appear as numbers with the exception of the second two SOME_NUMBER's because of the text in the initial column

So I select those two cells, high-light the error box (exclamation sign) and choose the second option "Convert To Number"

The format cells thing seems to be a bit stupid in that it won't apply the formatting to a cell with an error on it, until you click into the cell

Eoin Campbell
Manually correcting the error is possible, but not feasible. ;-) The file is rather large, and as I understand you'd have to do it separately for each cell. The file cannot have strings in numerical elements, it's database-generated. It will also not contain empty elements, only the value 0. I somehow still suspect regional settings/system locale to be involved in this whole thing...
Tomalak
A: 

I believe that the cell formatting by default applies for the whole column, so perhaps in your example some instances of store text or number but in quotas like "1.5" so the default text formatting.

When I tested the XML Data Import it would format all text columns to text, and numeric columns to general

kristof
Interestingly, if all (or at least the top n) contain a non-fractional number, or 0, then Excel correctly interprets the column as numeric. If a fractional value like "68.12" is contained (I'm in Germany, where this would be written as "68,12"), Excel starts to treat it as a string, showing the error. At least setting the user locale to U.S. English did not make a difference - I'll try changing the system locale.
Tomalak
Actually, this is untrue. I just found out Excel just does not display an error for the value "0". But the value is displayed as left-aligned, indicating that it is treated as a string.
Tomalak
A: 

I feel your pain, I've had the same problem for years. This is the only solution I've came up with.

Function ConvertText2Num(RangeToConvert As Range)
    RangeToConvert.ClearFormats
    RangeToConvert.TextToColumns
End Function