List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet autoSizeColumn
@Override public void autoSizeColumn(int column, boolean useMergedCells)
This process can be relatively slow on large sheets, so this should normally only be called once per column, at the end of your processing.
You can specify whether the content of merged cells should be considered or ignored.
From source file:kr.co.blackducksoftware.rg.displayexcel.Ex.java
License:Open Source License
@SuppressWarnings("unchecked") public static void srcPr(HSSFSheet srcSheet) { LogMaker.makelog("prepare to Print ID File info to Excel sheet"); //category // w w w. j a v a 2 s . c o m String[] strCategory = new String[FileVals.category.size()]; FileVals.category.toArray(strCategory); String[] strFPath = new String[FileVals.fPath.size()]; FileVals.fPath.toArray(strFPath); String[] strDType = new String[FileVals.dtype.size()]; FileVals.dtype.toArray(strDType); String[] strFileFolder = new String[FileVals.file.size()]; FileVals.file.toArray(strFileFolder); String[] strComponent = new String[FileVals.component.size()]; FileVals.component.toArray(strComponent); String[] strLicense = new String[FileVals.license.size()]; FileVals.license.toArray(strLicense); String[] strVersion = new String[FileVals.version.size()]; FileVals.version.toArray(strVersion); //matched files String[] strOSSFname = new String[FileVals.OSSFname.size()]; FileVals.OSSFname.toArray(strOSSFname); String[] strPercent = new String[FileVals.matchedRatio.size()]; FileVals.matchedRatio.toArray(strPercent); //OSS matched file line String[] strOSSFLine = new String[FileVals.OSSFLine.size()]; FileVals.OSSFLine.toArray(strOSSFLine); //Dev Matched First Line String[] strFirstLine = new String[FileVals.firstLine.size()]; FileVals.firstLine.toArray(strFirstLine); //matched total line String[] strTotalLine = new String[FileVals.tline.size()]; FileVals.tline.toArray(strTotalLine); //identified date String[] strIdentifiedDate = new String[FileVals.identifiedDate.size()]; FileVals.identifiedDate.toArray(strIdentifiedDate); //identifier String[] strIdentifier = new String[FileVals.identifier.size()]; FileVals.identifier.toArray(strIdentifier); String[] strComment = new String[FileVals.comment.size()]; FileVals.comment.toArray(strComment); int partialCount = Count.partialCount; //int partialCount=0; LogMaker.makelog("Printing File Info to excel"); for (int i = 0; i < strDType.length; i++) { //HSSFRow tempRow = srcSheet.createRow(i+2+iCount-(lineCount-1));//??? HSSFRow tempRow = srcSheet.createRow(i + 2 + Count.partialCount);//??? partialCount++; tempRow.setHeight((short) 500); String a = (strFileFolder[i].substring(1)); // category print int c = 0; try { tempRow.createCell(c).setCellValue(a.substring(0, a.indexOf("/"))); //if (strCate.equals(a.substring(0,a.indexOf("/")))){} } catch (Exception e) { tempRow.createCell(c).setCellValue(a); } tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; tempRow.createCell(c).setCellValue(a); tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //Identification type print tempRow.createCell(c).setCellValue(strDType[i]); tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; tempRow.createCell(c).setCellValue(strComponent[i]); tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //License Print tempRow.createCell(c).setCellValue(strLicense[i]); tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //version Print tempRow.createCell(c).setCellValue(strVersion[i]); tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //OSS matched Files;OSS matched Filename; print try { tempRow.createCell(c).setCellValue(strOSSFname[i]); } catch (Exception e) { tempRow.createCell(c).setCellValue(""); } tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //matched percent print; if (strPercent[i] == "" || strPercent[i] == null) { tempRow.createCell(c).setCellValue("100%"); } else { tempRow.createCell(c).setCellValue(strPercent[i] + "%"); } tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //OSS file line print try { tempRow.createCell(c).setCellValue(strOSSFLine[i]); } catch (Exception e) { tempRow.createCell(c).setCellValue(""); } tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //Dev Matched First Line print try { tempRow.createCell(c).setCellValue(strFirstLine[i]); } catch (Exception e) { tempRow.createCell(c).setCellValue(""); } tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //Dev Matched Total Line print try { tempRow.createCell(c).setCellValue(strTotalLine[i]); } catch (Exception e) { tempRow.createCell(c).setCellValue(""); } tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //Identified Date; identifieddate; try { tempRow.createCell(c).setCellValue(strIdentifiedDate[i]); } catch (Exception e) { tempRow.createCell(c).setCellValue(""); } //tempRow.createCell(c).setCellValue(strIdentifiedDate[i]); tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //Identifier print try { tempRow.createCell(c).setCellValue(strIdentifier[i]); } catch (Exception e) { tempRow.createCell(c).setCellValue(""); } tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //Comment print tempRow.createCell(c).setCellValue(strComment[i]); tempRow.getCell(c).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) c, true); c++; //other empty cell for (int temp = c; temp < 21; temp++) { tempRow.createCell(temp).setCellValue(""); tempRow.getCell(temp).setCellStyle(Style.componentCellStyle); //srcSheet.autoSizeColumn((short) c, true); if (temp == 16) { //CellRangeAddressList(startRow, endRow, startCol, endCol) CellRangeAddressList addressList = new CellRangeAddressList(i + 2, i + 2, temp, temp); DVConstraint dvConstraint = DVConstraint .createExplicitListConstraint(new String[] { "A", "B" }); DataValidation dataValidation = new HSSFDataValidation(addressList, dvConstraint); dataValidation.setSuppressDropDownArrow(false); srcSheet.addValidationData(dataValidation); } if (temp == 15) { //CellRangeAddressList(startRow, endRow, startCol, endCol) CellRangeAddressList addressList = new CellRangeAddressList(i + 2, i + 2, temp, temp); DVConstraint dvConstraint = DVConstraint .createExplicitListConstraint(new String[] { "A", "B", "C", "D", "E" }); DataValidation dataValidation = new HSSFDataValidation(addressList, dvConstraint); dataValidation.setSuppressDropDownArrow(false); srcSheet.addValidationData(dataValidation); } //c++; } //tempRow.createCell(3).setCellValue(strComponent[i]+" (+"+(compCount-1)+")"); tempRow.createCell(3).setCellValue(strComponent[i] + " (+0)"); tempRow.getCell(3).setCellStyle(Style.componentCellStyle); srcSheet.autoSizeColumn((short) 3, true); FileVals.clearAllArrayList(); } Count.partialCount = partialCount; }
From source file:kr.co.blackducksoftware.rg.displayexcel.Ex.java
License:Open Source License
public static void cover(HSSFWorkbook wb) { LogMaker.makelog("Making Cover sheet"); HSSFSheet sheet = wb.createSheet("Cover");// ??????? for (int iRowNum = 0; iRowNum < 1; iRowNum++) {///////1?? HSSFRow row = sheet.createRow(iRowNum); int iCol = 2; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Date "); row.getCell(iCol).setCellStyle(Style.dateCellStyle); sheet.autoSizeColumn((short) iCol, true); iCol++;/*from w ww.j a v a 2 s. c o m*/ row.createCell(iCol); row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(" "); row.getCell(iCol).setCellStyle(Style.leftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Doc. No. "); row.getCell(iCol).setCellStyle(Style.componentCellStyle); sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Version"); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol); row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(" "); row.getCell(iCol).setCellStyle(Style.leftOpenMediumRightCellStyle); //sheet.autoSizeColumn((short) iCol, true); } for (int iRowNum = 1; iRowNum < 2; iRowNum++) {//2?? HSSFRow row = sheet.createRow(iRowNum); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(" EXAMPLE "); row.getCell(iCol).setCellStyle(Style.exampleCellStyle); sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(" "); row.getCell(iCol).setCellStyle(Style.exbCellStyle); iCol++; row.createCell(iCol); row.getCell(iCol).setCellStyle(Style.dateCellStyle); iCol++; row.createCell(iCol); row.getCell(iCol).setCellStyle(Style.leftOpenCellStyle); iCol++; row.createCell(iCol); row.getCell(iCol).setCellStyle(Style.componentCellStyle); iCol++; row.createCell(iCol); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); iCol++; row.createCell(iCol); row.getCell(iCol).setCellStyle(Style.leftOpenMediumRightCellStyle); iCol++; } for (int iRowNum = 2; iRowNum < 3; iRowNum++) {//3?? HSSFRow row = sheet.createRow(iRowNum); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Organization"); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.leftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Author"); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.leftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Reviewer"); row.getCell(iCol).setCellStyle(Style.componentCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Approver"); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.leftOpenMediumRightCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } for (int iRowNum = 3; iRowNum < 4; iRowNum++) {//4th row HSSFRow row = sheet.createRow(iRowNum); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); row.setHeight((short) 500); iCol++; row.createCell(iCol); row.getCell(iCol).setCellStyle(Style.leftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.leftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.componentCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.leftOpenMediumRightCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } for (int iRowNum = 4; iRowNum < 5; iRowNum++) {//5th row HSSFRow row = sheet.createRow(iRowNum); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Project"); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.leftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Title"); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.LROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.LROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.LROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.leftOpenMediumRightCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } for (int iRowNum = 5; iRowNum < 6; iRowNum++) {//6th row HSSFRow row = sheet.createRow(iRowNum); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BRightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); row.setHeight((short) 500); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLeftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BRightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLeftOpenMediumRightCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } //////////////////////////example end for (int iRowNum = 7; iRowNum < 8; iRowNum++) {//8th row HSSFRow row = sheet.createRow(iRowNum); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Project Information"); row.getCell(iCol).setCellStyle(Style.projectInformationCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } for (int iRowNum = 8; iRowNum < 9; iRowNum++) {//9th row HSSFRow row = sheet.createRow(iRowNum); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.TLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.TLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); row.setHeight((short) 400); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.TLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.TLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.TleftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.TrightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.TleftOpenMediumRightCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } for (int iRowNum = 9; iRowNum < 18; iRowNum++) {//10-18th row HSSFRow row = sheet.createRow(iRowNum); row.setHeight((short) 350); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.LROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.LROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.LROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.LROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.leftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.rightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.leftOpenMediumRightCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } for (int iRowNum = 18; iRowNum < 19; iRowNum++) {//19th row HSSFRow row = sheet.createRow(iRowNum); row.setHeight((short) 350); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLROpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLeftOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BRightOpenCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.BLeftOpenMediumRightCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } for (int iRowNum = 20; iRowNum < 21; iRowNum++) {//21th row HSSFRow row = sheet.createRow(iRowNum); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Change History"); row.getCell(iCol).setCellStyle(Style.CHCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } for (int iRowNum = 21; iRowNum < 22; iRowNum++) {//22th row HSSFRow row = sheet.createRow(iRowNum); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Version"); row.getCell(iCol).setCellStyle(Style.greyCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Date"); row.getCell(iCol).setCellStyle(Style.greyCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Description"); row.getCell(iCol).setCellStyle(Style.greyCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.greyCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.greyCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("Author"); row.getCell(iCol).setCellStyle(Style.greyCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue("OSS Notice Version"); row.getCell(iCol).setCellStyle(Style.greyCellStyle); sheet.autoSizeColumn((short) iCol, true); iCol++; } for (int iRowNum = 22; iRowNum < 44; iRowNum++) {//23-44th row HSSFRow row = sheet.createRow(iRowNum); row.setHeight((short) 400); int iCol = 0; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.componentCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.componentCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.componentCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.componentCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.componentCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.componentCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; row.createCell(iCol, HSSFCell.CELL_TYPE_STRING).setCellValue(""); row.getCell(iCol).setCellStyle(Style.componentCellStyle); //sheet.autoSizeColumn((short) iCol, true); iCol++; } //////////merge cell //?????? sheet.AddMergedRegion(int ????row, short ????col,int ????row, short ????col); //example sheet.addMergedRegion(new Region(1, (short) 0, 1, (short) 1)); sheet.addMergedRegion(new Region(0, (short) 2, 0, (short) 3)); sheet.addMergedRegion(new Region(0, (short) 5, 0, (short) 6)); sheet.addMergedRegion(new Region(1, (short) 2, 1, (short) 3)); sheet.addMergedRegion(new Region(1, (short) 5, 1, (short) 6)); sheet.addMergedRegion(new Region(2, (short) 0, 2, (short) 1)); sheet.addMergedRegion(new Region(2, (short) 2, 2, (short) 3)); sheet.addMergedRegion(new Region(2, (short) 5, 2, (short) 6)); sheet.addMergedRegion(new Region(3, (short) 5, 3, (short) 6)); sheet.addMergedRegion(new Region(3, (short) 0, 3, (short) 1)); sheet.addMergedRegion(new Region(3, (short) 2, 3, (short) 3)); sheet.addMergedRegion(new Region(4, (short) 0, 4, (short) 1)); sheet.addMergedRegion(new Region(4, (short) 2, 4, (short) 6)); sheet.addMergedRegion(new Region(5, (short) 0, 5, (short) 1)); sheet.addMergedRegion(new Region(5, (short) 2, 5, (short) 6)); //project information sheet.addMergedRegion(new Region(8, (short) 0, 8, (short) 4)); sheet.addMergedRegion(new Region(8, (short) 5, 8, (short) 6)); sheet.addMergedRegion(new Region(9, (short) 0, 9, (short) 4)); sheet.addMergedRegion(new Region(9, (short) 5, 9, (short) 6)); sheet.addMergedRegion(new Region(10, (short) 0, 10, (short) 4)); sheet.addMergedRegion(new Region(10, (short) 5, 10, (short) 6)); sheet.addMergedRegion(new Region(11, (short) 0, 11, (short) 4)); sheet.addMergedRegion(new Region(11, (short) 5, 11, (short) 6)); sheet.addMergedRegion(new Region(12, (short) 0, 12, (short) 4)); sheet.addMergedRegion(new Region(12, (short) 5, 12, (short) 6)); sheet.addMergedRegion(new Region(13, (short) 0, 13, (short) 4)); sheet.addMergedRegion(new Region(13, (short) 5, 13, (short) 6)); sheet.addMergedRegion(new Region(14, (short) 0, 14, (short) 4)); sheet.addMergedRegion(new Region(14, (short) 5, 14, (short) 6)); sheet.addMergedRegion(new Region(15, (short) 0, 15, (short) 4)); sheet.addMergedRegion(new Region(15, (short) 5, 15, (short) 6)); sheet.addMergedRegion(new Region(16, (short) 0, 16, (short) 4)); sheet.addMergedRegion(new Region(16, (short) 5, 16, (short) 6)); sheet.addMergedRegion(new Region(17, (short) 0, 17, (short) 4)); sheet.addMergedRegion(new Region(17, (short) 5, 17, (short) 6)); sheet.addMergedRegion(new Region(18, (short) 0, 18, (short) 4)); sheet.addMergedRegion(new Region(18, (short) 5, 18, (short) 6)); //change history for (int i = 21; i < 44; i++) { sheet.addMergedRegion(new Region(i, (short) 2, i, (short) 4)); } }
From source file:kr.co.blackducksoftware.rg.displayexcel.Ex.java
License:Open Source License
/** * "src_Project_Name" //from www. jav a2 s .c o m * */ public static void src(HSSFWorkbook wb, String projectName) { LogMaker.makelog("Making sheet for Project ID Files"); HSSFSheet sheet; projectName = SCharRemover.StringReplace(projectName, false); int pCount = 0; sheet = wb.createSheet("SRC_" + projectName); Count.sheet = sheet; ArrayList<String> Header = new ArrayList<String>(); for (int rowNum = 0; rowNum < 1; rowNum++) { HSSFRow row = sheet.createRow(0); row.setHeight((short) 500); int i = 0; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Description"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(14, HSSFCell.CELL_TYPE_STRING).setCellValue("1st Review (Development Team)"); row.getCell(14).setCellStyle(Style.fReviewCellStyle); i++; row.createCell(19, HSSFCell.CELL_TYPE_STRING).setCellValue("Final Review"); row.getCell(19).setCellStyle(Style.finalReviewCellStyle); i++; } sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) 13)); sheet.addMergedRegion(new Region(0, (short) 14, 0, (short) 18)); sheet.addMergedRegion(new Region(0, (short) 19, 0, (short) 20)); Header.clear(); Header.add("Category"); Header.add("File Path"); Header.add("Identification Type"); Header.add("Component"); Header.add("License"); Header.add("Version"); Header.add("OSS: Matched Files"); Header.add("%"); Header.add("OSS: Matched File Line"); Header.add("Dev.: Matched First Line"); Header.add("Dev.: Matched Total Line"); Header.add("Identified Date"); Header.add("Identifier"); Header.add("Comments"); HSSFRow row = sheet.createRow(1); row.setHeight((short) 500); src2ndrow(sheet, Header, 0, row, 14, 19); Header.clear(); Header.add(" Person In Charge "); Header.add(" Linkage Type "); Header.add(" A or B "); Header.add(" Reviewer's Comments "); Header.add(" Counterplan "); src2ndrow(sheet, Header, 14, row, 14, 19);// 0?? ???? ??????? Header.clear(); Header.add(" Final Review Date "); Header.add(" Reviewer's Comments "); src2ndrow(sheet, Header, 19, row, 14, 19); for (int i = 14; i < 21; i++) { sheet.autoSizeColumn(i, true); } }
From source file:kr.co.blackducksoftware.rg.displayexcel.Ex.java
License:Open Source License
/** * "Build Image Analysis" //from w w w . j a v a2 s.com * * */ public static void lineHeader(HSSFSheet sheet, int iRowNum, ArrayList<String> al) { LogMaker.makelog("Creating Header Info"); HSSFRow row = sheet.createRow(0); row.setHeight((short) 500); int i = 0; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Description"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("a a"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Deion"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Description"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Dion"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis D escription"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(6, HSSFCell.CELL_TYPE_STRING).setCellValue("1st Review (Development Team)"); row.getCell(6).setCellStyle(Style.fReviewCellStyle); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Don"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Descrition"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(9, HSSFCell.CELL_TYPE_STRING).setCellValue("Final Review "); row.getCell(9).setCellStyle(Style.finalReviewCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Description"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; }
From source file:kr.co.blackducksoftware.rg.displayexcel.Ex.java
License:Open Source License
/** * "Build Image Analysis" /*from w w w. jav a 2s . com*/ * * */ public static void BIA(HSSFWorkbook wb) { LogMaker.makelog("Making BIA sheet"); HSSFSheet sheetBIA = wb.createSheet("Build Image Analysis");// ??????? ArrayList<String> Header = new ArrayList<String>(); Header.add("Analysis Description"); Header.add("1st Reviewer (Development Team)"); Header.add("Final Revewer"); lineHeader(sheetBIA, 0, Header);// 0?? ???? ??????? sheetBIA.addMergedRegion(new Region(0, (short) 0, 0, (short) 5)); sheetBIA.addMergedRegion(new Region(0, (short) 6, 0, (short) 8)); sheetBIA.addMergedRegion(new Region(0, (short) 9, 0, (short) 10)); Header.clear(); HSSFRow row = sheetBIA.createRow(1); //row ???? row.setHeight((short) 500); Header.add("Binary File Path"); Header.add(" "); Header.add("Component"); Header.add("License");//drop down Header.add("Analyzer"); Header.add("Analyzer's Comments"); src2ndrow(sheetBIA, Header, 0, row, 6, 9); Header.clear(); sheetBIA.addMergedRegion(new Region(1, (short) 0, 1, (short) 1)); Header.add("Person In Charge"); Header.add("A or B");//drop down Header.add("Reviewer's Ccomments"); src2ndrow(sheetBIA, Header, 6, row, 6, 9);// 0?? ???? ??????? sheetBIA.autoSizeColumn((short) 6, true); sheetBIA.autoSizeColumn((short) 8, true); Header.clear(); Header.add("Review Date"); Header.add("Reviewer's Comments"); src2ndrow(sheetBIA, Header, 9, row, 6, 9);// 0?? ???? ??????? Header.clear(); for (int i = 2; i < 200; i++) { HSSFRow row2 = sheetBIA.createRow(i); row2.setHeight((short) 500); for (int j = 0; j < 11; j++) { row2.createCell(j, HSSFCell.CELL_TYPE_STRING).setCellValue(" "); row2.getCell(j).setCellStyle(Style.componentCellStyle); if (j == 3) { CellRangeAddressList addressList = new CellRangeAddressList(i, i, j, j); DVConstraint dvConstraint = DVConstraint .createExplicitListConstraint(new String[] { "A", "B" }); DataValidation dataValidation = new HSSFDataValidation(addressList, dvConstraint); dataValidation.setSuppressDropDownArrow(false); sheetBIA.addValidationData(dataValidation); } if (j == 7) { CellRangeAddressList addressList = new CellRangeAddressList(i, i, j, j); DVConstraint dvConstraint = DVConstraint.createExplicitListConstraint( new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }); DataValidation dataValidation = new HSSFDataValidation(addressList, dvConstraint); dataValidation.setSuppressDropDownArrow(false); sheetBIA.addValidationData(dataValidation); } } } }
From source file:kr.co.blackducksoftware.rg.displayexcel.Ex.java
License:Open Source License
/** * "OSS Check List sheet" //from ww w.j a v a2 s . c o m * */ public static void OSSCLineHeader(HSSFSheet sheet) { LogMaker.makelog("Creating OSS Header"); HSSFRow row = sheet.createRow(0); row.setHeight((short) 500); int i = 0; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Description "); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis vv Description"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Description"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(3, HSSFCell.CELL_TYPE_STRING).setCellValue("1st Review (Development Team) "); row.getCell(3).setCellStyle(Style.fReviewCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Description"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(5, HSSFCell.CELL_TYPE_STRING).setCellValue(" Final Review "); row.getCell(5).setCellStyle(Style.finalReviewCellStyle); sheet.autoSizeColumn((short) i, true); i++; row.createCell(i, HSSFCell.CELL_TYPE_STRING).setCellValue("Analysis Description"); row.getCell(i).setCellStyle(Style.anaDesCellStyle); sheet.autoSizeColumn((short) i, true); i++; }
From source file:kr.co.blackducksoftware.rg.displayexcel.Style.java
@SuppressWarnings("deprecation") public static void createSheetHeaders(HSSFSheet currentSheet) { HSSFRow mainHeader = currentSheet.createRow(1); // HSSFRow topMergedHeaders = currentSheet.createRow(1); /**/* ww w .j a v a2s . c om*/ * ???? ??? ???? */ HSSFRichTextString sourceCodeIdentificationReportHeader = new HSSFRichTextString( "?? ???? SW ????? ???? ???"); mainHeader.createCell(0).setCellValue(sourceCodeIdentificationReportHeader); currentSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));// 7->6?? // ???? // for // comment mainHeader.getCell(0).setCellStyle(mainHeaderStyle); /* * Menu 1 */ HSSFRow menu1 = currentSheet.createRow(3); HSSFRichTextString menuString = new HSSFRichTextString( "1. ?????? ????"); menu1.createCell(0).setCellValue(menuString); currentSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));// 7->6?? // ???? // for // comment menu1.getCell(0).setCellStyle(menuLineStyle); /* * BOM (menu2) */ HSSFRow BOMHead = currentSheet.createRow(11);// 12?? ???? BOMHead.createCell(0).setCellValue( "2. ?????? ??????? ???(Bill of Materials)"); currentSheet.autoSizeColumn((short) 0, true); BOMHead.getCell(0).setCellStyle(menuLineStyle); /** * ?? ??? ???? ???? */ HSSFRichTextString homepageHeader = new HSSFRichTextString("??????"); HSSFRichTextString matchedObHeader = new HSSFRichTextString("??? ??"); HSSFRichTextString matchedFilesCountHeader = new HSSFRichTextString("File / Folder"); HSSFRichTextString componentHeader = new HSSFRichTextString("Component"); HSSFRichTextString versionHeader = new HSSFRichTextString("Version"); // HSSFRichTextString licenseHeader = new // HSSFRichTextString("Total Lines"); HSSFRichTextString identifierHeader = new HSSFRichTextString("Component"); HSSFRichTextString identifiedDateHeader = new HSSFRichTextString("Version"); HSSFRichTextString commentHeader = new HSSFRichTextString("????????"); HSSFRichTextString firstLineHeader = new HSSFRichTextString("Matched First Line");// firstline HSSFRichTextString matchedRatioHeader = new HSSFRichTextString("Matched Ratio");// MachedRatioPercent HSSFRichTextString realCommentHeader = new HSSFRichTextString("Comment");// add // for // comment HSSFRichTextString licenseHeader = new HSSFRichTextString("?????");// add // for // license HSSFRichTextString jointHeader = new HSSFRichTextString("????????");// add // for // license HSSFRichTextString fileCountHeader = new HSSFRichTextString("?? ???? ??");// add // for // license HSSFRichTextString percentHeader = new HSSFRichTextString("%");// add // for // license // currentSheet.addMergedRegion(new CellRangeAddress(1, 1, 9, 13)); /* * 2?? ?? ??????? ???. */ HSSFRow BOM = currentSheet.createRow(12);// 13?? ???? // topMergedHeaders.createCell(0).setCellValue(categoryHeader); BOM.createCell(0).setCellValue(matchedObHeader); BOM.createCell(1).setCellValue(componentHeader); BOM.createCell(2).setCellValue(versionHeader); BOM.createCell(3).setCellValue(homepageHeader); BOM.createCell(4).setCellValue(licenseHeader); BOM.createCell(5).setCellValue(jointHeader); BOM.createCell(6).setCellValue(fileCountHeader); // BOM.createCell(7).setCellValue(commentHeader); /* * 2?? ?? ?????? ? ?? */ for (int a = 0; a < BOM.getLastCellNum(); a++) { BOM.getCell(a).setCellStyle(firstMergedCellStyle); currentSheet.autoSizeColumn((short) a, true); } /* * ????sw????? ???? (menu3) */ int BOMCount = 0;// ?? HSSFRow OSSSMenu = currentSheet.createRow(15 + BOMCount);// 3?? ?? ???? ???? OSSSMenu.createCell(0) .setCellValue("3. ????SW????? ????"); currentSheet.autoSizeColumn((short) 0, true); OSSSMenu.getCell(0).setCellStyle(menuLineStyle); /* * 3?? ?? ??????? ???. */ HSSFRow OSSS = currentSheet.createRow(16 + BOMCount);// 3?? ???? // topMergedHeaders.createCell(0).setCellValue(categoryHeader); OSSS.createCell(0).setCellValue(licenseHeader); OSSS.createCell(1).setCellValue(jointHeader); OSSS.createCell(2).setCellValue(fileCountHeader); OSSS.createCell(3).setCellValue(percentHeader); // OSSS.createCell(7).setCellValue(commentHeader); for (int a = 0; a < OSSS.getLastCellNum(); a++) { OSSS.getCell(a).setCellStyle(firstMergedCellStyle); currentSheet.autoSizeColumn((short) a, true); } /* * ????? ????? (menu4) */ int OSSSCount = 0;// ?? HSSFRow analMenu = currentSheet.createRow(19 + BOMCount + OSSSCount);// 4?? // ?? // ???? // ???? analMenu.createCell(0).setCellValue("4. ????? ?????"); currentSheet.autoSizeColumn((short) 0, true); analMenu.getCell(0).setCellStyle(menuLineStyle); /* * 4?? ?? ??????? ???. */ HSSFRow anal = currentSheet.createRow(20 + BOMCount + OSSSCount);// 3?? // ???? anal.createCell(0).setCellValue("????? ?????"); anal.getCell(0).setCellStyle(analCellStyle); currentSheet.autoSizeColumn((short) 0, true); }
From source file:net.sf.jasperreports.engine.export.JRXlsMetadataExporter.java
License:Open Source License
protected void closeWorkbook(OutputStream os) throws JRException { try {/* ww w. j a va2 s . c o m*/ for (Object anchorName : anchorNames.keySet()) { HSSFName anchor = anchorNames.get(anchorName); List<Hyperlink> linkList = anchorLinks.get(anchorName); anchor.setRefersToFormula( "'" + workbook.getSheetName(anchor.getSheetIndex()) + "'!" + anchor.getRefersToFormula()); if (linkList != null && !linkList.isEmpty()) { for (Hyperlink link : linkList) { link.setAddress(anchor.getRefersToFormula()); } } } int index = 0; for (Integer linkPage : pageLinks.keySet()) { List<Hyperlink> linkList = pageLinks.get(linkPage); if (linkList != null && !linkList.isEmpty()) { for (Hyperlink link : linkList) { index = onePagePerSheetMap.get(linkPage - 1) != null ? (onePagePerSheetMap.get(linkPage - 1) ? Math.max(0, linkPage - 1) : Math.max(0, sheetsBeforeCurrentReportMap.get(linkPage))) : 0; link.setAddress("'" + workbook.getSheetName(index) + "'!$A$1"); } } } for (int i = 0; i < workbook.getNumberOfSheets(); i++) { HSSFSheet currentSheet = workbook.getSheetAt(i); currentSheet.setForceFormulaRecalculation(true); for (String columnName : columnNames) { Integer columnWidth = columnWidths.get(columnName); if (columnWidth != null && columnWidth < Integer.MAX_VALUE) { currentSheet.setColumnWidth(columnNamesMap.get(columnName), Math.min(43 * columnWidth, 256 * 255)); } else { currentSheet.autoSizeColumn(columnNamesMap.get(columnName), false); } } } workbook.write(os); } catch (IOException e) { throw new JRException("Error generating XLS metadata report : " + jasperPrint.getName(), e); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.academicAdministration.executionCourseManagement.CourseLoadOverviewBean.java
License:Open Source License
public StyledExcelSpreadsheet getInconsistencySpreadsheet() { final StyledExcelSpreadsheet spreadsheet = new StyledExcelSpreadsheet( BundleUtil.getString(Bundle.ACADEMIC, "label.course.load.inconsistency.filename") + "_" + executionSemester.getExecutionYear().getYear().replace('/', '_') + "_" + executionSemester.getSemester()); HSSFCellStyle normalStyle = spreadsheet.getExcelStyle().getValueStyle(); normalStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFWorkbook wb = spreadsheet.getWorkbook(); HSSFFont font = wb.createFont();//from ww w . jav a2 s .c o m font.setColor(HSSFColor.BLACK.index); font.setFontHeightInPoints((short) 8); HSSFCellStyle redStyle = wb.createCellStyle(); redStyle.setFont(font); redStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); redStyle.setFillForegroundColor(HSSFColor.ORANGE.index); redStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFCellStyle yellowStyle = wb.createCellStyle(); yellowStyle.setFont(font); yellowStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); yellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index); yellowStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); spreadsheet.newHeaderRow(); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.department")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.degree")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shift")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shiftType")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.competenceCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.curricularCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lesson.count")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances.count")); for (final ExecutionCourse executionCourse : executionSemester.getAssociatedExecutionCoursesSet()) { for (final CourseLoad courseLoad : executionCourse.getCourseLoadsSet()) { for (final Shift shift : courseLoad.getShiftsSet()) { spreadsheet.newRow(); spreadsheet.addCell(getDepartmentString(executionCourse)); spreadsheet.addCell(executionCourse.getDegreePresentationString()); spreadsheet.addCell(executionCourse.getName()); spreadsheet.addCell(shift.getNome()); spreadsheet.addCell(courseLoad.getType().getFullNameTipoAula()); final BigDecimal competenceCourseLoad = new BigDecimal(getCompetenceCourseLoad(courseLoad)) .setScale(2, RoundingMode.HALF_EVEN); final BigDecimal curricularCourseLoad = new BigDecimal(getCurricularCourseLoad(courseLoad)) .setScale(2, RoundingMode.HALF_EVEN); final BigDecimal executionLoad = courseLoad.getTotalQuantity().setScale(2, RoundingMode.HALF_EVEN); final BigDecimal shiftCourseLoad = getShiftCourseLoad(shift).setScale(2, RoundingMode.HALF_EVEN); if (competenceCourseLoad.signum() < 0) { spreadsheet.addCell(getCompetenceCourseLoadStrings(courseLoad), redStyle); } else { spreadsheet.addCell(competenceCourseLoad); } if (!competenceCourseLoad.equals(curricularCourseLoad) || curricularCourseLoad.signum() < 0) { spreadsheet.addCell(getCurricularCourseLoadString(courseLoad), redStyle); } else { spreadsheet.addCell(curricularCourseLoad); } if (!executionLoad.equals(curricularCourseLoad)) { spreadsheet.addCell(executionLoad, redStyle); } else { spreadsheet.addCell(executionLoad); } if (!shiftCourseLoad.equals(executionLoad)) { if (isLargeDifference(shiftCourseLoad, executionLoad, competenceCourseLoad.divide(new BigDecimal(14), 2, RoundingMode.HALF_EVEN))) { spreadsheet.addCell(shiftCourseLoad, redStyle); } else { spreadsheet.addCell(shiftCourseLoad, yellowStyle); } } else { spreadsheet.addCell(shiftCourseLoad); } spreadsheet.addCell(shift.getAssociatedLessonsSet().size()); spreadsheet.addCell(getLessonInstanceCount(shift)); } } } final HSSFSheet sheet = wb.getSheetAt(0); sheet.createFreezePane(0, 1, 0, 1); sheet.autoSizeColumn(1, true); sheet.autoSizeColumn(2, true); sheet.autoSizeColumn(3, true); sheet.autoSizeColumn(4, true); sheet.autoSizeColumn(5, true); sheet.autoSizeColumn(6, true); sheet.autoSizeColumn(7, true); sheet.autoSizeColumn(8, true); sheet.autoSizeColumn(9, true); return spreadsheet; }
From source file:org.fenixedu.academic.ui.struts.action.academicAdministration.executionCourseManagement.CourseLoadOverviewBean.java
License:Open Source License
public StyledExcelSpreadsheet getInconsistencySpreadsheet() { final StyledExcelSpreadsheet spreadsheet = new StyledExcelSpreadsheet( BundleUtil.getString(Bundle.ACADEMIC, "label.course.load.inconsistency.filename") + "_" + executionSemester.getExecutionYear().getYear().replace('/', '_') + "_" + executionSemester.getSemester()); CellStyle normalStyle = spreadsheet.getExcelStyle().getValueStyle(); normalStyle.setAlignment(HorizontalAlignment.CENTER); HSSFWorkbook wb = spreadsheet.getWorkbook(); HSSFFont font = wb.createFont();//w ww . j av a 2 s .c o m font.setColor(HSSFColor.BLACK.index); font.setFontHeightInPoints((short) 8); HSSFCellStyle redStyle = wb.createCellStyle(); redStyle.setFont(font); redStyle.setAlignment(HorizontalAlignment.CENTER); redStyle.setFillForegroundColor(HSSFColor.ORANGE.index); redStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); HSSFCellStyle yellowStyle = wb.createCellStyle(); yellowStyle.setFont(font); yellowStyle.setAlignment(HorizontalAlignment.CENTER); yellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index); yellowStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); spreadsheet.newHeaderRow(); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.department")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.degree")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shift")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shiftType")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.competenceCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.curricularCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lesson.count")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances.count")); for (final ExecutionCourse executionCourse : executionSemester.getAssociatedExecutionCoursesSet()) { for (final CourseLoad courseLoad : executionCourse.getCourseLoadsSet()) { for (final Shift shift : courseLoad.getShiftsSet()) { spreadsheet.newRow(); spreadsheet.addCell(getDepartmentString(executionCourse)); spreadsheet.addCell(executionCourse.getDegreePresentationString()); spreadsheet.addCell(executionCourse.getName()); spreadsheet.addCell(shift.getNome()); spreadsheet.addCell(courseLoad.getType().getFullNameTipoAula()); final BigDecimal competenceCourseLoad = new BigDecimal(getCompetenceCourseLoad(courseLoad)) .setScale(2, RoundingMode.HALF_EVEN); final BigDecimal curricularCourseLoad = new BigDecimal(getCurricularCourseLoad(courseLoad)) .setScale(2, RoundingMode.HALF_EVEN); final BigDecimal executionLoad = courseLoad.getTotalQuantity().setScale(2, RoundingMode.HALF_EVEN); final BigDecimal shiftCourseLoad = getShiftCourseLoad(shift).setScale(2, RoundingMode.HALF_EVEN); if (competenceCourseLoad.signum() < 0) { spreadsheet.addCell(getCompetenceCourseLoadStrings(courseLoad), redStyle); } else { spreadsheet.addCell(competenceCourseLoad); } if (!competenceCourseLoad.equals(curricularCourseLoad) || curricularCourseLoad.signum() < 0) { spreadsheet.addCell(getCurricularCourseLoadString(courseLoad), redStyle); } else { spreadsheet.addCell(curricularCourseLoad); } if (!executionLoad.equals(curricularCourseLoad)) { spreadsheet.addCell(executionLoad, redStyle); } else { spreadsheet.addCell(executionLoad); } if (!shiftCourseLoad.equals(executionLoad)) { if (isLargeDifference(shiftCourseLoad, executionLoad, competenceCourseLoad.divide(new BigDecimal(14), 2, RoundingMode.HALF_EVEN))) { spreadsheet.addCell(shiftCourseLoad, redStyle); } else { spreadsheet.addCell(shiftCourseLoad, yellowStyle); } } else { spreadsheet.addCell(shiftCourseLoad); } spreadsheet.addCell(shift.getAssociatedLessonsSet().size()); spreadsheet.addCell(getLessonInstanceCount(shift)); } } } final HSSFSheet sheet = wb.getSheetAt(0); sheet.createFreezePane(0, 1, 0, 1); sheet.autoSizeColumn(1, true); sheet.autoSizeColumn(2, true); sheet.autoSizeColumn(3, true); sheet.autoSizeColumn(4, true); sheet.autoSizeColumn(5, true); sheet.autoSizeColumn(6, true); sheet.autoSizeColumn(7, true); sheet.autoSizeColumn(8, true); sheet.autoSizeColumn(9, true); return spreadsheet; }