Using npoi. SS. usermodel; using npoi. hssf. usermodel; // create execl iworkbook hssfworkbook = new hssfworkbook (); // create a sheet hssfworkbook. createsheet ("sheet1"); // filestream file = new filestream (@ "test.xls", filemode. create); hssfworkbook. write (File); file. close (); // to create a cell, you must first create the row where the cell is located. For example, the following code creates row 0th: isheet sheet1 = hssfworkbook. createsheet ("sheet1"); irow row1 = sheet1.createrow (0); // After the row is created, you can create a cell, for example, create a cell at the A1 position: row1.createcell (0 ). setcellvalue ("This is a sample"); // or sheet1.getrow (0 ). createcell (0 ). setcellvalue ("This is a sample"); // set header text to set the header s1.header. center = "this is a test sheet"; // set footer text to set the footer s1.footer. left = "Copyright npoi team"; s1.footer. right = "created by 123"; // set date format to set the cell format icellstyle cellstyle = hssfworkbook. createcellstyle (); idataformat format = hssfworkbook. createdataformat (); cellstyle. dataformat = format. getformat ("yyyy-mm-dd"); // cellstyle. dataformat = hssfdataformat. getbuiltinformat ("0.00"); the cell format is "0.00", "¥ #, #0" USD, and "0.00%" percentage shows cell. cellstyle = cellstyle; // merge cell irow ROW = sheet. createrow (0); icell cell = row. createcell (0); cell. setcellvalue ("Sales Report"); icellstyle style = hssfworkbook. createcellstyle (); style. alignment = horizontalalignment. center; ifont font = hssfworkbook. createfont (); font. fontheight = 20*20; style. setfont (font); cell. cellstyle = style; sheet. addmergedregion (new region (0, 0, 0, 5 ));
Npoi format setting 1