NET Npoi the simplest way to list< entities > Export Excel

Source: Internet
Author: User

It's just a temporary data guide. Convenient. The most basic method,
[HttpGet] [Route ("Exportenterprise")] public baseresponse exportenterprise () {Iworkbook workbook = new HSS Fworkbook (); Isheet sheet = workbook. Createsheet ("Onesheet"); IRow row0 = sheet. CreateRow (0); Row0. Createcell (0). Setcellvalue ("sequential number"); Row0. Createcell (1). Setcellvalue ("Enterprise Name"); Row0. Createcell (2). Setcellvalue ("Industry category"); Row0. Createcell (3). Setcellvalue ("Large category of Industry"); Row0. Createcell (4). Setcellvalue ("Business territory"); Row0. Createcell (5). Setcellvalue ("legal person"); Row0. Createcell (6). Setcellvalue ("Corporate Phone"); Row0. Createcell (7). Setcellvalue ("Legal person fixed"); Row0. Createcell (8). Setcellvalue ("Daily Contact"); Row0. Createcell (9). Setcellvalue ("Daily Contact phone"); Row0. Createcell (10). Setcellvalue ("Daily Contact phone"); Row0. Createcell (11). Setcellvalue ("safe person"); Row0. Createcell (12). Setcellvalue ("Safe Person mobile"); Row0. Createcell (13). Setcellvalue ("Security person phone"); Row0. Createcell (14). Setcellvalue ("Production person"); Row0. Createcell (15). Setcellvalue ("Production person mobile phone"); Row0. Createcell (16). Setcellvalue ("Production person phone"); Row0. Createcell (17). Setcellvalue ("technical person"); Row0. Createcell (18). Setcellvalue ("Technical Person mobile"); Row0. Createcell (19). Setcellvalue ("Technical person phone"); Row0. Createcell (20). Setcellvalue ("Integrated person"); Row0. Createcell (21). Setcellvalue ("Integrated person phone"); var enterprises = _enterpriseservice.getenterprisesoftest (). ToList (); var Lineno = 1; foreach (var enterprise in enterprises) {IRow row = sheet. CreateRow (Lineno); Row. Createcell (0). Setcellvalue (Lineno); Row. Createcell (1). Setcellvalue (Enterprise. Enterprisename); var doordescr = _industrycategoryservice.getdescriptionby (Enterprise. Industrycategorycode); Row. Createcell (2). Setcellvalue (DOORDESCR); var industrygeneradescr = _industrycategoryservice.Getdescriptionby (Enterprise. Industrygeneracode); Row. Createcell (3). Setcellvalue (INDUSTRYGENERADESCR); Row. Createcell (4). Setcellvalue (_administrativedivisionservice.getdescriptionby (Enterprise. Businessaddressdivisoncode)); Row. Createcell (5). Setcellvalue (Enterprise. Legalpersonname); Row. Createcell (6). Setcellvalue (Enterprise. Legalpersonphone); Row. Createcell (7). Setcellvalue (Enterprise. Legalpersonfixedphone); Row. Createcell (8). Setcellvalue (Enterprise. Dailycontacts); Row. Createcell (9). Setcellvalue (Enterprise. Dailycontactsphone); Row. Createcell (10). Setcellvalue (Enterprise. Dailycontactsfixedphone); Row. Createcell (11). Setcellvalue (Enterprise. Safetyorganizationmanagername); Row. Createcell (12). Setcellvalue (Enterprise. Safetyorganizationmanagerphone); Row. Createcell (13). Setcellvalue (Enterprise. Safetyorganizationmanagerfox); Row. Createcell (14). Setcellvalue (Enterprise. Productionmanagername); Row. Createcell (15). Setcellvalue (Enterprise. Productionmanagerphone); Row. Createcell (16). Setcellvalue (Enterprise. Productionmanagerfixedphone); Row. Createcell (17). Setcellvalue (Enterprise.informationtechnologyprincipal); Row. Createcell (18). Setcellvalue (Enterprise.informationtechnologyprincipalphone); Row. Createcell (19). Setcellvalue (Enterprise.informationtechnologyprincipallandlinetelephone); var contact = string. Empty; var contactphone = string. Empty; if (!string. IsNullOrEmpty (Enterprise. Legalpersonname)) {contact = enterprise. Legalpersonname; if (!string. IsNullOrEmpty (Enterprise. Legalpersonphone)) {Contactphone = enterprise. Legalpersonphone; } else { Contactphone = enterprise. Legalpersonfixedphone; }}else if (!string. IsNullOrEmpty (Enterprise. dailycontacts)) {contact = enterprise. dailycontacts; if (!string. IsNullOrEmpty (Enterprise. Dailycontactsphone)) {Contactphone = enterprise. Dailycontactsphone; } else {contactphone = enterprise. Dailycontactsfixedphone; }} else if (!string. IsNullOrEmpty (Enterprise. Safetyorganizationmanagername)) {contact = enterprise. Safetyorganizationmanagername; if (!string. IsNullOrEmpty (Enterprise. Safetyorganizationmanagerphone)) {Contactphone = enterprise. Safetyorganizationmanagerphone; } else {Contactphone = enterprise. Safetyorganizationmanagerphone; }} else if (!string. IsNullOrEmpty (Enterprise. Productionmanagername)) {contact = enterprise. Productionmanagername; if (!string. IsNullOrEmpty (Enterprise. Productionmanagerphone)) {Contactphone = enterprise. Productionmanagerfixedphone; } else {contactphone = enterprise. Dailycontactsfixedphone; }} if (!string. IsNullOrEmpty (Enterprise. Informationtechnologyprincipal)) {contact = enterprise. Informationtechnologyprincipal; if (!string. IsNullOrEmpty (Enterprise. Informationtechnologyprincipalphone)) {Contactphone = enterprise. InformAtiontechnologyprincipalphone; } else {contactphone = enterprise. Informationtechnologyprincipallandlinetelephone; }} row. Createcell (20). Setcellvalue (contact); Row. Createcell (21). Setcellvalue (Contactphone); lineno++; }//Create a Stream object and set the path of the stored Excel file using (FileStream URL = new FileStream (HttpContext.Current.Server.MapPath (" /app_data/test.xls "), FileMode.OpenOrCreate, FileAccess.ReadWrite) {//export Excel file Workbook. Write (URL); }; Return Success (New Baseresponse ()); }

  

NET Npoi the simplest way to list< entities > Export Excel

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.