當前位置: 首頁>>代碼示例>>Java>>正文


Java XSSFCell.setCellStyle方法代碼示例

本文整理匯總了Java中org.apache.poi.xssf.usermodel.XSSFCell.setCellStyle方法的典型用法代碼示例。如果您正苦於以下問題:Java XSSFCell.setCellStyle方法的具體用法?Java XSSFCell.setCellStyle怎麽用?Java XSSFCell.setCellStyle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.xssf.usermodel.XSSFCell的用法示例。


在下文中一共展示了XSSFCell.setCellStyle方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setCellProperties

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
 * @param cell
 * @param value
 * @param style
 */
public static void setCellProperties(XSSFCell cell, String value,
		XSSFCellStyle style) {
	Assert.notNull(cell, "cell must not be null!");
	// fill year
	cell.setCellValue(value);
	cell.setCellStyle(style);
}
 
開發者ID:gp15237125756,項目名稱:PoiExcelExport,代碼行數:13,代碼來源:CellValueUtil.java

示例2: setCellProperties

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
 * @param cell
 * @param value
 * @param style
 */
public static void setCellProperties(XSSFCell cell,String value,XSSFCellStyle style){
	Assert.notNull(cell, "cell must not be null!");
	//fill year
	cell.setCellValue(value);
	cell.setCellStyle(style);
}
 
開發者ID:gp15237125756,項目名稱:PoiExcelExport,代碼行數:12,代碼來源:XSSFCellUtil.java

示例3: applyStyleToRange

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
public static void applyStyleToRange(XSSFSheet sheet, XSSFCellStyle style, int rowStart, int colStart, int rowEnd, int colEnd) {
    for (int r = rowStart; r <= rowEnd; r++) {
        for (int c = colStart; c <= colEnd; c++) {
            XSSFRow row = sheet.getRow(r);

            if (row != null) {
                XSSFCell cell = row.getCell(c);

                if (cell != null) {
                    cell.setCellStyle(style);
                }
            }
        }
    }
}
 
開發者ID:lucci,項目名稱:NFLFantasyAnalyzer,代碼行數:16,代碼來源:FileWriter.java

示例4: copyCell

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
 * @param oldCell
 * @param newCell
 * @param styleMap
 */
public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map<Integer, XSSFCellStyle> styleMap) {
    if (styleMap != null) {
        if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
            newCell.setCellStyle(oldCell.getCellStyle());
        } else {
            int stHashCode = oldCell.getCellStyle().hashCode();
            XSSFCellStyle newCellStyle = styleMap.get(stHashCode);
            if (newCellStyle == null) {
                newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
                newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
                styleMap.put(stHashCode, newCellStyle);
            }
            newCell.setCellStyle(newCellStyle);
        }
    }
    switch (oldCell.getCellType()) {
        case XSSFCell.CELL_TYPE_STRING:
            newCell.setCellValue(oldCell.getStringCellValue());
            break;
        case XSSFCell.CELL_TYPE_NUMERIC:
            newCell.setCellValue(oldCell.getNumericCellValue());
            break;
        case XSSFCell.CELL_TYPE_BLANK:
            newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
            break;
        case XSSFCell.CELL_TYPE_BOOLEAN:
            newCell.setCellValue(oldCell.getBooleanCellValue());
            break;
        case XSSFCell.CELL_TYPE_ERROR:
            newCell.setCellErrorValue(oldCell.getErrorCellValue());
            break;
        case XSSFCell.CELL_TYPE_FORMULA:
            newCell.setCellFormula(oldCell.getCellFormula());
            break;
        default:
            break;
    }

}
 
開發者ID:likelet,項目名稱:DAtools,代碼行數:45,代碼來源:Util.java

