Solved

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

Posted on 2008-06-24
5
528 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

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.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 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