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