示例5: shiftRange

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private void shiftRange(int numRowsDown, int rowStart, int rowEnd, int colStart, int colEnd) throws Exception {
        // loop through from bottom row up to either SHIFT the whole row, or copy necessary columns, insert  new row below, insert the data from the cell and then delete all style and format from the original cell
        for(int j=rowEnd;j>rowStart;j--) {
            XSSFRow row = worksheet.getRow(j);
            XSSFRow newRow = worksheet.getRow(j+numRowsDown);
            if(row == null && newRow == null) 
                continue;
            else if (row == null) {
                worksheet.removeRow(newRow);
                continue;
            }
            if(newRow == null) {
                newRow = worksheet.createRow(j+numRowsDown);
            }
//            newRow = worksheet.getRow(j+numRowsDown);
            //if(row ==null) continue;
            for(int k=colStart;k<=colEnd;k++) {
                XSSFCell cell = row.getCell(k);
                if(cell != null) {
                    XSSFCell newCell = newRow.getCell(k)==null ? newRow.createCell(k) : newRow.getCell(k);
                    if(cell==null) continue;
                    if(cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) {
                        String calc = cell.getCellFormula();
                        newCell.setCellStyle(cell.getCellStyle());
                        cell.setCellType(XSSFCell.CELL_TYPE_BLANK);
                        this.setCellFormula(newCell, calc);
                    } else if(cell.getCellType()==XSSFCell.CELL_TYPE_BLANK) {
                        newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
                    } else {
                        newCell.copyCellFrom(cell, new CellCopyPolicy());
                        newCell.setCellStyle(cell.getCellStyle());
                    }
                }
            }
        }
    }
 
開發者ID:linearblue,項目名稱:ExcelInjector,代碼行數:37,代碼來源:ExcelTableInjector.java

示例6: startSerialize

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
@Override
protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception
{
    workbook = new XSSFWorkbook();
    sheet = workbook.createSheet( "Sheet1" );

    XSSFFont boldFont = workbook.createFont();
    boldFont.setBold( true );

    XSSFCellStyle boldCellStyle = workbook.createCellStyle();
    boldCellStyle.setFont( boldFont );

    // build schema
    for ( Node child : rootNode.getChildren() )
    {
        if ( child.isCollection() )
        {
            if ( !child.getChildren().isEmpty() )
            {
                Node node = child.getChildren().get( 0 );

                XSSFRow row = sheet.createRow( 0 );

                int cellIdx = 0;

                for ( Node property : node.getChildren() )
                {
                    if ( property.isSimple() )
                    {
                        XSSFCell cell = row.createCell( cellIdx++ );
                        cell.setCellValue( property.getName() );
                        cell.setCellStyle( boldCellStyle );
                    }
                }
            }
        }
    }
}
 
開發者ID:dhis2,項目名稱:dhis2-core,代碼行數:39,代碼來源:ExcelNodeSerializer.java

示例7: createSheet

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private static void createSheet(XSSFWorkbook wb, Report report) {
    String sheetName = Long.toString(report.getAppId());//name of sheet


    XSSFSheet sheet = wb.createSheet(sheetName);
    CellStyle cellStyle = wb.createCellStyle();
    CreationHelper createHelper = wb.getCreationHelper();
    cellStyle.setDataFormat(
            createHelper.createDataFormat().getFormat(DATE_FORMAT));

    createFirstRow(sheet);
    int r = 1;
    //iterating r number of rows
    for (Review review : report.getReviews()) {
        XSSFRow row = sheet.createRow(r);

        row.createCell(0).setCellValue(review.getVersion());
        row.createCell(1).setCellValue(review.getRate());
        row.createCell(2).setCellValue(review.getTitle());
        row.createCell(3).setCellValue(review.getBody());

        XSSFCell dateCell = row.createCell(4);
        dateCell.setCellValue(review.getDate());
        dateCell.setCellStyle(cellStyle);

        row.createCell(5).setCellValue(review.getCountry().getName());
        r++;
    }
}
 
開發者ID:bydlokoder,項目名稱:AppStoreReviewsParser,代碼行數:30,代碼來源:ExcelExporter.java

示例8: writeTable

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private <T extends Number> void writeTable(XSSFSheet sheet, List<List<T>> tmp, String title, List<String> headers,
  List<String> values, boolean isContinuous) {
  writeTableHeaders(sheet, title, headers);

  ArrayList<String> rowHeaders = Lists.newArrayList(values);
  if(!isContinuous) rowHeaders.add("Total");

  int counter = 0;
  int rownum = 4;

  for(String k : rowHeaders) {
    int cellnum = 0;
    XSSFRow row = sheet.createRow(rownum++);
    XSSFCell cell = row.createCell(cellnum++);
    cell.setCellValue(k);
    cell.setCellStyle(headerStyle);

    for(T obj : tmp.get(counter)) {
      cell = row.createCell(cellnum++);
      cell.setCellStyle(tableStyle);

      if(obj instanceof Integer) cell.setCellValue((Integer) obj);
      else if(obj instanceof Float) cell.setCellValue((Float) obj);
      else cell.setCellValue(String.valueOf(obj));
    }

    counter++;
  }

  sheet.autoSizeColumn(0);
}
 
