Solved

Need to prevent numeric data from to default to print as number and print as text

Posted on 2008-06-24
5
524 Views
Last Modified: 2013-11-18
I am using a software called Navision 5.0 which can export data to Excel. The file that is activated is an XSLT file. The problem is that when the data is exported to Excel, all the numeric data that have zeros infront (Example Item No.: 01000) automatically change to 1000.

I do not have any experience with XML or XSLT but I was wondering if there is a way for me to change the logic so that all the numeric data are converted to text.  
<Style ss:ID="TextBoxNumber">
				<Alignment ss:Horizontal="Right" ss:Vertical="Bottom"/>
				<Font ss:FontName="Verdana" x:Family="Swiss"/>
				<NumberFormat ss:Format="Standard"/>
			</Style>
 
....
 
 
<xsl:attribute name="ss:StyleID">TextBoxNumber</xsl:attribute>

Open in new window

0
Comment
Question by:EngSiong
  • 3
5 Comments
 
LVL 10

Accepted Solution

by:
BobSiemens earned 300 total points
ID: 21857480
The problem is that excel thinks that that 01000 is a number.  In order to pevent that from happening, the exported data needs to look like text.  If you put double quotes around it, Excel will decide it's a string and won't delete the leading zero and won't display the quotes.

This is a sample of the XSL code that would do that:

&quot;<xsl:value-of select="PriceCode"/>&quot;

Your snippet doesn't seem to relate.  Your snippet is setting a CSS StyleID attribute.

Also, by the way, you can set the format of Excel cells so they display a fixed number of digits (with leading zeros).  Choose a custom format of 0000 for that column.
0
 
LVL 1

Author Comment

by:EngSiong
ID: 21862614
I am grateful for your suggestion. However, I do need to point out that there is only one generic stylesheet for Excel so there is no way for me target a column or even columns specifically. This is because the program will print the all the columns of data in Excel via the stylesheet. Moreover, all forms that can print the report will launch the same stylesheet preventing me from defaulting the format in the stylesheet. The only place I want to target is the data which I have narrowed the problem down to the variable TextBoxNumber.  

My snippet are not related because I am only targeting the code that is related to the variable TextBoxNumber.

Any other suggestions while I try to enter the quote marks around the variable?
0
 
LVL 1

Author Comment

by:EngSiong
ID: 21863644
Have some breakthrough on the XSLT code. I manage to change the code to NumberFormat ss:Format="@" The logic should work but I suspect the numbering logic is  
Code that I changed but does not affect the output.
			<Style ss:ID="TextBoxNumber">
				<Alignment ss:Horizontal="Right" ss:Vertical="Bottom" />
				<Font ss:FontName="Verdana" x:Family="Swiss"/>
				<NumberFormat ss:Format="@"/>
			</Style>
 
----
Code that I suspect is affecting the output 
			<Data>
				<xsl:choose>
					<xsl:when test="string(number(translate(@value,',.','11')))!='NaN'">
						<xsl:choose>
							<xsl:when test="contains(@value,'..')">
								<xsl:attribute name="ss:Type">String</xsl:attribute>
								<xsl:value-of select="@value"/>
							</xsl:when>
							<xsl:when test="@value = translate(@value,',.','')">
								<xsl:attribute name="ss:Type">Number</xsl:attribute>
								<xsl:value-of select="@value"/>
							</xsl:when>
              <xsl:when test="$DecimalSeparator = '.'">
                <xsl:attribute name="ss:Type">Number</xsl:attribute>
                <xsl:value-of select="translate(@value,',','')"/>
              </xsl:when>
              <xsl:when test="$DecimalSeparator = ','">
                <xsl:attribute name="ss:Type">Number</xsl:attribute>
                <xsl:value-of select="translate(translate(@value,'.',''),',','.')"/>
              </xsl:when>
              <xsl:otherwise>
								<xsl:attribute name="ss:Type">Number</xsl:attribute>
								<xsl:value-of select="translate(translate(@value,'.',''),',','.')"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="ss:Type">String</xsl:attribute>
						<xsl:value-of select="@value"/>
					</xsl:otherwise>
				</xsl:choose>
			</Data>

Open in new window

0
 
LVL 1

Author Comment

by:EngSiong
ID: 21863647
Sorry about the incomplete message.

What I meant was
Have some breakthrough on the XSLT code. I manage to change the code to NumberFormat ss:Format="@" The logic should work but I suspect the numbering logic is affected further down the code.
0
 
LVL 4

Assisted Solution

by:AndersHedegaard
AndersHedegaard earned 200 total points
ID: 21895625
When I look at an xslt definition from a Navision demo database I get the below. Try to set the Type="String" in you xslt file. That could be a solution.

<Cell ss:StyleID="formCaption">
      <Data ss:Type="String">
            <xsl:value-of select="//Object/@caption"/>
      </Data>
</Cell>
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question