Java Code Examples for org.apache.poi.ss.usermodel.Row#createCell()

The following examples show how to use org.apache.poi.ss.usermodel.Row#createCell() . 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: ExcelUtil.java    From javautils with Apache License 2.0 6 votes vote down vote up
/**
 * 向指定页中写入数据
 * @param sheet
 * @param list
 */
private static void putSheet(Sheet sheet, List<Object> list){
    Row row;
    Cell c;
    if(sheet != null && list != null){
        for(int i = 0; i < list.size(); i++){
            row =  sheet.createRow(i);
            Object obj = list.get(i);
            if(obj instanceof List){
                List rowData = (List) obj;
                for(int j = 0; j < rowData.size(); j++){
                    Object colData = rowData.get(j);
                    c = row.createCell(j);
                    String value = colData != null ? colData.toString() : "";
                    if(colData instanceof String){
                        c.setCellValue(value);
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: AnnotationsSheet.java    From tools with Apache License 2.0 6 votes vote down vote up
/**
 * @param relationship
 */
public void add(Annotation annotation, String elementId) {
	Row row = addRow();		
	if (elementId != null) {
		Cell idCell = row.createCell(ID_COL, CellType.STRING);
		idCell.setCellValue(elementId);
	}
	if (annotation.getComment() != null) {
		row.createCell(COMMENT_COL).setCellValue(annotation.getComment());
	}
	if (annotation.getAnnotationDate() != null) {
		row.createCell(DATE_COL).setCellValue(annotation.getAnnotationDate());
	}
	if (annotation.getAnnotator() != null) {
		row.createCell(ANNOTATOR_COL).setCellValue(annotation.getAnnotator());
	}
	if (annotation.getAnnotationType() != null) {
		row.createCell(TYPE_COL).setCellValue(annotation.getAnnotationType().getTag());
	}
}
 
Example 3
Source File: ExcelImportServer.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 保存字段值(获取值,校验值,追加错误信息)
 * 
 * @param params
 * @param object
 * @param cell
 * @param excelParams
 * @param titleString
 * @param row
 * @throws Exception
 */
private void saveFieldValue(ImportParams params, Object object, Cell cell, Map<String, ExcelImportEntity> excelParams, String titleString, Row row) throws Exception {
	Object value = cellValueServer.getValue(params.getDataHanlder(), object, cell, excelParams, titleString);
	if (object instanceof Map) {
		if (params.getDataHanlder() != null) {
			params.getDataHanlder().setMapValue((Map) object, titleString, value);
		} else {
			((Map) object).put(titleString, value);
		}
	} else {
		ExcelVerifyHanlderResult verifyResult = verifyHandlerServer.verifyData(object, value, titleString, excelParams.get(titleString).getVerify(), params.getVerifyHanlder());
		if (verifyResult.isSuccess()) {
			setValues(excelParams.get(titleString), object, value);
		} else {
			Cell errorCell = row.createCell(row.getLastCellNum());
			errorCell.setCellValue(verifyResult.getMsg());
			errorCell.setCellStyle(errorCellStyle);
			verfiyFail = true;
			throw new ExcelImportException(ExcelImportEnum.VERIFY_ERROR);
		}
	}
}
 
Example 4
Source File: DefaultXlsTableExporter.java    From olat with Apache License 2.0 6 votes vote down vote up
private void createHeader(final Table table, final Translator translator, final int cdcnt, final Sheet exportSheet) {

        Row headerRow = exportSheet.createRow(0);
        for (int c = 0; c < cdcnt; c++) {
            ColumnDescriptor cd = table.getColumnDescriptor(c);
            if (cd instanceof StaticColumnDescriptor) {
                // ignore static column descriptors - of no value in excel download!
                continue;
            }
            String headerKey = cd.getHeaderKey();
            String headerVal = cd.translateHeaderKey() ? translator.translate(headerKey) : headerKey;
            Cell cell = headerRow.createCell(c);
            cell.setCellValue(headerVal);
            cell.setCellStyle(headerCellStyle);
        }
    }
 
Example 5
Source File: SheetBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Builds sheet from parent workbook and 2D array with cell
 * values. Creates rows anyway (even if row contains only null
 * cells), creates cells if either corresponding array value is not
 * null or createEmptyCells property is true.
 * The conversion is performed in the following way:
 * <p>
 * <ul>
 * <li>Numbers become numeric cells.</li>
 * <li><code>java.util.Date</code> or <code>java.util.Calendar</code>
 * instances become date cells.</li>
 * <li>String with leading '=' char become formulas (leading '='
 * will be truncated).</li>
 * <li>Other objects become strings via <code>Object.toString()</code>
 * method call.</li>
 * </ul>
 *
 * @return newly created sheet
 */
public Sheet build() {
    Sheet sheet = (sheetName == null) ? workbook.createSheet() : workbook.createSheet(sheetName);
    Row currentRow = null;
    Cell currentCell = null;

    for (int rowIndex = 0; rowIndex < cells.length; ++rowIndex) {
        Object[] rowArray = cells[rowIndex];
        currentRow = sheet.createRow(rowIndex);

        for (int cellIndex = 0; cellIndex < rowArray.length; ++cellIndex) {
            Object cellValue = rowArray[cellIndex];
            if (cellValue != null || shouldCreateEmptyCells) {
                currentCell = currentRow.createCell(cellIndex);
                setCellValue(currentCell, cellValue);
            }
        }
    }
    return sheet;
}
 
Example 6
Source File: NonStandardLicensesSheet.java    From tools with Apache License 2.0 6 votes vote down vote up
public static void create(Workbook wb, String sheetName) {
	int sheetNum = wb.getSheetIndex(sheetName);
	if (sheetNum >= 0) {
		wb.removeSheetAt(sheetNum);
	}
	Sheet sheet = wb.createSheet(sheetName);
	CellStyle headerStyle = AbstractSheet.createHeaderStyle(wb);
	CellStyle centerStyle = AbstractSheet.createCenterStyle(wb);
	CellStyle wrapStyle = AbstractSheet.createLeftWrapStyle(wb);

	Row row = sheet.createRow(0);
	for (int i = 0; i < HEADER_TITLES.length; i++) {
		sheet.setColumnWidth(i, COLUMN_WIDTHS[i]*256);
		if (LEFT_WRAP[i]) {
			sheet.setDefaultColumnStyle(i, wrapStyle);
		} else if (CENTER_NOWRAP[i]) {
			sheet.setDefaultColumnStyle(i, centerStyle);
		}
		Cell cell = row.createCell(i);
		cell.setCellStyle(headerStyle);
		cell.setCellValue(HEADER_TITLES[i]);
	}
}
 
Example 7
Source File: ExcelWriteContext.java    From poi-excel-utils with Apache License 2.0 6 votes vote down vote up
public Cell setCellValue(int rowIndex, int colIndex, Object val) {
    if (rowIndex < 0 || colIndex < 0) {
        throw new IllegalArgumentException("rowIndex:" + rowIndex + " &colIndex:" + colIndex);
    }
    if (curSheet == null) {
        throw new NullPointerException("sheet is null");
    }
    Row row = curSheet.getRow(rowIndex);
    if (row == null) {
        row = curSheet.createRow(rowIndex);
    }
    Cell cell = row.getCell(colIndex);
    if (cell == null) {
        cell = row.createCell(colIndex);
    }
    ExcelUtils.writeCell(cell, val);
    return cell;
}
 
Example 8
Source File: SheetUtility.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Given a sheet, this method deletes a column from a sheet and moves
 * all the columns to the right of it to the left one cell.
 * 
 * Note, this method will not update any formula references.
 * 
 * @param sheet
 * @param column
 */
public static void deleteColumn( Sheet sheet, int columnToDelete ){
	int maxColumn = 0;
	for ( int r=0; r < sheet.getLastRowNum()+1; r++ ){
		Row	row	= sheet.getRow( r );
		
		// if no row exists here; then nothing to do; next!
		if ( row == null )
			continue;
		
		int lastColumn = row.getLastCellNum();
		if ( lastColumn > maxColumn )
			maxColumn = lastColumn;
		
		// if the row doesn't have this many columns then we are good; next!
		if ( lastColumn < columnToDelete )
			continue;
		
		for ( int x=columnToDelete+1; x < lastColumn + 1; x++ ){
			Cell oldCell	= row.getCell(x-1);
			if ( oldCell != null )
				row.removeCell( oldCell );
			
			Cell nextCell	= row.getCell( x );
			if ( nextCell != null ){
				Cell newCell	= row.createCell( x-1, nextCell.getCellType() );
				cloneCell(newCell, nextCell);
			}
		}
	}

	
	// Adjust the column widths
	for ( int c=0; c < maxColumn; c++ ){
		sheet.setColumnWidth( c, sheet.getColumnWidth(c+1) );
	}
}
 
Example 9
Source File: AddCellService.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public static void setHeaderRow(final Sheet worksheet, final String headerData, final String delimiter) {
/*StringTokenizer headerTokens = new StringTokenizer(headerData, delimiter);
Row headerRow = worksheet.createRow(0);
int columnIndex = 0;
while (headerTokens.hasMoreTokens())
{
	Cell cell = headerRow.createCell(columnIndex);
	cell.setCellValue(headerTokens.nextToken());
	columnIndex++;
}*/
      final Row headerRow = worksheet.createRow(0);

      final String[] tmp = headerData.split(delimiter);
      for (int i = 0; i < tmp.length; i++) {
          Cell cell = headerRow.getCell(i);
          if (cell == null) {
              cell = headerRow.createCell(i);
          }
          try {
              double valueNumeric = Double.parseDouble(tmp[i].trim());
              cell.setCellValue(valueNumeric);
          }
          //for non-numeric value
          catch (Exception e) {
              cell.setCellValue(tmp[i].trim());
          }
      }
  }
 
Example 10
Source File: ExtractedLicenseSheet.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * @param comparer
 * @param docNames 
 * @throws InvalidSPDXAnalysisException 
 */
public void importCompareResults(SpdxComparer comparer, String[] docNames) throws SpdxCompareException, InvalidSPDXAnalysisException {
	if (comparer.getNumSpdxDocs() != docNames.length) {
		throw(new SpdxCompareException("Number of document names does not match the number of SPDX documents"));
	}
	this.clear();
	Row header = sheet.getRow(0);
	int[] licenseIndexes = new int[comparer.getNumSpdxDocs()];
	AnyLicenseInfo[][] extractedLicenses = new AnyLicenseInfo[comparer.getNumSpdxDocs()][];
	for (int i = 0; i < extractedLicenses.length; i++) {
		Cell headerCell = header.getCell(FIRST_LIC_ID_COL+i);
		headerCell.setCellValue(docNames[i]);
		AnyLicenseInfo[] docExtractedLicenses = comparer.getSpdxDoc(i).getExtractedLicenseInfos();
		Arrays.sort(docExtractedLicenses, extractedLicenseComparator);
		extractedLicenses[i] = docExtractedLicenses;
		licenseIndexes[i] = 0;
	}
	while (!allLicensesExhausted(extractedLicenses, licenseIndexes)) {
		Row currentRow = this.addRow();
		String extractedLicenseText = getNextExtractedLicenseText(extractedLicenses, licenseIndexes);
		Cell licenseTextCell = currentRow.createCell(EXTRACTED_TEXT_COL);
		licenseTextCell.setCellValue(extractedLicenseText);
		for (int i = 0; i < extractedLicenses.length; i++) {
			if (extractedLicenses[i].length > licenseIndexes[i]) {
				if  (extractedLicenses[i][licenseIndexes[i]] instanceof ExtractedLicenseInfo) {
					String compareExtractedText = ((ExtractedLicenseInfo)extractedLicenses[i][licenseIndexes[i]]).getExtractedText();
					if (LicenseCompareHelper.isLicenseTextEquivalent(extractedLicenseText, 
							compareExtractedText)) {
						Cell licenseIdCell = currentRow.createCell(FIRST_LIC_ID_COL+i);
						licenseIdCell.setCellValue(formatLicenseInfo((ExtractedLicenseInfo)extractedLicenses[i][licenseIndexes[i]]));
						licenseIndexes[i]++;
					}
				} else {
					licenseIndexes[i]++;	// skip any licenses which are not non-standard licenses
				}
			}
		}
	}
}
 
Example 11
Source File: ExcelUtil.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 创建单元格
 */
public Cell createCell(Excel attr, Row row, int column)
{
    // 创建列
    Cell cell = row.createCell(column);
    // 写入列信息
    cell.setCellValue(attr.name());
    setDataValidation(attr, row, column);
    cell.setCellStyle(styles.get("header"));
    return cell;
}
 
Example 12
Source File: DocumentAnnotationSheet.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * @param comparer
 * @param docNames 
 * @throws InvalidSPDXAnalysisException 
 */
public void importCompareResults(SpdxComparer comparer, String[] docNames) throws SpdxCompareException, InvalidSPDXAnalysisException {
	if (comparer.getNumSpdxDocs() != docNames.length) {
		throw(new SpdxCompareException("Number of document names does not match the number of SPDX documents"));
	}
	this.clear();
	Row header = sheet.getRow(0);
	int[] annotationIndexes = new int[comparer.getNumSpdxDocs()];
	Annotation[][] annotations = new Annotation[comparer.getNumSpdxDocs()][];
	for (int i = 0; i < annotations.length; i++) {
		Cell headerCell = header.getCell(FIRST_DATE_COL+i);
		headerCell.setCellValue(docNames[i]);
		Annotation[] docAnnotations = comparer.getSpdxDoc(i).getAnnotations();
		Arrays.sort(docAnnotations, annotationComparator);
		annotations[i] = docAnnotations;
		annotationIndexes[i] = 0;
	}
	while (!allAnnotationsExhausted(annotations, annotationIndexes)) {
		Row currentRow = this.addRow();
		Annotation nextAnnotation = getNextAnnotation(annotations, annotationIndexes);
		Cell annotatorCell = currentRow.createCell(ANNOTATOR_COL);
		annotatorCell.setCellValue(nextAnnotation.getAnnotator());
		Cell typeCell = currentRow.createCell(TYPE_COL);
		typeCell.setCellValue(nextAnnotation.getAnnotationType().getTag());
		Cell commentCell = currentRow.createCell(COMMENT_COL);
		commentCell.setCellValue(nextAnnotation.getComment());
		for (int i = 0; i < annotations.length; i++) {
			if (annotations[i].length > annotationIndexes[i]) {
				Annotation compareAnnotation = annotations[i][annotationIndexes[i]];
				if (annotationComparator.compare(nextAnnotation, compareAnnotation) == 0) {
					Cell dateCell = currentRow.createCell(FIRST_DATE_COL+i);
					dateCell.setCellValue(annotations[i][annotationIndexes[i]].getAnnotationDate());
					annotationIndexes[i]++;
				}
			}
		}
	}
}
 
Example 13
Source File: PackageSheet.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * @param wb
 * @param sheetName
 */
public static void create(Workbook wb, String sheetName) {
	int sheetNum = wb.getSheetIndex(sheetName);
	if (sheetNum >= 0) {
		wb.removeSheetAt(sheetNum);
	}
	Sheet sheet = wb.createSheet(sheetName);
	CellStyle headerStyle = AbstractSheet.createHeaderStyle(wb);
	CellStyle defaultStyle = AbstractSheet.createLeftWrapStyle(wb);
	Row headerRow = sheet.createRow(0);
	sheet.setColumnWidth(FIELD_COL, FIELD_COL_WIDTH*256);
	sheet.setDefaultColumnStyle(FIELD_COL, defaultStyle);
	Cell fieldCell = headerRow.createCell(FIELD_COL);
	fieldCell.setCellStyle(headerStyle);
	fieldCell.setCellValue(FIELD_HEADER_TEXT);
	
	sheet.setColumnWidth(EQUALS_COL, EQUALS_COL_WIDTH * 256);
	sheet.setDefaultColumnStyle(EQUALS_COL, defaultStyle);
	Cell equalsCell = headerRow.createCell(EQUALS_COL);
	equalsCell.setCellStyle(headerStyle);
	equalsCell.setCellValue(EQUALS_HEADER_TEXT);
	
	for (int i = FIRST_DOC_COL; i < MultiDocumentSpreadsheet.MAX_DOCUMENTS+FIRST_DOC_COL; i++) {
		sheet.setColumnWidth(i, COL_WIDTH*256);
		sheet.setDefaultColumnStyle(i, defaultStyle);
		Cell cell = headerRow.createCell(i);
		cell.setCellStyle(headerStyle);
	}
}
 
Example 14
Source File: DocumentRelationshipSheet.java    From tools with Apache License 2.0 5 votes vote down vote up
/**
 * @param comparer
 * @param docNames 
 * @throws InvalidSPDXAnalysisException 
 */
public void importCompareResults(SpdxComparer comparer, String[] docNames) throws SpdxCompareException, InvalidSPDXAnalysisException {
	if (comparer.getNumSpdxDocs() != docNames.length) {
		throw(new SpdxCompareException("Number of document names does not match the number of SPDX documents"));
	}
	this.clear();
	Row header = sheet.getRow(0);
	int[] relationshipsIndexes = new int[comparer.getNumSpdxDocs()];
	Relationship[][] relationships = new Relationship[comparer.getNumSpdxDocs()][];
	for (int i = 0; i < relationships.length; i++) {
		Cell headerCell = header.getCell(FIRST_RELATIONSHIP_COL+i);
		headerCell.setCellValue(docNames[i]);
		Relationship[] docRelationships = comparer.getSpdxDoc(i).getRelationships();
		Arrays.sort(docRelationships, relationshipComparator);
		relationships[i] = docRelationships;
		relationshipsIndexes[i] = 0;
	}
	while (!allRelationshipsExhausted(relationships, relationshipsIndexes)) {
		Row currentRow = this.addRow();
		Relationship nextRelationship = getNexRelationship(relationships, relationshipsIndexes);
		Cell typeCell = currentRow.createCell(TYPE_COL);
		typeCell.setCellValue(nextRelationship.getRelationshipType().toTag());
		for (int i = 0; i < relationships.length; i++) {
			if (relationships[i].length > relationshipsIndexes[i]) {
				Relationship compareRelationship = relationships[i][relationshipsIndexes[i]];
				if (relationshipComparator.compare(nextRelationship, compareRelationship) == 0) {
					Cell relationshipCell = currentRow.createCell(FIRST_RELATIONSHIP_COL+i);
					relationshipCell.setCellValue(CompareHelper.relationshipToString(relationships[i][relationshipsIndexes[i]]));
					relationshipsIndexes[i]++;
				}
			}
		}
	}
}
 
Example 15
Source File: ExcelExportBase.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
public void createNumericCell (Row row, int index, String text, CellStyle style, ExcelExportEntity entity) {
	Cell cell = row.createCell(index);	
	if(StringUtils.isEmpty(text)){
		cell.setCellValue("");
		cell.setCellType(Cell.CELL_TYPE_BLANK);
	}else{
		cell.setCellValue(Double.parseDouble(text));
		cell.setCellType(Cell.CELL_TYPE_NUMERIC);
	}
	if (style != null) {
		cell.setCellStyle(style);
	}
	addStatisticsData(index, text, entity);
}
 
Example 16
Source File: WorkBookUtil.java    From easyexcel with Apache License 2.0 4 votes vote down vote up
public static Cell createCell(Row row, int colNum) {
    return row.createCell(colNum);
}
 
Example 17
Source File: PackageInfoSheetV09d2.java    From tools with Apache License 2.0 4 votes vote down vote up
public void add(SPDXPackageInfo pkgInfo) {
	Row row = addRow();
	Cell nameCell = row.createCell(NAME_COL);
	nameCell.setCellValue(pkgInfo.getDeclaredName());
	Cell copyrightCell = row.createCell(DECLARED_COPYRIGHT_COL);
	copyrightCell.setCellValue(pkgInfo.getDeclaredCopyright());
	Cell DeclaredLicenseCol = row.createCell(DECLARED_LICENSE_COL);
	DeclaredLicenseCol.setCellValue(pkgInfo.getDeclaredLicenses().toString());
	Cell concludedLicenseCol = row.createCell(CONCLUDED_LICENSE_COL);
	concludedLicenseCol.setCellValue(pkgInfo.getConcludedLicense().toString());
	Cell fileChecksumCell = row.createCell(FILE_VERIFICATION_VALUE_COL);
	if (pkgInfo.getPackageVerification() != null) {
		fileChecksumCell.setCellValue(pkgInfo.getPackageVerification().getValue());
		Cell verificationExcludedFilesCell = row.createCell(VERIFICATION_EXCLUDED_FILES_COL);
		StringBuilder excFilesStr = new StringBuilder();
		String[] excludedFiles = pkgInfo.getPackageVerification().getExcludedFileNames();
		if (excludedFiles.length > 0) {
			excFilesStr.append(excludedFiles[0]);
			for (int i = 1;i < excludedFiles.length; i++) {
				excFilesStr.append(", ");
				excFilesStr.append(excludedFiles[i]);
			}
		}
		verificationExcludedFilesCell.setCellValue(excFilesStr.toString());
	}

	if (pkgInfo.getDescription() != null) {
		Cell descCell = row.createCell(FULL_DESC_COL);
		descCell.setCellValue(pkgInfo.getDescription());
	}
	Cell fileNameCell = row.createCell(MACHINE_NAME_COL);
	fileNameCell.setCellValue(pkgInfo.getFileName());
	Cell pkgSha1 = row.createCell(PACKAGE_SHA_COL);
	if (pkgInfo.getSha1() != null) {
		pkgSha1.setCellValue(pkgInfo.getSha1());
	}
	// add the license infos in files in multiple rows
	SPDXLicenseInfo[] licenseInfosInFiles = pkgInfo.getLicensesFromFiles();
	if (licenseInfosInFiles != null && licenseInfosInFiles.length > 0) {
		StringBuilder sb = new StringBuilder(licenseInfosInFiles[0].toString());
		for (int i = 1; i < licenseInfosInFiles.length; i++) {
			sb.append(",");
			sb.append(licenseInfosInFiles[i].toString());
		}
		row.createCell(LICENSE_INFO_IN_FILES_COL).setCellValue(sb.toString());
	}
	if (pkgInfo.getLicenseComments() != null) {
		row.createCell(LICENSE_COMMENT_COL).setCellValue(pkgInfo.getLicenseComments());
	}
	if (pkgInfo.getShortDescription() != null) {
		Cell shortDescCell = row.createCell(SHORT_DESC_COL);
		shortDescCell.setCellValue(pkgInfo.getShortDescription());
	}
	if (pkgInfo.getSourceInfo() != null) {
		Cell sourceInfoCell = row.createCell(SOURCE_INFO_COL);
		sourceInfoCell.setCellValue(pkgInfo.getSourceInfo());
	}
	Cell urlCell = row.createCell(URL_COL);
	urlCell.setCellValue(pkgInfo.getUrl());
	if (pkgInfo.getVersionInfo() != null) {
		Cell versionInfoCell = row.createCell(VERSION_COL);
		versionInfoCell.setCellValue(pkgInfo.getVersionInfo());
	}
}
 
Example 18
Source File: PdcaReportExcelCommand.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
private int createPdcaItem(XSSFWorkbook wb, XSSFSheet sh, int row, XSSFCellStyle cellNormalStyle, List<PdcaItemVO> items, PdcaAuditVO audit) throws Exception {
	
	XSSFColor fnColor = new XSSFColor( SimpleUtils.getColorRGB4POIColor("#000000"), null );		
	XSSFColor bgLabelColor = new XSSFColor( SimpleUtils.getColorRGB4POIColor("#F2F2F2"), null );
	
	XSSFCellStyle cellLabelStyle = wb.createCellStyle();
	cellLabelStyle.setFillForegroundColor( bgLabelColor );
	cellLabelStyle.setFillPattern( FillPatternType.SOLID_FOREGROUND );				
	
	XSSFFont cellLabelFont = wb.createFont();
	cellLabelFont.setBold(true);
	cellLabelFont.setColor(fnColor);
	cellLabelStyle.setFont(cellLabelFont);		
	cellLabelStyle.setBorderBottom(BorderStyle.THIN);
	cellLabelStyle.setBorderTop(BorderStyle.THIN);
	cellLabelStyle.setBorderRight(BorderStyle.THIN);
	cellLabelStyle.setBorderLeft(BorderStyle.THIN);
	cellLabelStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	cellLabelStyle.setAlignment(HorizontalAlignment.CENTER);
	cellLabelStyle.setWrapText(true);			
	
	Map<String, String> pdcaTypeMap = PdcaType.getDataMap(false);
	
	for (PdcaItemVO item : items) {
		
		Row labelRow = sh.createRow(row);
		Cell labelCell_6_1 = labelRow.createCell(0);	
		labelCell_6_1.setCellValue( pdcaTypeMap.get(item.getType()) );
		labelCell_6_1.setCellStyle(cellLabelStyle);				
		
		Cell labelCell_6_2 = labelRow.createCell(1);	
		labelCell_6_2.setCellValue( item.getTitle() + ( !StringUtils.isBlank(item.getDescription()) ? "\n\n" + item.getDescription() : "" ) );
		labelCell_6_2.setCellStyle(cellNormalStyle);	
		
		Cell labelCell_6_3 = labelRow.createCell(2);	
		labelCell_6_3.setCellValue( item.getEmployeeAppendNames() );
		labelCell_6_3.setCellStyle(cellNormalStyle);
		
		Cell labelCell_6_4 = labelRow.createCell(3);	
		labelCell_6_4.setCellValue( item.getStartDateDisplayValue() + " ~ " + item.getEndDateDisplayValue() );
		labelCell_6_4.setCellStyle(cellNormalStyle);	
		
		Cell labelCell_6_5 = labelRow.createCell(4);	
		labelCell_6_5.setCellValue( (audit != null ? audit.getEmpId() : " ") );
		labelCell_6_5.setCellStyle(cellNormalStyle);	
		
		Cell labelCell_6_6 = labelRow.createCell(5);	
		labelCell_6_6.setCellValue( (audit != null ? audit.getConfirmDateDisplayValue() : " ") );
		labelCell_6_6.setCellStyle(cellNormalStyle);
		
		
		row++;
		
	}
	
	return row;
}
 
Example 19
Source File: ReportItemFormatters.java    From jig with Apache License 2.0 4 votes vote down vote up
public void apply(Row row, ReportItemMethod reportItemMethod, Object methodReturnValue) {
    short lastCellNum = row.getLastCellNum();
    Cell cell = row.createCell(lastCellNum == -1 ? 0 : lastCellNum);

    format(reportItemMethod.value(), methodReturnValue, cell);
}
 
Example 20
Source File: ExcelTestHelper.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private static void generateSheetData(final Sheet sheet, final CellStyle style, short startingRow) {
  int currentRow = startingRow;
  // Create first row values
  Row row1 = sheet.createRow(currentRow++);
  row1.createCell(0).setCellValue(1.0);
  row1.createCell(1).setCellValue("One");
  row1.createCell(2).setCellValue("One");
  Cell c13 = row1.createCell(3);
  c13.setCellValue(LocaleUtil.getLocaleCalendar(1983, 04/*zero based*/, 18, 4, 0, 0));
  c13.setCellStyle(style);
  Cell c14 = row1.createCell(4);
  c14.setCellFormula("A2+1");
  // For formulas we read pre-computed values. Editors set the precomputed value by default. We need to add it here
  // explicitly as the library doesn't pre compute the formula value.
  c14.setCellValue(2.0d);
  row1.createCell(5).setCellValue(true);
  row1.createCell(6).setCellFormula("B2*20");
  row1.createCell(6).setCellValue("#ERROR");

  // Create second row values
  Row row2 = sheet.createRow(currentRow++);
  row2.createCell(0).setCellValue(2.0);
  row2.createCell(1).setCellValue("Two");
  row2.createCell(2).setCellValue("Two");
  Cell c23 = row2.createCell(3);
  c23.setCellValue(LocaleUtil.getLocaleCalendar(2013, 06/*zero based*/, 05, 5, 0, 1));
  c23.setCellStyle(style);
  Cell c24 = row2.createCell(4);
  c24.setCellFormula("A3+1");
  c24.setCellValue(3.0d);
  row2.createCell(5).setCellValue(false);
  row2.createCell(6).setCellFormula("B3*20");
  row2.createCell(6).setCellValue("#ERROR");

  // Create third row values
  Row row3 = sheet.createRow(currentRow++);
  row3.createCell(0).setCellValue(3.0);
  row3.createCell(1).setCellValue("Three and Three");
  row3.createCell(5).setCellValue(false);

  // Create fourth row values
  Row row4 = sheet.createRow(currentRow++);
  row4.createCell(0).setCellValue(4.0);
  row4.createCell(1).setCellValue("Four and Four, Five and Five");

  // Create fifth row values
  Row row5 = sheet.createRow(currentRow++);
  row5.createCell(0).setCellValue(5.0);

  sheet.addMergedRegion(new CellRangeAddress(startingRow + 2, startingRow + 2, 1, 2));
  sheet.addMergedRegion(new CellRangeAddress(startingRow + 2, startingRow + 4, 5, 5));
  sheet.addMergedRegion(new CellRangeAddress(startingRow + 3, startingRow + 4, 1, 2));
}