開發者ID:obiba,項目名稱:mica2,代碼行數:32,代碼來源:ExcelContingencyWriter.java

示例9: copyCell

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
 * Copy a cell to another cell
 * 
 * @param oldCell cell to be copied
 * @param newCell cell to be created
 * @param styleMap style map
 */
public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map<Integer, CellStyle> styleMap) {
	if (styleMap != null) {			
		if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
			newCell.setCellStyle(oldCell.getCellStyle());
		} else {				
			int stHashCode = oldCell.getCellStyle().hashCode();
			CellStyle newCellStyle = styleMap.get(stHashCode);				
			if (newCellStyle == null) {					
				newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
				newCellStyle.cloneStyleFrom(oldCell.getCellStyle());					
				styleMap.put(stHashCode, newCellStyle);
			}
			newCell.setCellStyle(newCellStyle);
		}			
	}
	switch (oldCell.getCellType()) {
	case XSSFCell.CELL_TYPE_STRING:
		newCell.setCellValue(oldCell.getStringCellValue());
		break;
	case XSSFCell.CELL_TYPE_NUMERIC:
		newCell.setCellValue(oldCell.getNumericCellValue());
		break;
	case XSSFCell.CELL_TYPE_BLANK:
		newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
		break;
	case XSSFCell.CELL_TYPE_BOOLEAN:
		newCell.setCellValue(oldCell.getBooleanCellValue());
		break;
	case XSSFCell.CELL_TYPE_ERROR:
		newCell.setCellErrorValue(oldCell.getErrorCellValue());
		break;
	case XSSFCell.CELL_TYPE_FORMULA:
		newCell.setCellFormula(oldCell.getCellFormula());
		break;
	default:
		break;
	}

}
 
開發者ID:nextreports,項目名稱:nextreports-engine,代碼行數:47,代碼來源:XlsxUtil.java

示例10: printSheet

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private void printSheet(final XSSFWorkbook wb, final XSSFSheet sheet, final List<APIModel> apis) {

		XSSFCell cell = null;
		XSSFRow row = null;

		////////////////////////////////////////////////////
		XSSFFont fontBold = wb.createFont();
		fontBold.setBold(true);

		CellStyle styleHeader = wb.createCellStyle();
		styleHeader.setFillPattern(CellStyle.SOLID_FOREGROUND);
		styleHeader.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex());
		styleHeader.setFont(fontBold);
		styleHeader.setBorderTop(CellStyle.BORDER_THIN);
		styleHeader.setBorderLeft(CellStyle.BORDER_THIN);
		styleHeader.setBorderRight(CellStyle.BORDER_THIN);
		styleHeader.setBorderBottom(CellStyle.BORDER_DOUBLE);

		row = sheet.createRow(0); //////////////////////////
		cell = row.createCell(1, Cell.CELL_TYPE_STRING);

		CellStyle style1 = wb.createCellStyle();
		style1.setFont(fontBold);
		cell.setCellStyle(style1);
		cell.setCellValue("外部I/F (API) 一覧");

		row = sheet.createRow(1); //////////////////////////
		cell = row.createCell(1, Cell.CELL_TYPE_STRING);
		cell.setCellValue("APIの一覧を下記の通り定義する");

		row = sheet.createRow(4); //////////////////////////
		cell = row.createCell(1, Cell.CELL_TYPE_STRING);
		cell.setCellValue("ID");
		cell.setCellStyle(styleHeader);
		cell = row.createCell(2, Cell.CELL_TYPE_STRING);
		cell.setCellValue("Group");
		cell.setCellStyle(styleHeader);
		cell = row.createCell(3, Cell.CELL_TYPE_STRING);
		cell.setCellValue("Name");
		cell.setCellStyle(styleHeader);
		cell = row.createCell(4, Cell.CELL_TYPE_STRING);
		cell.setCellValue("Comment");
		cell.setCellStyle(styleHeader);

		int offsetRow = 5;
		int offsetCol = 1;
		for (int i = 0; i < apis.size(); i++) {
			APIModel api = apis.get(i);

			row = sheet.createRow(offsetRow + i);

			cell = row.createCell(offsetCol + 0, Cell.CELL_TYPE_STRING);
			cell.setCellValue(s(api.getId()));

			cell = row.createCell(offsetCol + 2, Cell.CELL_TYPE_STRING);
			cell.setCellValue(s(api.getName()));

			cell = row.createCell(offsetCol + 3, Cell.CELL_TYPE_STRING);
			cell.setCellValue(s(api.getComment()));
		}
	}
 
