Java Code Examples for org.apache.poi.hssf.usermodel.HSSFSheet#createRow()

The following examples show how to use org.apache.poi.hssf.usermodel.HSSFSheet#createRow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExcelExportSuper.java    From phone with Apache License 2.0 7 votes vote down vote up
/**
 * 表头条件
 * @param sheet
 * @param t
 * @param cellCount
 * @return
 */
void writeCondtions(HSSFSheet sheet){
	T t = getConditions();
	if (t!=null) {
		HSSFRow row = sheet.createRow(getRowNumber());
		row.setHeight((short) 500);
		CellRangeAddress cra = new CellRangeAddress(getRowNumber(), getRowNumber(), 0, getColumnJson().size());
		sheet.addMergedRegion(cra);
		HSSFCell cell = row.createCell(0);
		HSSFCellStyle style = cell.getCellStyle();
		style.setAlignment(HorizontalAlignment.CENTER);
		style.setVerticalAlignment(VerticalAlignment.CENTER);
		style.setWrapText(true);
		cell.setCellStyle(style);
		setCellValue(cell, formatCondition(t));
		addRowNumber();
	}
}
 
Example 2
Source File: ExcelUtil.java    From phone with Apache License 2.0 6 votes vote down vote up
/**
   * 初始化表头
   * @param sheet
   * @param columnJson
   * @param rowNumber
   */
  private static void writeSheetHead(HSSFSheet sheet,JSONObject columnJson,int rowNumber){
if (logger.isDebugEnabled()) {
	logger.debug("writeSheetHead(HSSFSheet, JSONObject, int) - start"); //$NON-NLS-1$
}

Set<String> keySet = columnJson.keySet();
int cellNumber = 0;
HSSFRow row = sheet.createRow(rowNumber);
for (String k : keySet) {//k:GOODS_NO
	String name = columnJson.getString(k);//品项编码
	sheet.autoSizeColumn(cellNumber);
	HSSFCell cell = row.createCell(cellNumber++);
	cell.setCellValue(name);
}

if (logger.isDebugEnabled()) {
	logger.debug("writeSheetHead(HSSFSheet, JSONObject, int) - end"); //$NON-NLS-1$
}
  }
 
Example 3
Source File: ExportEventsImpl.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet )
{
    final Font font = sheet.getWorkbook ().createFont ();
    font.setFontName ( "Arial" );
    font.setBoldweight ( Font.BOLDWEIGHT_BOLD );
    font.setColor ( HSSFColor.WHITE.index );

    final CellStyle style = sheet.getWorkbook ().createCellStyle ();
    style.setFont ( font );
    style.setFillForegroundColor ( HSSFColor.BLACK.index );
    style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND );

    final HSSFRow row = sheet.createRow ( 0 );

    for ( int i = 0; i < columns.size (); i++ )
    {
        final Field field = columns.get ( i );

        final HSSFCell cell = row.createCell ( i );
        cell.setCellValue ( field.getHeader () );
        cell.setCellStyle ( style );
    }
}
 
Example 4
Source File: EPFLCandidatesReport.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public HSSFSheet build(final SearchPhdIndividualProgramProcessBean bean) {
    List<PhdIndividualProgramProcess> processes =
            PhdIndividualProgramProcess.search(bean.getExecutionYear(), bean.getPredicates());

    if (!hasEPFLCandidates(processes)) {
        return null;
    }

    HSSFSheet sheet = workbook.createSheet("Candidaturas EPFL");

    setHeaders(sheet);

    int i = 2;
    for (PhdIndividualProgramProcess process : processes) {
        if (isProcessFromEPFL(process) && process.isAllowedToManageProcess(Authenticate.getUser())) {
            HSSFRow row = sheet.createRow(i);

            fillRow(process, row);
            i++;
        }

    }

    return sheet;
}
 
Example 5
Source File: PoiUtil.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
/**
 * 导出函数有三个参数,主内容数据,标题数组,到处文件名
 */
public void createxls(Object[][] messages, String[] titles, String filename) {
    try {
        FileOutputStream fos = new FileOutputStream( new File( filename ) );
        HSSFWorkbook book = new HSSFWorkbook();// 所有execl的父节点
        HSSFSheet sheet = book.createSheet( "sheet1" );//此处可以随意设置
        HSSFRow hssfrow = sheet.createRow( 0 );//创建首行标题
        HSSFCell hssfcell = null;
        for (int i = 0; i < titles.length; i++) {//创建标题栏目,也就是表格第一行
            hssfcell = hssfrow.createCell( i );
            hssfcell.setCellType( HSSFCell.ENCODING_UTF_16 );
            hssfcell.setCellValue( titles[i] );
        }

        System.out.println( "message:" + messages.length );
        for (int i = 0; i < messages.length; i++) {//添加表格中的内容
            hssfrow = sheet.createRow( i + 1 );//创建表格第二行,由于标记为0,这里设置为一,主要为了区别标题和内容
            Object[] obj = messages[i];
            for (int j = 0; j < obj.length; j++) {
                hssfcell = hssfrow.createCell( j );
                hssfcell.setCellType( HSSFCell.ENCODING_UTF_16 );//关于数据编码的问题
                hssfcell.setCellValue( obj[j] + "" );//转换为字符串的方式
                System.out.print( obj[j] + "\t" );
            }
            System.out.println();
        }
        book.write( fos );
        fos.flush();
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println( e );
    }
}
 
