ASP. Npoi using

Source: Internet
Author: User

Hssfworkbook Hssfworkbook = new Hssfworkbook (); Add Excel
Npoi. Ss. Usermodel.isheet sheetname = Hssfworkbook. Createsheet (dr_subject["Subjectname"). ToString ());//Increase Sheet
Npoi. Ss. Usermodel.irow sheetrows = Sheetname.createrow (RowCount); Yes
Npoi. Ss. Usermodel.icell cell = Sheetrows.createcell (ColCount);//Column
Cell. Setcellvalue (dt_grade.rows[i]["Gradename"). ToString () + "scheduling");//value
Npoi. Ss. Util.cellrangeaddress cellrangeaddress = new Npoi. Ss. Util.cellrangeaddress (Rowstart, Rowend, Colstart, colend);//Merge cells
Sheet. Addmergedregion (cellrangeaddress);//Merge cells
Sheetrows.getcell (ColCount). CellStyle = CellStyle ()//Set style

Private Npoi. Ss. Usermodel.icellstyle CellStyle () {Npoi. Ss. Usermodel.icellstyle style = Hssfworkbook. Createcellstyle ();//The style of cell npoi. Ss. Usermodel.ifont font = Hssfworkbook. CreateFont ();//font fonts for cells.        FontName = "<span style= ' COLOR: #faebde ' > ' Arial ' </SPAN>"; Font.        Fontheightinpoints = 10; Font. Boldweight = (short) npoi. Ss.        UserModel.FontBoldWeight.BOLD; Style. SetFont (font);//The font style of the cell. Alignment = Npoi. Ss. usermodel.horizontalalignment.center;//horizontally centered style. VerticalAlignment = Npoi. Ss.        usermodel.verticalalignment.center;//Vertical Center Color levelonecolor = Color.FromArgb (255, 153, 0); Style. FillPattern = Npoi. Ss. usermodel.fillpatterntype.solid_foreground;//fills the style. Fillforegroundcolor = Getxlcolour (Hssfworkbook, Levelonecolor); Call the Getxlcolour method//have a border style. BorderBottom = Npoi. Ss.        UserModel.CellBorderType.THIN; Style. Borderleft = Npoi. Ss.        UserModel.CellBorderType.THIN; Style. BorderTop= Npoi. Ss.        UserModel.CellBorderType.THIN; Style. BorderRight = Npoi. Ss. UserModel.CellBorderType.THIN;
       Sheetname.setcolumnwidth (Col, 16 * 256);
        return style;    }


Prevent duplicate rows from being added

  for (int stcount = 0; Stcount < DT_WHF. Rows.Count; stcount++)    {               if (sheetname.getrow (Xh) = = null)//not created row condition       {           Rowst = Sheetname.createrow (Xh);//       }       Else       {           Rowst = Sheetname.getrow (Xh);//Create line case                 }       Xh = Xh + 1;       RowCount = RowCount + 1;       Studentsxuhao = stcount+1;       Npoi. Ss. Usermodel.icell Cellst_xuhao = Rowst.createcell (0);//Create add column here       cellst_xuhao.setcellvalue ( Studentsxuhao.tostring ());//Set the column value       npoi here. Ss. Usermodel.icell cellst = Rowst.createcell (ClassCount + 1);//Create add Column       Cellst.setcellvalue here (DT_WHF. rows[stcount]["Stname"]. ToString ());//Set column values here        }

  

ASP. Npoi using

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.