開發者ID:azuki-framework,項目名稱:azuki-doclet-jaxrs,代碼行數:62,代碼來源:JAXRSXlsxDocletWriter.java

示例11: copyRow

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
private XSSFRow copyRow(XSSFWorkbook workbook, XSSFSheet worksheet, int sourceRowNum, int destinationRowNum) {
    XSSFRow sourceRow = worksheet.getRow(sourceRowNum);
       worksheet.shiftRows(destinationRowNum, worksheet.getLastRowNum(), 1, true, false);
       XSSFRow newRow = worksheet.createRow(destinationRowNum);

    // Loop through source columns to add to new row
    for (int i = 0; i < sourceRow.getLastCellNum(); i++) {
        // Grab a copy of the old/new cell
        XSSFCell oldCell = sourceRow.getCell(i);
        XSSFCell newCell = newRow.createCell(i);

        // If the old cell is null jump to next cell
        if (oldCell == null) {
            newCell = null;
            continue;
        }

        newCell.setCellStyle(oldCell.getCellStyle());

        // Set the cell data type
        newCell.setCellType(oldCell.getCellType());
    }

    // If there are are any merged regions in the source row, copy to new row
    for (int i = 0; i < worksheet.getNumMergedRegions(); i++) {
        CellRangeAddress cellRangeAddress = worksheet.getMergedRegion(i);
        if (cellRangeAddress.getFirstRow() == sourceRow.getRowNum()) {
            CellRangeAddress newCellRangeAddress = new CellRangeAddress(newRow.getRowNum(),
                    (newRow.getRowNum() +
                            (cellRangeAddress.getLastRow() - cellRangeAddress.getFirstRow()
                                    )),
                    cellRangeAddress.getFirstColumn(),
                    cellRangeAddress.getLastColumn());
            worksheet.addMergedRegion(newCellRangeAddress);
        }
    }
    
    newRow.setHeight(sourceRow.getHeight());
    
    return newRow;
}
 
開發者ID:SiLeBAT,項目名稱:BfROpenLab,代碼行數:42,代碼來源:TraceGenerator.java