Example 6
Source File: ReportStudentsUTLCandidatesForOneStudentFirstYear.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void addHeaders(HSSFSheet sheet) {
    sheet.createRow(0);
    sheet.createRow(1);

    addHeaderCell(sheet, getHeaderInBundle("institutionCode"), 0);
    addHeaderCell(sheet, getHeaderInBundle("institutionName"), 1);
    addHeaderCell(sheet, getHeaderInBundle("candidacyNumber"), 2);
    addHeaderCell(sheet, getHeaderInBundle("studentNumberForPrint"), 3);
    addHeaderCell(sheet, getHeaderInBundle("studentName"), 4);
    addHeaderCell(sheet, getHeaderInBundle("documentTypeName"), 5);
    addHeaderCell(sheet, getHeaderInBundle("documentNumber"), 6);
    addHeaderCell(sheet, getHeaderInBundle("degreeCode"), 7);
    addHeaderCell(sheet, getHeaderInBundle("degreeName"), 8);
    addHeaderCell(sheet, getHeaderInBundle("degreeTypeName"), 9);
    addHeaderCell(sheet, getHeaderInBundle("firstEnrolmentOnCurrentExecutionYear"), 10);
    addHeaderCell(sheet, getHeaderInBundle("gratuityAmount"), 11);
    addHeaderCell(sheet, getHeaderInBundle("numberOfMonthsExecutionYear"), 12);
    addHeaderCell(sheet, getHeaderInBundle("firstMonthOfPayment"), 13);
    addHeaderCell(sheet, getHeaderInBundle("ownerOfCETQualification"), 14);
    addHeaderCell(sheet, getHeaderInBundle("degreeQualificationOwner"), 15);
    addHeaderCell(sheet, getHeaderInBundle("masterQualificationOwner"), 16);
    addHeaderCell(sheet, getHeaderInBundle("phdQualificationOwner"), 17);
    addHeaderCell(sheet, getHeaderInBundle("ownerOfCollegeQualification"), 18);
    addHeaderCell(sheet, getHeaderInBundle("observations"), 19);
    addHeaderCell(sheet, getHeaderInBundle("regime"), 20);
    addHeaderCell(sheet, getHeaderInBundle("numberOfDegreeCurricularYears"), 21);
    addHeaderCell(sheet, getHeaderInBundle("ingression.year.on.cycle.studies.count"), 22);
    addHeaderCell(sheet, getHeaderInBundle("numberOfEnrolledECTS"), 23);
    addHeaderCell(sheet, getHeaderInBundle("nif"), 24);

}
 
Example 7
Source File: PhdReport.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void addHeaderCell(HSSFSheet sheet, String value, int columnNumber) {
    HSSFRow row = sheet.getRow(0);
    if (row == null) {
        row = sheet.createRow(0);
    }

    HSSFCell cell = row.createCell(columnNumber);

    cell.setCellValue(value);
    cell.setCellStyle(headerStyle);

    cell.setCellValue(value);

    sheet.addMergedRegion(new CellRangeAddress(0, 1, columnNumber, columnNumber));
}
 
Example 8
Source File: TestExternalRelvarXLS4.java    From Rel with Apache License 2.0 5 votes vote down vote up
@Before
public void testXLS1() throws IOException {
       try (HSSFWorkbook workbook = new HSSFWorkbook()) {
        HSSFSheet sheet = workbook.createSheet();
        HSSFRow row = null;
        HSSFCell cell = null;
        row = sheet.createRow(0);
        cell = row.createCell(0);
		cell.setCellValue("A");
		cell = row.createCell(1);
		cell.setCellValue("B");
		cell = row.createCell(2);
		cell.setCellValue("C");
		
		insert(1,sheet,row,cell,1,2,3);
		insert(2,sheet,row,cell,4,5,6);
		insert(3,sheet,row,cell,7,8,9);
        
		try (FileOutputStream out = new FileOutputStream(file)) {
		    workbook.write(out);
		} catch (IOException e) {
			e.printStackTrace();
		}
       }

	String src = 
			"BEGIN;\n" +
					"var myvar external xls \"" + file.getAbsolutePath() + "\";" +
			"END;\n" +
			"true";
	testEquals("true", src);
}
 
Example 9
Source File: ToolImportSplitter.java    From android-lang-tool with Apache License 2.0 5 votes vote down vote up
private void copyRowRange(HSSFSheet inSheet, HSSFSheet outSheet, int rowStart, int rowEnd) {
    for (int rowIdx = rowStart, outRowIdx = 1; rowIdx < rowEnd; rowIdx++, outRowIdx++) {
        HSSFRow outRow = outSheet.createRow(outRowIdx);
        HSSFRow inRow = inSheet.getRow(rowIdx-1);
        copyRow(inRow, outRow);
    }
}
 
