"Web development" ☆★ using POI to manipulate Excel Table series tutorial "8" to set how cells are to be used

Source: Internet
Author: User


"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

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.