当前位置: 首页>>代码示例>>Java>>正文


Java Cell.setCellFormula方法代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.Cell.setCellFormula方法的典型用法代码示例。如果您正苦于以下问题:Java Cell.setCellFormula方法的具体用法?Java Cell.setCellFormula怎么用?Java Cell.setCellFormula使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.ss.usermodel.Cell的用法示例。


在下文中一共展示了Cell.setCellFormula方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupTotalCell

import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
protected void setupTotalCell(Cell cell, final String propId, final int currentRow, final int startRow, int col) {
    cell.setCellStyle(getCellStyle(propId, currentRow, startRow, col, true));
    final HorizontalAlignment poiAlignment = getGridHolder().getCellAlignment(propId);
    CellUtil.setAlignment(cell, poiAlignment);
    Class<?> propType = getGridHolder().getPropertyType(propId);
    if (isNumeric(propType)) {
        CellRangeAddress cra = new CellRangeAddress(startRow, currentRow - 1, col, col);
        if (isHierarchical()) {
            // 9 & 109 are for sum. 9 means include hidden cells, 109 means exclude.
            // this will show the wrong value if the user expands an outlined category, so
            // we will range value it first
            cell.setCellFormula("SUM(" + cra.formatAsString(hierarchicalTotalsSheet.getSheetName(),
                    true) + ")");
        } else {
            cell.setCellFormula("SUM(" + cra.formatAsString() + ")");
        }
    } else {
        if (0 == col) {
            cell.setCellValue(createHelper.createRichTextString("Total"));
        }
    }
}
 
开发者ID:TFyre,项目名称:vaadin-gridexport,代码行数:23,代码来源:ExcelExport.java

示例2: sumRatingsUp

import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
 * generates the sum over all competences
 * @param rowNumPR
 * @param rowPR
 */
private static void sumRatingsUp(int rowNumPR, Row rowPR) {
	//SUM of all NOVICE ratings
	CellReference cellRefNoviceFirst = new CellReference(1, COLUMN_NOVICE);
	CellReference cellRefNoviceLast = new CellReference(rowNumPR-1, COLUMN_NOVICE);
	
	Cell cellPR = rowPR.createCell(COLUMN_NOVICE);
	cellPR.setCellFormula("SUM("+cellRefNoviceFirst.formatAsString()+":"+cellRefNoviceLast.formatAsString()+")");
  
	//SUM of all INTERMEDIATE ratings
	CellReference cellRefIntermediateFirst = new CellReference(1, COLUMN_INTERMEDIATE);
	CellReference cellRefIntermediateLast = new CellReference(rowNumPR-1, COLUMN_INTERMEDIATE);
	
	cellPR = rowPR.createCell(COLUMN_INTERMEDIATE);
	cellPR.setCellFormula("SUM("+cellRefIntermediateFirst.formatAsString()+":"+cellRefIntermediateLast.formatAsString()+")");
  
	//SUM of all EXPERT ratings
	CellReference cellRefExpertFirst = new CellReference(1, COLUMN_EXPERT);
	CellReference cellRefExpertLast = new CellReference(rowNumPR-1, COLUMN_EXPERT);
	
	cellPR = rowPR.createCell(COLUMN_EXPERT);
	cellPR.setCellFormula("SUM("+cellRefExpertFirst.formatAsString()+":"+cellRefExpertLast.formatAsString()+")");
  
	//SUM of all IRRELEVANT ratings
	CellReference cellRefIrrelevantFirst = new CellReference(1, COLUMN_IRRELEVANT);
	CellReference cellRefIrrelevantLast = new CellReference(rowNumPR-1, COLUMN_IRRELEVANT);
	
	cellPR = rowPR.createCell(COLUMN_IRRELEVANT);
	cellPR.setCellFormula("SUM("+cellRefIrrelevantFirst.formatAsString()+":"+cellRefIrrelevantLast.formatAsString()+")");
}
 
开发者ID:SemanticSoftwareLab,项目名称:ScholarLens,代码行数:35,代码来源:GenerateMetrics.java

示例3: copyCellByBlankSpace

import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
 * 复制单位格(空白行的复制,即只复制格式和固定文字,不填充数据)
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-07-03
 * @version     v1.0
 *
 * @param i_RTemplate      模板对象
 * @param i_TemplateCell   模板中的单元格对象
 * @param i_DataWorkbook   数据工作薄
 * @param i_DataCell       数据中的单元格对象
 * @param io_RSystemValue 系统变量信息
 * @param i_Datas          本行对应的数据
 * @param io_RValue        小计循环的迭代器
 * @return                 
 */
