C # list to able

Source: Internet
Author: User

Recently, I was doing Excel export and found this method. Although it was not written by myself, it is worth adding to my favorites. But I forgot to extract it from it and did not write it to the original author. Sorry!

1 # region export Excel 2 /// <summary> 3 // list to convert able 4 /// </Summary> 5 /// <Param name = "reslist"> </param> 6 // <returns> </returns> 7 public datatable dataout (list <Excel> reslist) 8 {9 10 datatable tempdt = new datatable (); 11 system. reflection. propertyinfo [] P = reslist [0]. getType (). getproperties (); 12 foreach (system. reflection. propertyinfo PI in P) 13 {14 tempdt. columns. add (Pi. name); 15} 16 for (INT I = 0; I <reslist. count; I ++) 17 {18 arraylist templist = new arraylist (); 19 // write a record in ilist to arraylist20 foreach (system. reflection. propertyinfo PI in P) 21 {22 object oo = pi. getvalue (reslist [I], null); 23 templist. add (OO); 24} 25 26 object [] ITM = new object [p. length]; 27 // traverse the arraylist to put data 28 for (Int J = 0; j <templist. count; j ++) 29 {30 ITM. setvalue (templist [J], J); 31} 32 // put the content of object [] into ableable33 tempdt. loaddatarow (ITM, true); 34} 35 // return datatable36 return tempdt; 37}
View code

 

C # list to able

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.