Generate Excel files using the Apache "POI" framework

Source: Internet
Author: User

public static void Createbugfile (String fileName, String Bussinessno, String projectpath) throws Exception {

File Bugfile = new file (FileName + ". xls");

File File = new file (ProjectPath);

String[] titles = {"Code change description", "Owning subsystem", "Code path", "Modified person", "Business Number", "Remarks"};

Hssfworkbook workbook = new Hssfworkbook ();

Hssfsheet sheet = workbook.createsheet ("code import");

Hssfcellstyle Hssfcellstyle = Workbook.createcellstyle ();

Hssfcellstyle.setborderbottom (Hssfcellstyle.border_thin);

Hssfcellstyle.setbordertop (Hssfcellstyle.border_thin);

Hssfcellstyle.setborderleft (Hssfcellstyle.border_thin);

Hssfcellstyle.setborderright (Hssfcellstyle.border_thin);

Hssfcellstyle.setverticalalignment (Hssfcellstyle.align_left);

hssfcellstyle.setalignment (hssfcellstyle.align_center);

Hssfcellstyle.setrightbordercolor (Hssfcellstyle.border_thin);

Hssfcellstyle.setleftbordercolor (Hssfcellstyle.border_thin);

Hssfrow hssfrow = sheet.createrow (0);

for (int i = 0, j = titles.length; I < J; i++) {

Hssfcell Hssfcell = Hssfrow.createcell (i);

if (i = = 2) {

Sheet.setcolumnwidth (I, 10000);

} else {

Sheet.setcolumnwidth (i, 5000);

}

Hssfcell.setcellvalue (Titles[i].trim ());

Hssfcell.setcellstyle (Hssfcellstyle);

}

for (int i = 0; i < list.size (); i++) {

Hssfrow HssfRow2 = Sheet.createrow (i + 1);

for (int m = 0; m < 6; m++) {

Hssfcell Hssfcell = Hssfrow2.createcell (m);

if (M = = 0) {

Sheet.setcolumnwidth (M, 5000);

Hssfcell.setcellvalue (Codechangedesc.trim ());

} else if (m = = 1) {

Sheet.setcolumnwidth (M, 5000);

Hssfcell.setcellvalue (Childsys.trim ());

} else if (M = = 2) {

Sheet.setcolumnwidth (M, 10000);

Hssfcell.setcellvalue (List.get (i). toString (). Trim ());

} else if (m = = 3) {

Sheet.setcolumnwidth (M, 5000);

Hssfcell.setcellvalue (Updater.trim ());

} else if (m = = 4) {

Sheet.setcolumnwidth (M, 5000);

Hssfcell.setcellvalue (Bussinessno.trim ());

} else if (m = = 5) {

Sheet.setcolumnwidth (M, 5000);

Hssfcell.setcellvalue (Remark.trim ());

}

Sheet.setcolumnwidth (M, 5000);

Hssfcell.setcellstyle (Hssfcellstyle);

}

}

FileOutputStream FileOutputStream = new FileOutputStream (bugfile);

Workbook.write (FileOutputStream);

Fileoutputstream.close ();

}


This article is from the "Generation Guru" blog, please make sure to keep this source http://765682.blog.51cto.com/755682/1899573

Generate Excel files using the Apache "POI" framework

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.