Example 10
Source File: JU_Excel2003Color.java    From hy.common.report with Apache License 2.0 5 votes vote down vote up
@Test
public void test_001()
{
    HSSFWorkbook v_Workbook = new HSSFWorkbook();
    HSSFSheet    v_Sheet    = v_Workbook.createSheet("测试单元格颜色");
    
    v_Sheet.setColumnWidth(0 ,2560);
    
    for (int v_RowIndex=0; v_RowIndex<4000; v_RowIndex++)
    {
        HSSFRow v_Row = v_Sheet.createRow(v_RowIndex);
        
        for (int v_ColIndex=0; v_ColIndex<1; v_ColIndex++)
        {
            HSSFCell      v_Cell = v_Row.createCell(v_ColIndex);
            HSSFCellStyle v_CellStyle = v_Workbook.createCellStyle();
            
            v_CellStyle.setFillForegroundColor((short)(v_RowIndex + 1));
            v_CellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            
            v_Cell.setCellStyle(v_CellStyle);
            v_Cell.setCellValue("" + (v_RowIndex + 1));
        }
    }
    
    ExcelHelp.save(v_Workbook ,"/Users/hy/Downloads/测试2003版本的单元格颜色");
}
 
Example 11
Source File: TestExternalRelvarXLS3.java    From Rel with Apache License 2.0 5 votes vote down vote up
private static void insert(int rowNum, HSSFSheet sheet, HSSFRow row, HSSFCell cell, int arg0, int arg1, int arg2) {
	row = sheet.createRow(rowNum);
       cell = row.createCell(0);
	cell.setCellValue(arg0);
	cell = row.createCell(1);
	cell.setCellValue(arg1);
	cell = row.createCell(2);
	cell.setCellValue(arg2);
}
 
Example 12
Source File: TestExternalRelvarXLS2.java    From Rel with Apache License 2.0 5 votes vote down vote up
@Before
public void testXLS1() throws IOException {
       try (HSSFWorkbook workbook = new HSSFWorkbook()) {
        HSSFSheet sheet = workbook.createSheet();
        HSSFRow row = null;
        HSSFCell cell = null;
        row = sheet.createRow(0);
        cell = row.createCell(0);
		cell.setCellValue("A");
		cell = row.createCell(1);
		cell.setCellValue("B");
		cell = row.createCell(2);
		cell.setCellValue("C");
		
		insert(1,sheet,row,cell,1,2,3);
		insert(2,sheet,row,cell,4,5,6);
		insert(3,sheet,row,cell,4,5,6);
		insert(4,sheet,row,cell,1,2,3);
		insert(5,sheet,row,cell,7,8,9);
		insert(6,sheet,row,cell,7,8,9);
		insert(7,sheet,row,cell,4,5,6);
        
		try (FileOutputStream out = new FileOutputStream(file)) {
		    workbook.write(out);
		} catch (IOException e) {
			e.printStackTrace();
		}
       }

	String src = 
			"BEGIN;\n" +
					"var myvar external xls \"" + file.getAbsolutePath() + "\" dup_remove;" +
			"END;\n" +
			"true";
	testEquals("true", src);
}
 
Example 13
Source File: TestExternalRelvarXLS4.java    From Rel with Apache License 2.0 5 votes vote down vote up
private static void insert(int rowNum, HSSFSheet sheet, HSSFRow row, HSSFCell cell, int arg0, int arg1, int arg2) {
	row = sheet.createRow(rowNum);
       cell = row.createCell(0);
	cell.setCellValue(arg0);
	cell = row.createCell(1);
	cell.setCellValue(arg1);
	cell = row.createCell(2);
	cell.setCellValue(arg2);
}
 
