Write excel in Java org

Source: Internet
Author: User

Package com. csland. workflow. business;

Import org. Apache. Poi. hssf. usermodel. hssfworkbook;
Import org. Apache. Poi. hssf. usermodel. hssfsheet;
Import org. Apache. Poi. hssf. usermodel. hssfrow;
Import org. Apache. Poi. hssf. usermodel. hssfcell;
Import org. Apache. Poi. hssf. usermodel .*;
Import java. Io. fileoutputstream;

Public class ylexcel {
Public ylexcel (){

}

Private Static void createcelltitle (hssfworkbook WB, hssfrow row, int column,
String Value ){
Hssfcell cell = row. createcell (short) column );

Hssfcellstyle cellstyle = WB. createcellstyle ();
Cellstyle. setalignment (hssfcellstyle. align_center );

Hssffont font = WB. createfont ();
Font. setfontheightinpoints (short) 11 );;
Font. setfontname (" ");
Font. setboldweight (hssffont. boldweight_bold );

Cellstyle. setfont (font );

Cell. setcellstyle (cellstyle );

Cell. setcellvalue (value );

}

Private Static void createfile (string outputfile ){
Try {
// Create a new XL document
Hssfworkbook WB = new hssfworkbook ();
// Make a worksheet in the XL document created
Hssfsheet sheet = WB. createsheet ();
// Create row at index zero (top row)

Hssfrow ROW = sheet. createrow (short) 0 );
For (INT I = 0; I <10; I ++ ){
Createcelltitle (WB, row, I, "gisoracle" + I );

}

// The output file is where the XLS will be created
Fileoutputstream fout = new fileoutputstream (outputfile );
// Write the XL Sheet
WB. Write (fout );
Fout. Flush ();
// Done deal ..
Fout. Close ();
System. Out. println ("File Created ..");

}
Catch (exception e ){
System. Out. println ("!! Bang !! Xlcreate (): "+ E );
}
}

Public static void ylb (string ym ){
System. Out. println ("Poi ");
Createfile ("C:/test.xls ");
System. Out. println ("================ ");

}

}

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.