public final static void copyCellByBlankSpace(RTemplate i_RTemplate ,Cell i_TemplateCell ,RWorkbook i_DataWorkbook ,Cell i_DataCell ,RSystemValue io_RSystemValue)
{
    // 复制样式
    i_DataCell.setCellStyle(i_DataWorkbook.getCellStyle(i_RTemplate ,i_TemplateCell.getCellStyle().getIndex()));
    
    // 复制评论
    copyComment(i_RTemplate ,i_TemplateCell ,i_DataWorkbook ,i_DataCell);
    
    // 复制数据类型
    CellType v_CellType = i_TemplateCell.getCellTypeEnum();
    // i_DataCell.setCellType(v_CellType);  不能在此统一设置,原因是:下面代码对类型是有浮动的
    
    if ( v_CellType == CellType.NUMERIC ) 
    {
        i_DataCell.setCellType(v_CellType);
        
        if ( HSSFDateUtil.isCellDateFormatted(i_TemplateCell) ) 
        {
            i_DataCell.setCellValue(i_TemplateCell.getDateCellValue());
        } 
        else 
        {
            i_DataCell.setCellValue(i_TemplateCell.getNumericCellValue());
        }
    }
    else if ( v_CellType == CellType.STRING ) 
    {
        RichTextString v_TemplateRichText = i_TemplateCell.getRichStringCellValue();
        String         v_ValueName        = v_TemplateRichText.toString();
        
        if ( i_RTemplate.isExists(v_ValueName) )
        {
            i_DataCell.setCellType(v_CellType);
            i_DataCell.setCellValue("");
        }
        else 
        {
            i_DataCell.setCellType(v_CellType);
            copyRichTextStyle(i_RTemplate ,v_TemplateRichText ,i_DataWorkbook ,i_DataCell);
        }
    } 
    else if ( v_CellType == CellType.BOOLEAN ) 
    {
        i_DataCell.setCellType(v_CellType);
        i_DataCell.setCellValue(i_TemplateCell.getBooleanCellValue());
    } 
    else if ( v_CellType == CellType.FORMULA) 
    {
        i_DataCell.setCellType(v_CellType);
        i_DataCell.setCellFormula(i_TemplateCell.getCellFormula());
    } 
    else 
    {
        // Nothing.
        i_DataCell.setCellType(v_CellType);
    }
}
 
开发者ID:HY-ZhengWei,项目名称:hy.common.report,代码行数:74,代码来源:JavaToExcel.java

示例4: computeAveragePrecision

import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
 * generates the average precisions
 * @param rowPR
 */
private static void computeAveragePrecision(Row rowPR) {
	//[email protected]
	CellReference cellRefRelevant10First = new CellReference(1, COLUMN_RELEVANT);
	CellReference cellRefRelevant10Last = new CellReference(10, COLUMN_RELEVANT);
	
	CellReference cellRefAvgAt10First = new CellReference(1, COLUMN_AVG_At_10);
	CellReference cellRefAvgAt10Last = new CellReference(10, COLUMN_AVG_At_10);
	
	Cell cellPR = rowPR.createCell(COLUMN_AVG_At_10);
	cellPR.setCellFormula("SUMIF("+cellRefRelevant10First.formatAsString()
			+":"+cellRefRelevant10Last.formatAsString()+",1,"
			+cellRefAvgAt10First.formatAsString()
			+":"+cellRefAvgAt10Last.formatAsString()
			+")/SUM("+cellRefRelevant10First.formatAsString()
			+":"+cellRefRelevant10Last.formatAsString()+")");
	
	
	//[email protected]
	CellReference cellRefRelevant25First = new CellReference(1, COLUMN_RELEVANT);
	CellReference cellRefRelevant25Last = new CellReference(25, COLUMN_RELEVANT);
	
	CellReference cellRefAvgAt25First = new CellReference(1, COLUMN_AVG_At_25);
	CellReference cellRefAvgAt25Last = new CellReference(25, COLUMN_AVG_At_25);
	
	
	cellPR = rowPR.createCell(COLUMN_AVG_At_25);
	cellPR.setCellFormula("SUMIF("+cellRefRelevant25First.formatAsString()
			+":"+cellRefRelevant25Last.formatAsString()+",1,"
			+cellRefAvgAt25First.formatAsString()
			+":"+cellRefAvgAt25Last.formatAsString()
			+")/SUM("+cellRefRelevant25First.formatAsString()
			+":"+cellRefRelevant25Last.formatAsString()+")");
	
	//[email protected]
	CellReference cellRefRelevant50First = new CellReference(1, COLUMN_RELEVANT);
	CellReference cellRefRelevant50Last = new CellReference(50, COLUMN_RELEVANT);
	
	CellReference cellRefAvgAt50First = new CellReference(1, COLUMN_AVG_At_50);
	CellReference cellRefAvgAt50Last = new CellReference(50, COLUMN_AVG_At_50);
	
	
	cellPR = rowPR.createCell(COLUMN_AVG_At_50);
	cellPR.setCellFormula("SUMIF("+cellRefRelevant50First.formatAsString()
			+":"+cellRefRelevant50Last.formatAsString()+",1,"
			+cellRefAvgAt50First.formatAsString()
			+":"+cellRefAvgAt50Last.formatAsString()
			+")/SUM("+cellRefRelevant50First.formatAsString()
			+":"+cellRefRelevant50Last.formatAsString()+")");
}
 
