Solved

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

Posted on 2008-06-24
5
527 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSL-FO - show results in 2 columns 5 32
c# code 19 72
Test ddwrt:UserLookup 1 67
Automating receiving uploaded files via HTTPS instead of SFTP 3 59
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 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