A solution for automatically converting the ID card number to scientific notation when DataTable is exported to Excel

Source: Internet
Author: User

Have you ever encountered this problem during the project? I will share with you today that the answers I have found online are for the gridview control, in addition, the type of the ID card number column of the DataTable is string, and the type of the ID card number column is enclosed by single quotation marks. However, I have not tried it successfully. I don't know whether it is my character or not, but today, my entire solution perfectly avoids scientific notation.
1 DataTable dt = new DataTable ();
2 dt. Columns. Add (new DataColumn ("ID card number "));
3 DataRow dr = dt. NewRow ();
4 StringBuilder sb = new StringBuilder ("= \"");
5 sb. Append ("1234567890123456789"). Append ("\"");
6 dr [0] = sb. ToString ();
7 dt. Rows. Add (dr );
8 ImportAndExport. CreateExcel (dt, "1", "11.xls ");

Hey, it's easy enough! The principle is that Excel will automatically calculate the string formula = "1234567890123456789". If you do not believe this, create an Exel file.

 

From wlitsoft

Related Article

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.