ASP sets the Excel cell type to text

Source: Internet
Author: User

<Style>
. Xlstext {MSO-style-parent: style0; MSO-number-format: "\ @";}/* set the cell type to text */
</Style>
<%
Response. contenttype = "application/vnd. MS-excel" 'sets the webpage output type to excel.
%>

<Table>

<Tr>
<TD> Field 1 </TD>
<TD> Field 2 </TD>
<TD> Field 3 </TD>
<TD> Field 4 </TD>
</Tr>
<Tr>
<TD class = "xlstext"> <% = value of Field 1%> </TD> <! -- The cell is in text format -->
<TD class = "xlstext"> <% = value of Field 2%> </TD> <! -- The cell is in text format -->
<TD> <% = value of Field 3%> </TD>
<TD> <% = value of field 4%> </TD>
</Tr>

</Table>

MSO-number-format: "0" No Decimals
MSO-number-format: "0 \. 000" 3 Decimals
MSO-number-format: "\#\,\#\# 0 \. 000" comma with 3 Dec
MSO-number-format: "mm \/DD \/YY" date7
MSO-number-format: "Mmmm \ D \, \ YYYY" date9
MSO-number-format: "m \/d \/yy \ H \: mm \ am \/PM" D-T ampm
MSO-number-format: "short date" 01/03/1998
MSO-number-format: "Medium date" 01-Mar-98
MSO-number-format: "d \-Mmm \-YYYY" 01-Mar-1998
MSO-number-format: "Short Time" 5: 16
MSO-number-format: "medium time" 5:16 AM
MSO-number-format: "Long time" 5: 16: 21: 00
MSO-number-format: "percent" percent-two decimals
MSO-number-format: "0%" percent-No Decimals
MSO-number-format: "0 \. e + 00" scientific notation
MSO-number-format: "\ @" Text
MSO-number-format :"\#\??? \/??? "Fractions-up to 3 digits (312/943)
MSO-number-format: "\ 0022 & pound; \ 0022 \#\,#\# 0 \. 00" & pound; 12.76
MSO-number-format: "\#\,\#\# 0 \. 00 _ \; \-\ # \, # \ #0 \. 00 \ "2 decimals, negative numbers in red and signed
(1.56-1.56)

Example:

When <% @ page contenttype = "application/vnd. MS-Excel; charset = UTF-8 "%> when exporting JSP files to excel, if the exported data contains numbers starting with 0, the 0 will be omitted, to keep the first 0, you can add:

Style = 'mso-number-format :"\@";'

In this case, the number with the first digit 0 in the exported table will be retained!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.