Link to home
Start Free TrialLog in
Avatar of CaseyRobertsTTU
CaseyRobertsTTU

asked on

opening datagrid to Excel - Excel is changing the format of a column to a number from a string

I have a datagrid that has a column which is a string identity field that is 19 characters long - all the characters values are numeric.  I'm exporting and opening the datagrid in Excel using a xslt file.  Excel changes the values from string to numeric and the result is a number who's last character is incorrect and and displays in scientific notation.

Datagrid Column Value: 4003000000009010001
What I see in the resulting worksheet in Excel: 4.003E+18
What i see in the data field at the top: 4003000000009010000

The line in the xslt file

<TD>
<xsl:value-of select="IDNUMBER" />
</TD>


How can I tell Excel not to convert this data?
ASKER CERTIFIED SOLUTION
Avatar of ctm5
ctm5

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CaseyRobertsTTU
CaseyRobertsTTU

ASKER

Thanks for the suggestion. I can't have an apostrophe showing up in the final spreadsheet.  I need a way to tell Excel, through code, not to convert the string to a number.  I was hoping to be able to specify an attribute in the xslt line.
You could try setting the numberformat of the column to "@" (in VB code).
It's not a number in my datagrid column.  It's a string value being written in XML to be opened by Excel.  Excel, based on the fact that all the characters are numbers, changes it for me.  I have no control of the users Excel program, just the file I'm creating.  I'd like to know how to explicitly declare a field as a string in XML or in the XSLT - without adding string characters to my data.

XML line is: <IDNUMBER>4003000000009010001</IDNUMBER>
Right, you have control of the file you are creating. Which is an Excel spreadsheet, right? So you can figure out (in code) what column it is that is a problem and set its format to "@" This is done in the VB code (which I assume you must resort to at some point, since you have posted this in the VB.NET forum). If you want to do it in XML or XSLT, you might try a different forum. (In your original question, you did not specify a solution must lie in the XML or XSLT.)

ctm5
Sorry, for the confusion.  I'm not writing an Excel file (.xls). The VB.Net program is taking the data from my datagrid columns and writing an XML file to be opened by Excel.  In the XML file the data is correct.  I need a way to write the XML file in such a way that Excel doesn't reformat the data when it opens it.

I have added this question to the XML area, but no response there yet.  

Thanks for your suggestions so far.  
I decided to use the apostrophe as a temporary solution until I can find the answer I need.  Thanks.