Example 14
Source File: ReportStudentsUTLCandidatesForOneStudentFirstYear.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void addValues(HSSFSheet sheet) {
    int i = 2;
    for (StudentLine studentLine : getCorrectStudentLines()) {

        try {

            String institutionCode = studentLine.getInstitutionCode();
            String institutionName = studentLine.getInstitutionName();
            String candidacyNumber = studentLine.getCandidacyNumber();
            String studentNumberForPrint = studentLine.getStudentNumberForPrint();
            String studentName = studentLine.getStudentName();
            String documentTypeName = studentLine.getDocumentTypeName();
            String documentNumber = studentLine.getDocumentNumber();
            String degreeCode = studentLine.getDegreeCode();
            String degreeName = studentLine.getDegreeName();
            String degreeTypeName = studentLine.getDegreeTypeName();
            String regime = studentLine.getRegime();
            Integer countNumberOfEnrolmentsYearsSinceRegistrationStart =
                    studentLine.getCountNumberOfEnrolmentsYearsSinceRegistrationStart();
            Integer numberOfDegreeCurricularYears = studentLine.getNumberOfDegreeCurricularYears();
            Double numberOfEnrolledECTS = studentLine.getNumberOfEnrolledECTS();
            Money gratuityAmount = studentLine.getGratuityAmount();
            Integer numberOfMonthsExecutionYear = studentLine.getNumberOfMonthsExecutionYear();
            String firstMonthOfPayment = studentLine.getFirstMonthOfPayment();
            Boolean ownerOfCETQualification = studentLine.getOwnerOfCETQualification();
            boolean degreeQualificationOwner = studentLine.isDegreeQualificationOwner();
            boolean masterQualificationOwner = studentLine.isMasterQualificationOwner();
            boolean phdQualificationOwner = studentLine.isPhdQualificationOwner();
            boolean ownerOfCollegeQualification = studentLine.isOwnerOfCollegeQualification();
            String observations = studentLine.getObservations();
            String nif = studentLine.getNif();
            LocalDate firstEnrolmentOnCurrentExecutionYear = studentLine.getFirstEnrolmentOnCurrentExecutionYear();

            HSSFRow row = sheet.createRow(i);
            addCellValue(row, onNullEmptyString(institutionCode), 0);
            addCellValue(row, onNullEmptyString(institutionName), 1);
            addCellValue(row, onNullEmptyString(candidacyNumber), 2);
            addCellValue(row, onNullEmptyString(studentNumberForPrint), 3);
            addCellValue(row, onNullEmptyString(studentName), 4);
            addCellValue(row, onNullEmptyString(documentTypeName), 5);
            addCellValue(row, onNullEmptyString(documentNumber), 6);
            addCellValue(row, onNullEmptyString(degreeCode), 7);
            addCellValue(row, onNullEmptyString(degreeName), 8);
            addCellValue(row, onNullEmptyString(degreeTypeName), 9);
            addCellValue(row, onNullEmptyString(firstEnrolmentOnCurrentExecutionYear), 10);
            addCellValue(row,
                    onNullEmptyString(gratuityAmount != null ? gratuityAmount.toPlainString().replace('.', ',') : ""), 11);
            addCellValue(row, onNullEmptyString(numberOfMonthsExecutionYear), 12);
            addCellValue(row, onNullEmptyString(firstMonthOfPayment), 13);
            addCellValue(row, onNullEmptyString(ownerOfCETQualification), 14);
            addCellValue(row, onNullEmptyString(degreeQualificationOwner), 15);
            addCellValue(row, onNullEmptyString(masterQualificationOwner), 16);
            addCellValue(row, onNullEmptyString(phdQualificationOwner), 17);
            addCellValue(row, onNullEmptyString(ownerOfCollegeQualification), 18);
            addCellValue(row, onNullEmptyString(observations), 19);
            addCellValue(row, onNullEmptyString(regime), 20);
            addCellValue(row, onNullEmptyString(numberOfDegreeCurricularYears), 21);
            addCellValue(row, onNullEmptyString(countNumberOfEnrolmentsYearsSinceRegistrationStart), 22);
            addCellValue(row,
                    onNullEmptyString(numberOfEnrolledECTS != null ? numberOfEnrolledECTS.toString().replace('.', ',') : ""),
                    23);
            addCellValue(row, onNullEmptyString(nif), 24);

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        i++;
    }
}
 
Example 15
Source File: ToolImportSplitter.java    From android-lang-tool with Apache License 2.0 4 votes vote down vote up
private void copyTitleRow(Row inTitleRow, HSSFSheet outSheet) {
    HSSFRow outTitleRow = outSheet.createRow(0);
    copyRow(inTitleRow, outTitleRow);
}
 
Example 16
Source File: ReportStudentsUTLCandidatesForFirstYear.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void addValues(HSSFSheet sheet) {
    int i = 2;
    for (StudentLine studentLine : getCorrectStudentLines()) {

        try {

            String institutionCode = studentLine.getInstitutionCode();
            String institutionName = studentLine.getInstitutionName();
            String candidacyNumber = studentLine.getCandidacyNumber();
            String studentNumberForPrint = studentLine.getStudentNumberForPrint();
            String studentName = studentLine.getStudentName();
            String documentTypeName = studentLine.getDocumentTypeName();
            String documentNumber = studentLine.getDocumentNumber();
            String degreeCode = studentLine.getDegreeCode();
            String degreeName = studentLine.getDegreeName();
            String degreeTypeName = studentLine.getDegreeTypeName();
            String regime = studentLine.getRegime();
            Integer countNumberOfEnrolmentsYearsSinceRegistrationStart =
                    studentLine.getCountNumberOfEnrolmentsYearsSinceRegistrationStart();
            Integer numberOfDegreeCurricularYears = studentLine.getNumberOfDegreeCurricularYears();
            Double numberOfEnrolledECTS = studentLine.getNumberOfEnrolledECTS();
            Money gratuityAmount = studentLine.getGratuityAmount();
            Integer numberOfMonthsExecutionYear = studentLine.getNumberOfMonthsExecutionYear();
            String firstMonthOfPayment = studentLine.getFirstMonthOfPayment();
            Boolean ownerOfCETQualification = studentLine.getOwnerOfCETQualification();
            boolean degreeQualificationOwner = studentLine.isDegreeQualificationOwner();
            boolean masterQualificationOwner = studentLine.isMasterQualificationOwner();
            boolean phdQualificationOwner = studentLine.isPhdQualificationOwner();
            boolean ownerOfCollegeQualification = studentLine.isOwnerOfCollegeQualification();
            String observations = studentLine.getObservations();
            String nif = studentLine.getNif();
            LocalDate firstEnrolmentOnCurrentExecutionYear = studentLine.getFirstEnrolmentOnCurrentExecutionYear();

            HSSFRow row = sheet.createRow(i);
            addCellValue(row, onNullEmptyString(institutionCode), 0);
            addCellValue(row, onNullEmptyString(institutionName), 1);
            addCellValue(row, onNullEmptyString(candidacyNumber), 2);
            addCellValue(row, onNullEmptyString(studentNumberForPrint), 3);
            addCellValue(row, onNullEmptyString(studentName), 4);
            addCellValue(row, onNullEmptyString(documentTypeName), 5);
            addCellValue(row, onNullEmptyString(documentNumber), 6);
            addCellValue(row, onNullEmptyString(degreeCode), 7);
            addCellValue(row, onNullEmptyString(degreeName), 8);
            addCellValue(row, onNullEmptyString(degreeTypeName), 9);
            addCellValue(row, "", 10);
            addCellValue(row, onNullEmptyString(firstEnrolmentOnCurrentExecutionYear), 11);
            addCellValue(row,
                    onNullEmptyString(gratuityAmount != null ? gratuityAmount.toPlainString().replace('.', ',') : ""), 12);
            addCellValue(row, onNullEmptyString(numberOfMonthsExecutionYear), 13);
            addCellValue(row, onNullEmptyString(firstMonthOfPayment), 14);
            addCellValue(row, onNullEmptyString(ownerOfCETQualification), 15);
            addCellValue(row, onNullEmptyString(degreeQualificationOwner), 16);
            addCellValue(row, onNullEmptyString(masterQualificationOwner), 17);
            addCellValue(row, onNullEmptyString(phdQualificationOwner), 18);
            addCellValue(row, onNullEmptyString(ownerOfCollegeQualification), 19);
            addCellValue(row, onNullEmptyString(observations), 20);
            addCellValue(row, onNullEmptyString(regime), 21);
            addCellValue(row, onNullEmptyString(numberOfDegreeCurricularYears), 22);
            addCellValue(row, onNullEmptyString(countNumberOfEnrolmentsYearsSinceRegistrationStart), 23);
            addCellValue(row,
                    onNullEmptyString(numberOfEnrolledECTS != null ? numberOfEnrolledECTS.toString().replace('.', ',') : ""),
                    24);
            addCellValue(row, onNullEmptyString(nif), 25);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        i++;
    }
}
 
Example 17
Source File: AddDimensionedImage.java    From kbase-doc with Apache License 2.0 4 votes vote down vote up
/**
 * Determines whether the sheet's row should be re-sized to accomodate
 * the image, adjusts the rows height if necessary and creates then
 * returns a ClientAnchorDetail object that facilitates construction of
 * an HSSFClientAnchor that will fix the image on the sheet and establish
 * it's size.
 *
 * @param sheet A reference to the sheet that will 'contain' the image.
 * @param rowNumber A primtive int that contains the index number of a
 *                  row on the sheet.
 * @param reqImageHeightMM A primtive double that contains the required
 *                         height of the image in millimetres
 * @param resizeBehaviour A primitve int whose value will indicate how the
 *                        height of the row should be adjusted if the
 *                        required height of the image is greater than the
 *                        height of the row.
 * @return An instance of the ClientAnchorDetail class that will contain
 *         the index number of the row containing the cell whose top
 *         left hand corner also defines the top left hand corner of the
 *         image, the index number of the row containing the cell whose
 *         top left hand corner also defines the bottom right hand
 *         corner of the image and an inset that determines how far the
 *         bottom edge of the image can protrude into the next (lower)
 *         row - expressed as a specific number of co-ordinate positions.
 */
private ClientAnchorDetail fitImageToRows(HSSFSheet sheet, int rowNumber,
        double reqImageHeightMM, int resizeBehaviour) {
    double rowCoordinatesPerMM;
    int pictureHeightCoordinates;
    ClientAnchorDetail rowClientAnchorDetail = null;

    // Get the row and it's height
    HSSFRow row = sheet.getRow(rowNumber);
    if(row == null) {
        // Create row if it does not exist.
        row = sheet.createRow(rowNumber);
    }

    // Get the row's height in millimetres
    double rowHeightMM = row.getHeightInPoints() / ConvertImageUnits.POINTS_PER_MILLIMETRE;

    // Check that the row's height will accomodate the image at the required
    // dimensions. If the height of the row is LESS than the required height
    // of the image, decide how the application should respond - resize the
    // row or overlay the image across a series of rows.
    if(rowHeightMM < reqImageHeightMM) {
        if((resizeBehaviour == AddDimensionedImage.EXPAND_ROW) ||
           (resizeBehaviour == AddDimensionedImage.EXPAND_ROW_AND_COLUMN)) {
            row.setHeightInPoints((float)(reqImageHeightMM *
                    ConvertImageUnits.POINTS_PER_MILLIMETRE));
            rowHeightMM = reqImageHeightMM;
            rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS /
                rowHeightMM;
            pictureHeightCoordinates = (int)(reqImageHeightMM * rowCoordinatesPerMM);
            rowClientAnchorDetail = new ClientAnchorDetail(rowNumber,
                    rowNumber, pictureHeightCoordinates);
        }
        // If the user has chosen to overlay both rows and columns or just
        // to expand ONLY the size of the columns, then calculate how to lay
        // the image out ver one or more rows.
        else if((resizeBehaviour == AddDimensionedImage.OVERLAY_ROW_AND_COLUMN) ||
                (resizeBehaviour == AddDimensionedImage.EXPAND_COLUMN)) {
            rowClientAnchorDetail = this.calculateRowLocation(sheet,
                    rowNumber, reqImageHeightMM);
        }
    }
    // Else, if the image is smaller than the space available
    else {
        rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS /
                rowHeightMM;
        pictureHeightCoordinates = (int)(reqImageHeightMM * rowCoordinatesPerMM);
        rowClientAnchorDetail = new ClientAnchorDetail(rowNumber,
                    rowNumber, pictureHeightCoordinates);
    }
    return(rowClientAnchorDetail);
}
 
Example 18
Source File: ReportStudentsUTLCandidates.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void addValues(HSSFSheet sheet) {
    int i = 2;
    for (StudentLine studentLine : getCorrectStudentLines()) {

        try {

            String institutionCode = studentLine.getInstitutionCode();
            String institutionName = studentLine.getInstitutionName();
            String candidacyNumber = studentLine.getCandidacyNumber();
            String studentNumberForPrint = studentLine.getStudentNumberForPrint();
            String studentName = studentLine.getStudentName();
            String documentTypeName = studentLine.getDocumentTypeName();
            String documentNumber = studentLine.getDocumentNumber();
            String degreeCode = studentLine.getDegreeCode();
            String degreeName = studentLine.getDegreeName();
            String degreeTypeName = studentLine.getDegreeTypeName();
            Integer countNumberOfDegreeChanges = studentLine.getCountNumberOfDegreeChanges();
            Boolean hasMadeDegreeChange = studentLine.getHasMadeDegreeChange();
            LocalDate firstEnrolmentOnCurrentExecutionYear = studentLine.getFirstEnrolmentOnCurrentExecutionYear();
            String regime = studentLine.getRegime();
            String firstRegistrationExecutionYear = studentLine.getFirstRegistrationExecutionYear();
            Integer countNumberOfEnrolmentsYearsSinceRegistrationStart =
                    studentLine.getCountNumberOfEnrolmentsYearsSinceRegistrationStart();
            Integer countNumberOfEnrolmentsYearsInIntegralRegime =
                    studentLine.getCountNumberOfEnrolmentsYearsInIntegralRegime();
            double achievedDegreeEcts = studentLine.getNumberOfDoneECTS();
            Integer numberOfDegreeCurricularYears = studentLine.getNumberOfDegreeCurricularYears();
            Integer curricularYearOneYearAgo = studentLine.getCurricularYearOneYearAgo();
            BigDecimal numberOfEnrolledEctsOneYearAgo = studentLine.getNumberOfEnrolledEctsOneYearAgo();
            BigDecimal numberOfApprovedEctsOneYearAgo = studentLine.getNumberOfApprovedEctsOneYearAgo();
            Integer curricularYearInCurrentYear = studentLine.getCurricularYearInCurrentYear();
            Double numberOfEnrolledECTS = studentLine.getNumberOfEnrolledECTS();
            Money gratuityAmount = studentLine.getGratuityAmount();
            Integer numberOfMonthsExecutionYear = studentLine.getNumberOfMonthsExecutionYear();
            String firstMonthOfPayment = studentLine.getFirstMonthOfPayment();
            Boolean ownerOfCETQualification = studentLine.getOwnerOfCETQualification();
            boolean degreeQualificationOwner = studentLine.isDegreeQualificationOwner();
            boolean masterQualificationOwner = studentLine.isMasterQualificationOwner();
            boolean phdQualificationOwner = studentLine.isPhdQualificationOwner();
            boolean ownerOfCollegeQualification = studentLine.isOwnerOfCollegeQualification();
            String observations = studentLine.getObservations();
            String lastEnrolmentExecutionYear = studentLine.getLastEnrolledExecutionYear();
            String nif = studentLine.getNif();

            HSSFRow row = sheet.createRow(i);
            addCellValue(row, onNullEmptyString(institutionCode), 0);
            addCellValue(row, onNullEmptyString(institutionName), 1);
            addCellValue(row, onNullEmptyString(candidacyNumber), 2);
            addCellValue(row, onNullEmptyString(studentNumberForPrint), 3);
            addCellValue(row, onNullEmptyString(studentName), 4);
            addCellValue(row, onNullEmptyString(documentTypeName), 5);
            addCellValue(row, onNullEmptyString(documentNumber), 6);
            addCellValue(row, onNullEmptyString(degreeCode), 7);
            addCellValue(row, onNullEmptyString(degreeName), 8);
            addCellValue(row, onNullEmptyString(degreeTypeName), 9);
            addCellValue(row, "", 10);
            addCellValue(row, onNullEmptyString(countNumberOfDegreeChanges), 11);
            addCellValue(row, onNullEmptyString(hasMadeDegreeChange), 12);
            addCellValue(row, onNullEmptyString(firstEnrolmentOnCurrentExecutionYear), 13);
            addCellValue(row, onNullEmptyString(regime), 14);
            addCellValue(row, "", 15);
            addCellValue(row, onNullEmptyString(firstRegistrationExecutionYear), 16);
            addCellValue(row, onNullEmptyString(countNumberOfEnrolmentsYearsSinceRegistrationStart), 17);
            addCellValue(row, onNullEmptyString(countNumberOfEnrolmentsYearsInIntegralRegime), 18);
            addCellValue(row, onNullEmptyString(achievedDegreeEcts), 19);
            addCellValue(row, onNullEmptyString(numberOfDegreeCurricularYears), 20);
            addCellValue(row, onNullEmptyString(curricularYearOneYearAgo), 21);
            addCellValue(row, onNullEmptyString(numberOfEnrolledEctsOneYearAgo != null ? numberOfEnrolledEctsOneYearAgo
                    .toString().replace('.', ',') : ""), 22);
            addCellValue(row, onNullEmptyString(numberOfApprovedEctsOneYearAgo != null ? numberOfApprovedEctsOneYearAgo
                    .toString().replace('.', ',') : ""), 23);
            addCellValue(row, onNullEmptyString(curricularYearInCurrentYear), 24);
            addCellValue(row,
                    onNullEmptyString(numberOfEnrolledECTS != null ? numberOfEnrolledECTS.toString().replace('.', ',') : ""),
                    25);
            addCellValue(row,
                    onNullEmptyString(gratuityAmount != null ? gratuityAmount.toPlainString().replace('.', ',') : ""), 26);
            addCellValue(row, onNullEmptyString(numberOfMonthsExecutionYear), 27);
            addCellValue(row, onNullEmptyString(firstMonthOfPayment), 28);
            addCellValue(row, onNullEmptyString(ownerOfCETQualification), 29);
            addCellValue(row, onNullEmptyString(degreeQualificationOwner), 30);
            addCellValue(row, onNullEmptyString(masterQualificationOwner), 31);
            addCellValue(row, onNullEmptyString(phdQualificationOwner), 32);
            addCellValue(row, onNullEmptyString(ownerOfCollegeQualification), 33);
            addCellValue(row, onNullEmptyString(observations), 34);
            addCellValue(row, onNullEmptyString(lastEnrolmentExecutionYear), 35);
            addCellValue(row, onNullEmptyString(nif), 36);
            addCellValue(row, "", 37);

            i++;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}
 
Example 19
Source File: AgentManageServiceImpl.java    From DrivingAgency with MIT License 4 votes vote down vote up
private String derivedStudentInfo(List<StudentVo> studentVos){

        String agentEmail = SecurityContextHolder.getAgent().getAgentEmail();
        if (StringUtils.isBlank(agentEmail)){
            throw new ParamException("你的邮箱为空,不能导出Excel数据");
        }

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet("获取学员信息Excel表格");
        HSSFRow row = null;
        row = sheet.createRow(0);
        row.setHeight((short) (26.25 * 20));
        row.createCell(0).setCellValue("学员信息列表");
        CellRangeAddress rowRegion = new CellRangeAddress(0, 0, 0, 8);
        sheet.addMergedRegion(rowRegion);
        row = sheet.createRow(1);
        row.setHeight((short) (22.50 * 20));//设置行高
        row.createCell(0).setCellValue("学员Id");//为第一个单元格设值
        row.createCell(1).setCellValue("学院学号");//为第一个单元格设值
        row.createCell(2).setCellValue("学员姓名");//为第二个单元格设值
        row.createCell(3).setCellValue("学员手机号");//为第三个单元格设值
        row.createCell(4).setCellValue("学员身份证照片地址");//为第四个单元格设值
        row.createCell(5).setCellValue("学员学费");//为第五个单元格设值
        row.createCell(6).setCellValue("学员学校");//为第六个单元格设值
        row.createCell(7).setCellValue("学员添加者");//为第七个单元格设值
        row.createCell(8).setCellValue("学员");//为第八个单元格设值

        for (int i = 0; i < studentVos.size(); i++) {
            row = sheet.createRow(i + 2);
            StudentVo studentVo = studentVos.get(i);
            row.createCell(0).setCellValue(studentVo.getId());
            row.createCell(1).setCellValue(studentVo.getStudentId());
            row.createCell(2).setCellValue(studentVo.getStudentName());
            row.createCell(3).setCellValue(studentVo.getStudentPhone());
            row.createCell(4).setCellValue(studentVo.getStudentImg());
            if (studentVo.getStudentPrice()==null){
                row.createCell(5).setCellValue(0);
            }else{
                row.createCell(5).setCellValue(studentVo.getStudentPrice().doubleValue());
            }
            row.createCell(6).setCellValue(studentVo.getStudentSchool());
            row.createCell(7).setCellValue(studentVo.getOperator());
            row.createCell(8).setCellValue(DateTimeUtil.dateToStr(studentVo.getUpdateTime()));
        }
        sheet.setDefaultRowHeight((short) (16.5 * 20));
        for (int i = 0; i <= 13; i++) {
            sheet.autoSizeColumn(i);
        }
        try {

            String folder=System.getProperty("java.io.tmpdir");
            File file=new File(folder,UUID.randomUUID().toString()+".xls");
            if (!file.exists()){
                file.createNewFile();
            }
            wb.write(file);

            mailSenderUtil.sendAttachmentMail(agentEmail,"【驾校全部学员数据】",
                    "驾校代理小程序中的全部学员数据,Excel在附件中",file);

            return "Excel导出成功";
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
 
Example 20
Source File: ReportStudentsUTLCandidates.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void addHeaders(HSSFSheet sheet) {
    sheet.createRow(0);
    sheet.createRow(1);

    addHeaderCell(sheet, getHeaderInBundle("institutionCode"), 0);
    addHeaderCell(sheet, getHeaderInBundle("institutionName"), 1);
    addHeaderCell(sheet, getHeaderInBundle("candidacyNumber"), 2);
    addHeaderCell(sheet, getHeaderInBundle("studentNumberForPrint"), 3);
    addHeaderCell(sheet, getHeaderInBundle("studentName"), 4);
    addHeaderCell(sheet, getHeaderInBundle("documentTypeName"), 5);
    addHeaderCell(sheet, getHeaderInBundle("documentNumber"), 6);
    addHeaderCell(sheet, getHeaderInBundle("degreeCode"), 7);
    addHeaderCell(sheet, getHeaderInBundle("degreeName"), 8);
    addHeaderCell(sheet, getHeaderInBundle("degreeTypeName"), 9);
    addHeaderCell(sheet, getHeaderInBundle("code"), 10);
    addHeaderCell(sheet, getHeaderInBundle("countNumberOfDegreeChanges"), 11);
    addHeaderCell(sheet, getHeaderInBundle("hasMadeDegreeChange"), 12);
    addHeaderCell(sheet, getHeaderInBundle("firstEnrolmentOnCurrentExecutionYear"), 13);
    addHeaderCell(sheet, getHeaderInBundle("regime"), 14);
    addHeaderCell(sheet, getHeaderInBundle("code"), 15);

    HSSFRow row = sheet.getRow(0);
    HSSFCell cell = row.createCell(16);
    cell.setCellValue(getHeaderInBundle("ingression.year.on.cycle.studies"));
    cell.setCellStyle(headerStyle);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 16, 18));

    cell = sheet.getRow(1).createCell(16);
    cell.setCellValue(getHeaderInBundle("ingression.year.on.cycle.studies.year"));
    cell.setCellStyle(headerStyle);

    cell = sheet.getRow(1).createCell(17);
    cell.setCellValue(getHeaderInBundle("ingression.year.on.cycle.studies.count"));
    cell.setCellStyle(headerStyle);

    cell = sheet.getRow(1).createCell(18);
    cell.setCellValue(getHeaderInBundle("ingression.year.on.cycle.studies.integral.count"));
    cell.setCellStyle(headerStyle);

    addHeaderCell(sheet, getHeaderInBundle("numberOfDoneECTS"), 19);
    addHeaderCell(sheet, getHeaderInBundle("numberOfDegreeCurricularYears"), 20);
    addHeaderCell(sheet, getHeaderInBundle("curricularYearOneYearAgo"), 21);
    addHeaderCell(sheet, getHeaderInBundle("numberOfEnrolledEctsOneYearAgo"), 22);
    addHeaderCell(sheet, getHeaderInBundle("numberOfApprovedEctsOneYearAgo"), 23);
    addHeaderCell(sheet, getHeaderInBundle("curricularYearInCurrentYear"), 24);
    addHeaderCell(sheet, getHeaderInBundle("numberOfEnrolledECTS"), 25);
    addHeaderCell(sheet, getHeaderInBundle("gratuityAmount"), 26);
    addHeaderCell(sheet, getHeaderInBundle("numberOfMonthsExecutionYear"), 27);
    addHeaderCell(sheet, getHeaderInBundle("firstMonthOfPayment"), 28);
    addHeaderCell(sheet, getHeaderInBundle("ownerOfCETQualification"), 29);
    addHeaderCell(sheet, getHeaderInBundle("degreeQualificationOwner"), 30);
    addHeaderCell(sheet, getHeaderInBundle("masterQualificationOwner"), 31);
    addHeaderCell(sheet, getHeaderInBundle("phdQualificationOwner"), 32);
    addHeaderCell(sheet, getHeaderInBundle("ownerOfCollegeQualification"), 33);
    addHeaderCell(sheet, getHeaderInBundle("observations"), 34);
    addHeaderCell(sheet, getHeaderInBundle("lastEnrolledExecutionYear"), 35);
    addHeaderCell(sheet, getHeaderInBundle("nif"), 36);
    addHeaderCell(sheet, getHeaderInBundle("last.conclusion.academic.facts"), 37);
}