Net Control Data to Excel format first, let's take a look at how Excel exports from the web page. When we send the data to the client, we want the Client Program (browser) to read it in Excel format, so we set the MIME type

Source: Internet
Author: User
. Net control data imported to Excel format
First, let's take a look at how Excel exports from a Web page. When we send the data to the client, we want the Client Program (browser) to read it in Excel format, so
Set the MIME type to application/vnd. MS-Excel. Data is displayed in the format of each cell when the Excel file is read.
Then, Excel displays the data of the cell in the default format. This provides us with a space for custom data formats. Of course, we must use the formats supported by Excel. Below
Common formats:
1) Text: VND. ms-excel.numberformat :@
2) Date: VND. ms-excel.numberformat: yyyy/mm/dd
3) number: VND. ms-excel.numberformat: #,## 0.00
4) Currency: VND. ms-excel.numberformat: ¥ #, #0.00
5) percentage: VND. ms-excel.numberformat: # 0.00%
You can also customize these formats. For example, you can define the year and month as YY-mm. So how can I add these formats to cells when I know these formats? It's easy. We just need to add the style
Add the corresponding tag pair (closed tag. For example, <TD> </TD>, add a style to the tag pair <TD> </TD>, as shown in
Below: <TD
Style = "Vnd. ms-excel.numberformat: @"> 410522198402161833 </TD>
Similarly, you can add a style to <div> </div> or <tr> <
/Tr>, <Table> </table> to add a style. When we add a style to both the parent and child tags, the data is displayed in a style.
What about it? After testing, it is displayed in the style closest to the data.
In Asp.net, The DataGrid data is exported to excel to prevent the numeric character format from becoming scientific count.

Write in itemdatabound event
'Modi by mingfei 20070712 prevents the ID card number from changing to a scientific count cell (4) as a numeric number when it is exported
If (E. Item. itemtype = listitemtype. item or E. Item. itemtype = listitemtype. alternatingitem) then
E. Item. cells (4). Attributes. Add ("style", "Vnd. ms-excel.numberformat :@")
End if

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.