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