本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFCell.setCellFormula方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFCell.setCellFormula方法的具体用法?Java HSSFCell.setCellFormula怎么用?Java HSSFCell.setCellFormula使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.setCellFormula方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
* @param oldCell
* @param newCell
* @param styleMap
*/
public static void copyCell(HSSFCell oldCell, HSSFCell newCell, Map<Integer, HSSFCellStyle> styleMap) {
if (styleMap != null) {
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
newCell.setCellStyle(oldCell.getCellStyle());
} else {
int stHashCode = oldCell.getCellStyle().hashCode();
HSSFCellStyle 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 HSSFCell.CELL_TYPE_STRING:
newCell.setCellValue(oldCell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default:
break;
}
}
示例2: copyCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static void copyCell(HSSFCell oldCell, HSSFCell newCell, Map<Integer, HSSFCellStyle> styleMap) {
if(styleMap != null) {
if(oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()){
newCell.setCellStyle(oldCell.getCellStyle());
} else{
int stHashCode = oldCell.getCellStyle().hashCode();
HSSFCellStyle 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 HSSFCell.CELL_TYPE_STRING:
newCell.setCellValue(oldCell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default:
break;
}
}
示例3: copyRow
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static void copyRow(final HSSFSheet oldSheet, final HSSFSheet newSheet, final int oldRowNum, final int newRowNum) {
final HSSFRow oldRow = oldSheet.getRow(oldRowNum);
final HSSFRow newRow = newSheet.createRow(newRowNum);
if (oldRow == null) {
return;
}
newRow.setHeight(oldRow.getHeight());
if (oldRow.getFirstCellNum() == -1) {
return;
}
for (int colNum = oldRow.getFirstCellNum(); colNum <= oldRow.getLastCellNum(); colNum++) {
final HSSFCell oldCell = oldRow.getCell(colNum);
final HSSFCell newCell = newRow.createCell(colNum);
if (oldCell != null) {
final HSSFCellStyle style = oldCell.getCellStyle();
newCell.setCellStyle(style);
final int cellType = oldCell.getCellType();
newCell.setCellType(cellType);
if (cellType == Cell.CELL_TYPE_BOOLEAN) {
newCell.setCellValue(oldCell.getBooleanCellValue());
} else if (cellType == Cell.CELL_TYPE_FORMULA) {
newCell.setCellFormula(oldCell.getCellFormula());
} else if (cellType == Cell.CELL_TYPE_NUMERIC) {
newCell.setCellValue(oldCell.getNumericCellValue());
} else if (cellType == Cell.CELL_TYPE_STRING) {
newCell.setCellValue(oldCell.getRichStringCellValue());
}
}
}
POIUtils.copyMergedRegion(newSheet, getMergedRegionList(oldSheet, oldRowNum), newRowNum);
}
示例4: copyRow
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static void copyRow(HSSFSheet oldSheet, HSSFSheet newSheet,
int oldRowNum, int newRowNum) {
HSSFRow oldRow = oldSheet.getRow(oldRowNum);
HSSFRow newRow = newSheet.createRow(newRowNum);
if (oldRow == null) {
return;
}
newRow.setHeight(oldRow.getHeight());
if (oldRow.getFirstCellNum() == -1) {
return;
}
for (int colNum = oldRow.getFirstCellNum(); colNum <= oldRow
.getLastCellNum(); colNum++) {
HSSFCell oldCell = oldRow.getCell(colNum);
HSSFCell newCell = newRow.createCell(colNum);
if (oldCell != null) {
HSSFCellStyle style = oldCell.getCellStyle();
newCell.setCellStyle(style);
int cellType = oldCell.getCellType();
newCell.setCellType(cellType);
if (cellType == HSSFCell.CELL_TYPE_BOOLEAN) {
newCell.setCellValue(oldCell.getBooleanCellValue());
} else if (cellType == HSSFCell.CELL_TYPE_FORMULA) {
newCell.setCellFormula(oldCell.getCellFormula());
} else if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
newCell.setCellValue(oldCell.getNumericCellValue());
} else if (cellType == HSSFCell.CELL_TYPE_STRING) {
newCell.setCellValue(oldCell.getRichStringCellValue());
}
}
}
POIUtils.copyMergedRegion(newSheet,
getMergedRegionList(oldSheet, oldRowNum), newRowNum);
}