开发者ID:SemanticSoftwareLab,项目名称:ScholarLens,代码行数:54,代码来源:GenerateMetrics.java

示例5: generateSheetData

import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
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));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:54,代码来源:ExcelTestHelper.java

示例6: computeIDCG_nDCG

import org.apache.poi.ss.usermodel.Cell; //导入方法依赖的package包/类
/**
 * generates the IDCG and nDCG
 * @param prec_recall
 * @param rowPR
 * @param ratings
 */
private static void computeIDCG_nDCG(Sheet prec_recall, Row rowPR, ArrayList<Rating> ratings) {
	CellReference cellRefDCGFirst = new CellReference(1, COLUMN_DCG);
	CellReference cellRefDCGLast = new CellReference(50, COLUMN_DCG);
			
	
	Cell cellPR = rowPR.createCell(COLUMN_DCG);
	cellPR.setCellFormula("SUM("+cellRefDCGFirst.formatAsString()
			+":"+cellRefDCGLast.formatAsString()+")");
	
	
	
	//Get the List of ratings and sort them by relevance (rating)
	Collections.sort(ratings, new Comparator<Rating>() {

		@Override
		public int compare(Rating o1, Rating o2) {
			return Float.compare(o2.rating, o1.rating);
		}

	});
	
	
	//go through the sheet again and add the ideal rank    		
	int current_position = 1;
	
	for (Iterator<Rating> it = ratings.iterator(); it.hasNext();) {
		int rank = it.next().getCompetenceRank();
		
		Row rowPR2 = prec_recall.getRow(rank);
		
			
		//CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());
	    cellPR = rowPR2.createCell(COLUMN_IDEAL_RANK, Cell.CELL_TYPE_NUMERIC);
	    cellPR.setCellValue(current_position);
	    
	    CellReference cellRefNovice = new CellReference(rowPR2.getRowNum(), COLUMN_NOVICE);
	    
	    CellReference cellRefIrrelevant = new CellReference(rowPR2.getRowNum(), COLUMN_IRRELEVANT);
	    CellReference cellRefNoviceWeight = new CellReference(0, COLUMN_NOVICE);
	    CellReference cellRefIrrelevantWeight = new CellReference(0, COLUMN_IRRELEVANT);
	    CellReference cellRefIdealRank = new CellReference(rowPR2.getRowNum(), COLUMN_IDEAL_RANK);
	    
	        
	        cellPR = rowPR2.createCell(COLUMN_IDCG, Cell.CELL_TYPE_NUMERIC);
	     	
	        //LOG 1 is not defined
	        if(current_position==1)
	        	cellPR.setCellFormula("SUMIF("+cellRefNovice.formatAsString()+":"+cellRefIrrelevant.formatAsString()+",1,"+cellRefNoviceWeight.formatAsString()+":"+cellRefIrrelevantWeight.formatAsString()+")");
	        else
	         	cellPR.setCellFormula("SUMIF("+cellRefNovice.formatAsString()+":"+cellRefIrrelevant.formatAsString()+",1,"+cellRefNoviceWeight.formatAsString()+":"+cellRefIrrelevantWeight.formatAsString()+")/LOG("+cellRefIdealRank.formatAsString()+",2)");
	      
	     current_position++;
	     	
		}
		
		//sum of iDCG
		cellPR = rowPR.createCell(COLUMN_IDCG, Cell.CELL_TYPE_NUMERIC);
	  
		CellReference cellRefIDCGFirst = new CellReference(1, COLUMN_IDCG);
		CellReference cellRefIDCGLast = new CellReference(50, COLUMN_IDCG);
		
	   	cellPR.setCellFormula("SUM("+cellRefIDCGFirst.formatAsString()+":"+cellRefIDCGLast.formatAsString()+")");
	
	   	//nDCG
	   	CellReference cellRefDCG = new CellReference(rowPR.getRowNum(), COLUMN_DCG);
		CellReference cellRefIDCG = new CellReference(rowPR.getRowNum(), COLUMN_IDCG);
		
	   	cellPR = rowPR.createCell(COLUMN_nDCG, Cell.CELL_TYPE_NUMERIC);
	   	cellPR.setCellFormula("SUM("+cellRefDCG.formatAsString()+"/"+cellRefIDCG.formatAsString()+")");
}
 
开发者ID:SemanticSoftwareLab,项目名称:ScholarLens,代码行数:77,代码来源:GenerateMetrics.java


注:本文中的org.apache.poi.ss.usermodel.Cell.setCellFormula方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。