Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-24
5
Medium Priority
?
537 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 1200 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 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

972 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