. Net Operations Excel Table

Source: Internet
Author: User

One,. From NuGet, reference the Microsoft.Office.Interop.Excel class library.

Method One, open a execl table and save it first

Application xApp =NULL; Workbook Xbook=NULL; Try            {                //1. Create a Applicaton objectXAPP =Newapplication (); Xapp.visible=true; Workbooks WBS=Xapp.workbooks; Workbook WB=WBS.                ADD (Missing.Value); Worksheet Xsheet= (Worksheet) WB. worksheets["Sheet1"]; Range R= Xsheet.get_range ("A1","N1"); Object[] Objheader =                {                    "Serial Number","User name","Phone number","whether to spend","Recharge Amount","Recharge Times","Purchase Service amount","number of services purchased","Purchase Copyright Amount","number of copyrights purchased","Voucher Amount",                    "Gift Amount","Total Amount","account Balance"                    }; introw =2;//the first line is the title                 for(inti =0; I < array. Length; i++)                {                    varstr =Array[i]; varList = Tjsonresult.deserializeobject<list<userinfoanalysisentity>>(str); foreach(varEntityinchlist) {                        if(Entity. Cost = ="is a") {XSheet.Cells.Font.ColorIndex=3; }                        Else{XSheet.Cells.Font.ColorIndex=1; } Xsheet.cells[row,1] =entity.                        Id; Xsheet.cells[row,2] =entity.                        UserName; Xsheet.cells[row,3] =entity.                        Phone; Xsheet.cells[row,4] =entity.                        cost; Xsheet.cells[row,5] =entity.                        Recharge; Xsheet.cells[row,6] =entity.                        Rechargenum; Xsheet.cells[row,7] =entity.                        Buyservices; Xsheet.cells[row,8] =entity.                        Buyservicesnum; Xsheet.cells[row,9] =entity.                        Buycopyright; Xsheet.cells[row,Ten] =entity.                        Buycopyrightnum; Xsheet.cells[row, One] =entity.                        Coupon; Xsheet.cells[row, A] =entity.                        Givemoney; Xsheet.cells[row, -] =entity.                        Totalmoney; Xsheet.cells[row, -] =entity.                        Balance; Row++;//represents a line number}                }

var filepath = AppDomain.CurrentDomain.BaseDirectory + "test123.xlsx";
Xsheet.saveas (filepath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);

More operations: https://www.cnblogs.com/junshijie/p/5292087.html

. Net Operations Excel Table

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.