示例12: testModifyCellContents

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
 * [Flow #-2] 액셀 파일 수정 : 엑샐 파일 내 셀의 내용을 변경하고 저장할 수 있음
 */
@Test
public void testModifyCellContents() throws Exception {
    
    try {
    	String content = "Use \n with word wrap on to create a new line";
    	short rownum = 2;
    	int cellnum = 2;
    	
    	log.debug("testModifyCellContents start....");

    	StringBuffer sb = new StringBuffer();
    	sb.append(fileLocation).append("/").append("testModifyCellContents.xlsx");

    	if (!EgovFileUtil.isExistsFile(sb.toString())) {
    		XSSFWorkbook wbT = new XSSFWorkbook();
     	wbT.createSheet();
	
         // 엑셀 파일 생성
         excelService.createXSSFWorkbook(wbT, sb.toString());
    	}
    	
        // 엑셀 파일 로드
        XSSFWorkbook wb = excelService.loadXSSFWorkbook(sb.toString());
        log.debug("testModifyCellContents after loadWorkbook....");
        
        XSSFSheet sheet = wb.getSheetAt(0);
        Font f2 = wb.createFont();
        CellStyle cs = wb.createCellStyle();
        cs = wb.createCellStyle();
        
        cs.setFont( f2 );
        //Word Wrap MUST be turned on
        cs.setWrapText( true );
        
        XSSFRow row = sheet.createRow( rownum );
        row.setHeight( (short) 0x349 );
        XSSFCell cellx = row.createCell( cellnum );
        cellx.setCellType( SXSSFCell.CELL_TYPE_STRING );
        cellx.setCellValue( new XSSFRichTextString(content) );
        cellx.setCellStyle( cs );
        
        sheet.setColumnWidth( 20, (int) ( ( 50 * 8 ) / ( (double) 1 / 20 ) ) );
        
        //excelService.writeWorkbook(wb);
        
        FileOutputStream outx = new FileOutputStream(sb.toString());
        wb.write(outx);
        outx.close();
        
        // 엑셀 파일 로드
        Workbook wb1 = excelService.loadXSSFWorkbook(sb.toString());
        
        Sheet sheet1 = wb1.getSheetAt(0);
        Row row1 = sheet1.getRow(rownum);
        Cell cell1 = row1.getCell( cellnum );
        
        // 수정된 셀의 내용 점검
        log.debug("cell ###" + cell1.getRichStringCellValue() + "###");
        log.debug("cont ###" + content + "###");
        
        assertNotSame("TEST", cell1.getRichStringCellValue().toString());
        assertEquals(content, cell1.getRichStringCellValue().toString());
        
    } catch (Exception e) {
    	log.error(e.toString());
    	throw new Exception(e);
    } finally {
    	log.debug("testModifyCellContents end....");
    }
}
 
開發者ID:eGovFrame,項目名稱:egovframework.rte.root,代碼行數:74,代碼來源:EgovExcelXSSFServiceTest.java

示例13: testGetCellContents

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
 * [Flow #-5] 셀 내용 추출 : 엑셀 파일을 읽어 특정 셀의 값을 얻어 옴
 */
@Test
public void testGetCellContents() throws Exception {
    
    try {
    	log.debug("testGetCellContents start....");

    	StringBuffer sb = new StringBuffer();
    	sb.append(fileLocation).append("/").append("testGetCellContents.xlsx");        	

    	if (EgovFileUtil.isExistsFile(sb.toString())) {
    		EgovFileUtil.delete(new File(sb.toString()));
    	
    		log.debug("Delete file...." + sb.toString());
    	}
    	
    	XSSFWorkbook wbTmp = new XSSFWorkbook();
    	wbTmp.createSheet();

        // 엑셀 파일 생성
        excelService.createXSSFWorkbook(wbTmp, sb.toString());

    	// 엑셀 파일 로드
    	XSSFWorkbook wb = excelService.loadXSSFWorkbook(sb.toString());
    	log.debug("testGetCellContents after loadWorkbook....");

    	XSSFSheet sheet = wb.createSheet("cell test sheet");

    	XSSFCellStyle cs = wb.createCellStyle();
    	cs = wb.createCellStyle();
        cs.setWrapText( true );
        
    	for (int i = 0; i < 100; i++) {
     	XSSFRow row = sheet.createRow(i);
     	for (int j = 0; j < 5; j++) {
      	XSSFCell cell = row.createCell(j);
      	cell.setCellValue(new XSSFRichTextString("row " + i + ", cell " + j));
      	cell.setCellStyle( cs );
     	}
    	}

    	// 엑셀 파일 저장
    	FileOutputStream out = new FileOutputStream(sb.toString());
        wb.write(out);
        out.close();
        
    	//////////////////////////////////////////////////////////////////////////
        // 검증
        XSSFWorkbook wbT = excelService.loadXSSFWorkbook(sb.toString());
        XSSFSheet sheetT = wbT.getSheet("cell test sheet");

        for (int i = 0; i < 100; i++) {
     	XSSFRow row1 = sheetT.getRow(i);
         for (int j = 0; j < 5; j++) {
         	XSSFCell cell1 = row1.getCell(j);
         	log.debug("row " + i + ", cell " + j + " : " + cell1.getRichStringCellValue());
          assertEquals("row " + i + ", cell " + j, cell1.getRichStringCellValue().toString());
         }
        }

    } catch (Exception e) {
    	log.error(e.toString());
    	throw new Exception(e);
    } finally {
    	log.debug("testGetCellContents end....");
    }
}
 
開發者ID:eGovFrame,項目名稱:egovframework.rte.root,代碼行數:70,代碼來源:EgovExcelXSSFServiceTest.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFCell.setCellStyle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。