"Web development" ☆★ using POI to manipulate Excel Table series tutorial "8" to set how cells are to be used
Package Csg.xiaoye.poidemo;import Java.io.fileoutputstream;import Org.apache.poi.hssf.usermodel.HSSFCellStyle; Import Org.apache.poi.hssf.usermodel.hssfrichtextstring;import Org.apache.poi.hssf.usermodel.hssfworkbook;import Org.apache.poi.ss.usermodel.cell;import Org.apache.poi.ss.usermodel.cellstyle;import Org.apache.poi.ss.usermodel.row;import Org.apache.poi.ss.usermodel.sheet;import Org.apache.poi.ss.usermodel.workbook;public class Dspace {public static void main (string[] args) throws Exception { Workbook wb = new Hssfworkbook (); Define a new workbook Sheet Sheet = Wb.createsheet ("First Sheet page"); Create the first sheet page of row row = Sheet.createrow (2); Create a row row.setheightinpoints (30); Createcell (WB, Row, (short) 0, Hssfcellstyle.align_center, hssfcellstyle.vertical_bottom); Createcell (WB, Row, (short) 1, Hssfcellstyle.align_fill, hssfcellstyle.vertical_center); Createcell (WB, Row, (short) 2, Hssfcellstyle.align_left, Hssfcellstyle.vertical_top); Createcell (WB, Row, (short) 3, hssfcellstyle.align_right, hssfcellstyle.vertical_top); FileOutputStream fileout = new FileOutputStream ("d:\\ saya. xls"); Wb.write (fileout); Fileout.close (); }/** * Create a cell and set it to the specified way * * @param WB Workbook * @param row row * @param column column * @param halign horizontal side To its way * @param valign vertically toward it */private static void Createcell (Workbook wb, Row row, short column, Short halign, short valign) {cell cell = Row.createcell (column);//Create Cell cell.setcellvalue (new Hssfrichtex Tstring ("Xiaoye")); Set the value CellStyle CellStyle = Wb.createcellstyle (); Create cell style cellstyle.setalignment (halign); Sets the horizontal direction of the cell to its way cellstyle.setverticalalignment (valign); Sets the vertical direction of the cell to its way cell.setcellstyle (CellStyle); Set cell Style}}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/26/90/wKioL1NrfO6TFRJuAABuvjThQls181.jpg "title=" 1.png " alt= "Wkiol1nrfo6tfrjuaabuvjthqls181.jpg"/>
This article from "Promise always attached to the small wood 、、、" blog, please be sure to keep this source http://1936625305.blog.51cto.com/6410597/1408587